From 6a8b32ad5eca845d8ac27b2a7cc02ed3473f4840 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 16:53:00 +0000 Subject: [PATCH 01/25] Directly use nano::write for serializing block_type since it's just one byte. --- nano/lib/block_type.cpp | 5 ----- nano/lib/block_type.hpp | 6 ------ nano/lib/blocks.cpp | 2 +- nano/node/messages.cpp | 2 +- 4 files changed, 2 insertions(+), 13 deletions(-) diff --git a/nano/lib/block_type.cpp b/nano/lib/block_type.cpp index 70ec28b40..5be00af00 100644 --- a/nano/lib/block_type.cpp +++ b/nano/lib/block_type.cpp @@ -5,8 +5,3 @@ std::string_view nano::to_string (nano::block_type type) { return nano::enum_util::name (type); } - -void nano::serialize_block_type (nano::stream & stream, const nano::block_type & type) -{ - nano::write (stream, type); -} diff --git a/nano/lib/block_type.hpp b/nano/lib/block_type.hpp index 020722e31..591c79999 100644 --- a/nano/lib/block_type.hpp +++ b/nano/lib/block_type.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include #include @@ -19,8 +17,4 @@ enum class block_type : uint8_t }; std::string_view to_string (block_type); -/** - * Serialize block type as an 8-bit value - */ -void serialize_block_type (nano::stream &, nano::block_type const &); } // namespace nano diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 4fc527eb0..294a0ceb0 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -1582,7 +1582,7 @@ std::shared_ptr nano::deserialize_block_json (boost::property_tree: void nano::serialize_block (nano::stream & stream_a, nano::block const & block_a) { - nano::serialize_block_type (stream_a, block_a.type ()); + nano::write (stream_a, block_a.type ()); block_a.serialize (stream_a); } diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index a2e819cc3..1d6d0fb61 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1873,7 +1873,7 @@ void nano::asc_pull_ack::blocks_payload::serialize (nano::stream & stream) const nano::serialize_block (stream, *block); } // For convenience, end with null block terminator - nano::serialize_block_type (stream, nano::block_type::not_a_block); + nano::write (stream, nano::block_type::not_a_block); } void nano::asc_pull_ack::blocks_payload::deserialize (nano::stream & stream) From dd5073944f78523ceff082f3bfe3bde06257a1d9 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 16:56:57 +0000 Subject: [PATCH 02/25] Forward declare block_type. --- nano/core_test/block_store.cpp | 1 + nano/core_test/difficulty.cpp | 1 + nano/lib/block_sideband.hpp | 2 +- nano/lib/blocks.cpp | 1 + nano/lib/config.cpp | 1 + nano/nano_node/entry.cpp | 1 + nano/node/active_elections.cpp | 3 ++- nano/node/blockprocessor.cpp | 3 ++- nano/node/bootstrap/bootstrap_bulk_push.cpp | 1 + nano/node/bootstrap/bootstrap_lazy.cpp | 1 + nano/node/bootstrap_ascending/service.cpp | 3 ++- nano/node/ipc/flatbuffers_util.cpp | 1 + nano/node/json_handler.cpp | 1 + nano/node/messages.cpp | 1 + nano/node/node.cpp | 1 + nano/node/websocket.cpp | 1 + nano/rpc_test/rpc.cpp | 1 + nano/secure/ledger.cpp | 1 + nano/store/rocksdb/rocksdb.cpp | 1 + 19 files changed, 22 insertions(+), 4 deletions(-) diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index 491741708..dfbd1a360 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/difficulty.cpp b/nano/core_test/difficulty.cpp index 2e65afacb..98b4d4fc6 100644 --- a/nano/core_test/difficulty.cpp +++ b/nano/core_test/difficulty.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/lib/block_sideband.hpp b/nano/lib/block_sideband.hpp index 871f9bfcf..e150538ae 100644 --- a/nano/lib/block_sideband.hpp +++ b/nano/lib/block_sideband.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -11,6 +10,7 @@ namespace nano { +enum class block_type : uint8_t; class object_stream; } diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 294a0ceb0..81da54a85 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/lib/config.cpp b/nano/lib/config.cpp index 4dda3dcf1..e249b3106 100644 --- a/nano/lib/config.cpp +++ b/nano/lib/config.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 37c2786bf..1a4f6da6a 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index 4d8c953f5..758752a08 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -624,4 +625,4 @@ nano::stat::type nano::to_stat_type (nano::election_state state) nano::stat::detail nano::to_stat_detail (nano::election_status_type type) { return nano::enum_util::cast (type); -} \ No newline at end of file +} diff --git a/nano/node/blockprocessor.cpp b/nano/node/blockprocessor.cpp index 34d6956a8..7f47f79d0 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -518,4 +519,4 @@ std::string_view nano::to_string (nano::block_source source) nano::stat::detail nano::to_stat_detail (nano::block_source type) { return nano::enum_util::cast (type); -} \ No newline at end of file +} diff --git a/nano/node/bootstrap/bootstrap_bulk_push.cpp b/nano/node/bootstrap/bootstrap_bulk_push.cpp index c023ec1fe..5d101fab4 100644 --- a/nano/node/bootstrap/bootstrap_bulk_push.cpp +++ b/nano/node/bootstrap/bootstrap_bulk_push.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index 439aa0ced..2f8807439 100644 --- a/nano/node/bootstrap/bootstrap_lazy.cpp +++ b/nano/node/bootstrap/bootstrap_lazy.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index bb6f4183e..107c9d034 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -852,4 +853,4 @@ nano::container_info nano::bootstrap_ascending::service::container_info () const nano::stat::detail nano::bootstrap_ascending::to_stat_detail (nano::bootstrap_ascending::service::query_type type) { return nano::enum_util::cast (type); -} \ No newline at end of file +} diff --git a/nano/node/ipc/flatbuffers_util.cpp b/nano/node/ipc/flatbuffers_util.cpp index f8265733f..c4d3a0355 100644 --- a/nano/node/ipc/flatbuffers_util.cpp +++ b/nano/node/ipc/flatbuffers_util.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 288296d05..344910ae9 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index 1d6d0fb61..c6e5dc479 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/node.cpp b/nano/node/node.cpp index e556fda03..b8de6fff0 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index d2b8eab72..4742c7dd7 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index ce050df02..8198cc9ca 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/secure/ledger.cpp b/nano/secure/ledger.cpp index d2857974d..4533eddcc 100644 --- a/nano/secure/ledger.cpp +++ b/nano/secure/ledger.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/store/rocksdb/rocksdb.cpp b/nano/store/rocksdb/rocksdb.cpp index fe6026fdf..75f3e5149 100644 --- a/nano/store/rocksdb/rocksdb.cpp +++ b/nano/store/rocksdb/rocksdb.cpp @@ -1,3 +1,4 @@ +#include #include #include #include From e11ecb70d8bf0a95fbaab5a271ab23217037b7de Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 18:08:13 +0000 Subject: [PATCH 03/25] Extracting epochs class to its own file and reducing epoch.hpp --- nano/lib/CMakeLists.txt | 2 ++ nano/lib/epoch.cpp | 37 ------------------------------- nano/lib/epoch.hpp | 42 +++--------------------------------- nano/lib/epochs.cpp | 39 +++++++++++++++++++++++++++++++++ nano/lib/epochs.hpp | 42 ++++++++++++++++++++++++++++++++++++ nano/node/epoch_upgrader.hpp | 14 +++++++----- nano/secure/common.hpp | 2 +- 7 files changed, 96 insertions(+), 82 deletions(-) create mode 100644 nano/lib/epochs.cpp create mode 100644 nano/lib/epochs.hpp diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index 76d53944f..386189342 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -44,6 +44,8 @@ add_library( env.cpp epoch.hpp epoch.cpp + epochs.cpp + epochs.hpp errors.hpp errors.cpp id_dispenser.hpp diff --git a/nano/lib/epoch.cpp b/nano/lib/epoch.cpp index 8fb6cd20f..1de1a0476 100644 --- a/nano/lib/epoch.cpp +++ b/nano/lib/epoch.cpp @@ -1,43 +1,6 @@ #include #include -#include - -nano::link const & nano::epochs::link (nano::epoch epoch_a) const -{ - return epochs_m.at (epoch_a).link; -} - -bool nano::epochs::is_epoch_link (nano::link const & link_a) const -{ - return std::any_of (epochs_m.begin (), epochs_m.end (), [&link_a] (auto const & item_a) { return item_a.second.link == link_a; }); -} - -nano::public_key const & nano::epochs::signer (nano::epoch epoch_a) const -{ - return epochs_m.at (epoch_a).signer; -} - -nano::epoch nano::epochs::epoch (nano::link const & link_a) const -{ - auto existing (std::find_if (epochs_m.begin (), epochs_m.end (), [&link_a] (auto const & item_a) { return item_a.second.link == link_a; })); - debug_assert (existing != epochs_m.end ()); - return existing->first; -} - -void nano::epochs::add (nano::epoch epoch_a, nano::public_key const & signer_a, nano::link const & link_a) -{ - debug_assert (epochs_m.find (epoch_a) == epochs_m.end ()); - epochs_m[epoch_a] = { signer_a, link_a }; -} - -bool nano::epochs::is_sequential (nano::epoch epoch_a, nano::epoch new_epoch_a) -{ - auto head_epoch = std::underlying_type_t (epoch_a); - bool is_valid_epoch (head_epoch >= std::underlying_type_t (nano::epoch::epoch_0)); - return is_valid_epoch && (std::underlying_type_t (new_epoch_a) == (head_epoch + 1)); -} - std::underlying_type_t nano::normalized_epoch (nano::epoch epoch_a) { // Currently assumes that the epoch versions in the enum are sequential. diff --git a/nano/lib/epoch.hpp b/nano/lib/epoch.hpp index df0a24f7b..4fae5e1a5 100644 --- a/nano/lib/epoch.hpp +++ b/nano/lib/epoch.hpp @@ -1,9 +1,8 @@ #pragma once -#include - +#include +#include #include -#include namespace nano { @@ -31,42 +30,7 @@ struct hash<::nano::epoch> { std::size_t operator() (::nano::epoch const & epoch_a) const { - std::hash> hash; - return hash (static_cast> (epoch_a)); + return std::underlying_type_t<::nano::epoch> (epoch_a); } }; } -namespace nano -{ -class epoch_info -{ -public: - nano::public_key signer; - nano::link link; -}; -class epochs -{ -public: - /** Returns true if link matches one of the released epoch links. - * WARNING: just because a legal block contains an epoch link, it does not mean it is an epoch block. - * A legal block containing an epoch link can easily be constructed by sending to an address identical - * to one of the epoch links. - * Epoch blocks follow the following rules and a block must satisfy them all to be a true epoch block: - * epoch blocks are always state blocks - * epoch blocks never change the balance of an account - * epoch blocks always have a link field that starts with the ascii bytes "epoch v1 block" or "epoch v2 block" (and possibly others in the future) - * epoch blocks never change the representative - * epoch blocks are not signed by the account key, they are signed either by genesis or by special epoch keys - */ - bool is_epoch_link (nano::link const & link_a) const; - nano::link const & link (nano::epoch epoch_a) const; - nano::public_key const & signer (nano::epoch epoch_a) const; - nano::epoch epoch (nano::link const & link_a) const; - void add (nano::epoch epoch_a, nano::public_key const & signer_a, nano::link const & link_a); - /** Checks that new_epoch is 1 version higher than epoch */ - static bool is_sequential (nano::epoch epoch_a, nano::epoch new_epoch_a); - -private: - std::unordered_map epochs_m; -}; -} diff --git a/nano/lib/epochs.cpp b/nano/lib/epochs.cpp new file mode 100644 index 000000000..426d5ab10 --- /dev/null +++ b/nano/lib/epochs.cpp @@ -0,0 +1,39 @@ +#include +#include + +#include + +nano::link const & nano::epochs::link (nano::epoch epoch_a) const +{ + return epochs_m.at (epoch_a).link; +} + +bool nano::epochs::is_epoch_link (nano::link const & link_a) const +{ + return std::any_of (epochs_m.begin (), epochs_m.end (), [&link_a] (auto const & item_a) { return item_a.second.link == link_a; }); +} + +nano::public_key const & nano::epochs::signer (nano::epoch epoch_a) const +{ + return epochs_m.at (epoch_a).signer; +} + +nano::epoch nano::epochs::epoch (nano::link const & link_a) const +{ + auto existing (std::find_if (epochs_m.begin (), epochs_m.end (), [&link_a] (auto const & item_a) { return item_a.second.link == link_a; })); + debug_assert (existing != epochs_m.end ()); + return existing->first; +} + +void nano::epochs::add (nano::epoch epoch_a, nano::public_key const & signer_a, nano::link const & link_a) +{ + debug_assert (epochs_m.find (epoch_a) == epochs_m.end ()); + epochs_m[epoch_a] = { signer_a, link_a }; +} + +bool nano::epochs::is_sequential (nano::epoch epoch_a, nano::epoch new_epoch_a) +{ + auto head_epoch = std::underlying_type_t (epoch_a); + bool is_valid_epoch (head_epoch >= std::underlying_type_t (nano::epoch::epoch_0)); + return is_valid_epoch && (std::underlying_type_t (new_epoch_a) == (head_epoch + 1)); +} diff --git a/nano/lib/epochs.hpp b/nano/lib/epochs.hpp new file mode 100644 index 000000000..c81ade7f2 --- /dev/null +++ b/nano/lib/epochs.hpp @@ -0,0 +1,42 @@ +#pragma once + +#include +#include + +#include +#include + +namespace nano +{ +class epoch_info +{ +public: + nano::public_key signer; + nano::link link; +}; +class epochs +{ +public: + /** Returns true if link matches one of the released epoch links. + * WARNING: just because a legal block contains an epoch link, it does not mean it is an epoch block. + * A legal block containing an epoch link can easily be constructed by sending to an address identical + * to one of the epoch links. + * Epoch blocks follow the following rules and a block must satisfy them all to be a true epoch block: + * epoch blocks are always state blocks + * epoch blocks never change the balance of an account + * epoch blocks always have a link field that starts with the ascii bytes "epoch v1 block" or "epoch v2 block" (and possibly others in the future) + * epoch blocks never change the representative + * epoch blocks are not signed by the account key, they are signed either by genesis or by special epoch keys + */ + bool is_epoch_link (nano::link const & link_a) const; + nano::link const & link (nano::epoch epoch_a) const; + nano::public_key const & signer (nano::epoch epoch_a) const; + nano::epoch epoch (nano::link const & link_a) const; + void add (nano::epoch epoch_a, nano::public_key const & signer_a, nano::link const & link_a); + /** Checks that new_epoch is 1 version higher than epoch */ + static bool is_sequential (nano::epoch epoch_a, nano::epoch new_epoch_a); + +private: + std::unordered_map epochs_m; +}; +} diff --git a/nano/node/epoch_upgrader.hpp b/nano/node/epoch_upgrader.hpp index d9bccad98..d2de09b41 100644 --- a/nano/node/epoch_upgrader.hpp +++ b/nano/node/epoch_upgrader.hpp @@ -1,22 +1,26 @@ #pragma once -#include #include #include #include +#include #include namespace nano { +enum class epoch : uint8_t; +class network_params; class node; class ledger; -namespace store -{ - class component; } -class network_params; +namespace nano::store +{ +class component; +} +namespace nano +{ class epoch_upgrader final { public: diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index e1639bd26..d79e314a3 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include #include From 4d86e5fab3f950ba0b4815a61f3febc82bacbf22 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 18:16:08 +0000 Subject: [PATCH 04/25] Using standard threads rather than boost threads and using default stack size. --- nano/lib/work.cpp | 4 ++-- nano/lib/work.hpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nano/lib/work.cpp b/nano/lib/work.cpp index 7ee17cd1f..7d9165c19 100644 --- a/nano/lib/work.cpp +++ b/nano/lib/work.cpp @@ -41,7 +41,7 @@ nano::work_pool::work_pool (nano::network_constants & network_constants, unsigne } for (auto i (0u); i < count; ++i) { - threads.emplace_back (nano::thread_attributes::get_default (), [this, i] () { + threads.emplace_back ([this, i] () { nano::thread_role::set (nano::thread_role::name::work); nano::work_thread_reprioritize (); loop (i); @@ -240,4 +240,4 @@ nano::container_info nano::work_pool::container_info () const info.put ("pending", pending); info.add ("work_observers", work_observers.container_info ()); return info; -} \ No newline at end of file +} diff --git a/nano/lib/work.hpp b/nano/lib/work.hpp index 164064893..0336d10a0 100644 --- a/nano/lib/work.hpp +++ b/nano/lib/work.hpp @@ -8,10 +8,10 @@ #include #include -#include #include #include +#include namespace nano { @@ -54,7 +54,7 @@ public: nano::network_constants & network_constants; std::atomic ticket; bool done; - std::vector threads; + std::vector threads; std::list pending; mutable nano::mutex mutex{ mutex_identifier (mutexes::work_pool) }; nano::condition_variable producer_condition; From 56da1b2dec0febf8c989b33b827c36b0bc17eb45 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 19:52:58 +0000 Subject: [PATCH 05/25] Move singleton memory pool class to memory.hpp and reducing headers. --- nano/core_test/entry.cpp | 2 +- nano/lib/memory.hpp | 10 ++++++++++ nano/node/common.hpp | 23 +++++------------------ nano/qt_test/entry.cpp | 2 +- nano/secure/common.hpp | 5 ----- nano/slow_test/entry.cpp | 2 +- 6 files changed, 18 insertions(+), 26 deletions(-) diff --git a/nano/core_test/entry.cpp b/nano/core_test/entry.cpp index 9d08284dd..7c51ce85b 100644 --- a/nano/core_test/entry.cpp +++ b/nano/core_test/entry.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/nano/lib/memory.hpp b/nano/lib/memory.hpp index 333a5ff98..3d0a248a2 100644 --- a/nano/lib/memory.hpp +++ b/nano/lib/memory.hpp @@ -48,6 +48,16 @@ private: std::vector> cleanup_funcs; }; +/** Helper guard which contains all the necessary purge (remove all memory even if used) functions */ +class node_singleton_memory_pool_purge_guard +{ +public: + node_singleton_memory_pool_purge_guard (); + +private: + nano::cleanup_guard cleanup_guard; +}; + template std::shared_ptr make_shared (Args &&... args) { diff --git a/nano/node/common.hpp b/nano/node/common.hpp index 5dd98516d..c62c30132 100644 --- a/nano/node/common.hpp +++ b/nano/node/common.hpp @@ -1,14 +1,14 @@ #pragma once -#include -#include -#include -#include #include -#include #include +namespace boost::asio::ip +{ +class address; +} + namespace nano { bool parse_port (std::string const &, uint16_t &); @@ -126,16 +126,3 @@ struct hash } }; } - -namespace nano -{ -/** Helper guard which contains all the necessary purge (remove all memory even if used) functions */ -class node_singleton_memory_pool_purge_guard -{ -public: - node_singleton_memory_pool_purge_guard (); - -private: - nano::cleanup_guard cleanup_guard; -}; -} diff --git a/nano/qt_test/entry.cpp b/nano/qt_test/entry.cpp index b3ce57fd8..1847ff850 100644 --- a/nano/qt_test/entry.cpp +++ b/nano/qt_test/entry.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index d79e314a3..b3711d88e 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -13,11 +13,6 @@ #include #include -#include -#include -#include -#include - #include #include diff --git a/nano/slow_test/entry.cpp b/nano/slow_test/entry.cpp index 096c7dc6a..83d12130d 100644 --- a/nano/slow_test/entry.cpp +++ b/nano/slow_test/entry.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include From aecf0748b3ebf8f972c065cc9b6b6108f0df4591 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 20:16:57 +0000 Subject: [PATCH 06/25] Forward declare endpoint in lib/common.hpp --- nano/lib/CMakeLists.txt | 1 + nano/lib/common.hpp | 11 ++++++++--- nano/node/common.hpp | 1 + nano/node/portmapping.hpp | 1 + nano/secure/common.cpp | 1 + 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index 386189342..7c781add2 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -33,6 +33,7 @@ add_library( char_traits.hpp cli.hpp cli.cpp + common.hpp config.hpp config.cpp configbase.hpp diff --git a/nano/lib/common.hpp b/nano/lib/common.hpp index bd1f30994..1e54097d0 100644 --- a/nano/lib/common.hpp +++ b/nano/lib/common.hpp @@ -1,9 +1,14 @@ #pragma once -#include +namespace boost::asio::ip +{ +class tcp; +template +class basic_endpoint; +} namespace nano { -using endpoint = boost::asio::ip::tcp::endpoint; +using endpoint = boost::asio::ip::basic_endpoint; using tcp_endpoint = endpoint; -} \ No newline at end of file +} diff --git a/nano/node/common.hpp b/nano/node/common.hpp index c62c30132..92613306e 100644 --- a/nano/node/common.hpp +++ b/nano/node/common.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/nano/node/portmapping.hpp b/nano/node/portmapping.hpp index cc542896a..437852e94 100644 --- a/nano/node/portmapping.hpp +++ b/nano/node/portmapping.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index f5fd8e44f..920e20d51 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -1,3 +1,4 @@ +#include #include #include #include From 8f0b2c5fc2445696a5e5476b067b43bd6ce4ea14 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 20:23:51 +0000 Subject: [PATCH 07/25] Forward declare jsonconfig in messages.hpp --- nano/core_test/websocket.cpp | 1 + nano/node/json_handler.cpp | 1 + nano/node/messages.cpp | 1 + nano/node/messages.hpp | 6 +++++- nano/node/repcrawler.hpp | 1 + nano/node/websocket.cpp | 1 + nano/rpc_test/rpc.cpp | 1 + 7 files changed, 11 insertions(+), 1 deletion(-) diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index 90991493d..65a18dd21 100644 --- a/nano/core_test/websocket.cpp +++ b/nano/core_test/websocket.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 344910ae9..2b90c682e 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index c6e5dc479..022c54d8e 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 00f1070b0..2aeb4aef6 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -22,6 +21,11 @@ #include #include +namespace nano +{ +class jsonconfig; +} + namespace nano { /** diff --git a/nano/node/repcrawler.hpp b/nano/node/repcrawler.hpp index c7892399e..cd9d68009 100644 --- a/nano/node/repcrawler.hpp +++ b/nano/node/repcrawler.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index 4742c7dd7..653c60f76 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 8198cc9ca..bf3c5f60c 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include From 8dad87f9c068ff318dc6f78b6713841bcc5ba2c3 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 21:01:23 +0000 Subject: [PATCH 08/25] Move block_details and block_sideband implementations to its own file. --- nano/lib/block_sideband.cpp | 215 ++++++++++++++++++++++++++++++++++++ nano/lib/blocks.cpp | 210 ----------------------------------- 2 files changed, 215 insertions(+), 210 deletions(-) diff --git a/nano/lib/block_sideband.cpp b/nano/lib/block_sideband.cpp index e69de29bb..14fd1b3c8 100644 --- a/nano/lib/block_sideband.cpp +++ b/nano/lib/block_sideband.cpp @@ -0,0 +1,215 @@ +#include +#include +#include + +#include + +/* + * block_details + */ + +nano::block_details::block_details (nano::epoch const epoch_a, bool const is_send_a, bool const is_receive_a, bool const is_epoch_a) : + epoch (epoch_a), is_send (is_send_a), is_receive (is_receive_a), is_epoch (is_epoch_a) +{ +} + +bool nano::block_details::operator== (nano::block_details const & other_a) const +{ + return epoch == other_a.epoch && is_send == other_a.is_send && is_receive == other_a.is_receive && is_epoch == other_a.is_epoch; +} + +uint8_t nano::block_details::packed () const +{ + std::bitset<8> result (static_cast (epoch)); + result.set (7, is_send); + result.set (6, is_receive); + result.set (5, is_epoch); + return static_cast (result.to_ulong ()); +} + +void nano::block_details::unpack (uint8_t details_a) +{ + constexpr std::bitset<8> epoch_mask{ 0b00011111 }; + auto as_bitset = static_cast> (details_a); + is_send = as_bitset.test (7); + is_receive = as_bitset.test (6); + is_epoch = as_bitset.test (5); + epoch = static_cast ((as_bitset & epoch_mask).to_ulong ()); +} + +void nano::block_details::serialize (nano::stream & stream_a) const +{ + nano::write (stream_a, packed ()); +} + +bool nano::block_details::deserialize (nano::stream & stream_a) +{ + bool result (false); + try + { + uint8_t packed{ 0 }; + nano::read (stream_a, packed); + unpack (packed); + } + catch (std::runtime_error &) + { + result = true; + } + + return result; +} + +void nano::block_details::operator() (nano::object_stream & obs) const +{ + obs.write ("epoch", epoch); + obs.write ("is_send", is_send); + obs.write ("is_receive", is_receive); + obs.write ("is_epoch", is_epoch); +} + +std::string nano::state_subtype (nano::block_details const details_a) +{ + debug_assert (details_a.is_epoch + details_a.is_receive + details_a.is_send <= 1); + if (details_a.is_send) + { + return "send"; + } + else if (details_a.is_receive) + { + return "receive"; + } + else if (details_a.is_epoch) + { + return "epoch"; + } + else + { + return "change"; + } +} + +/* + * block_sideband + */ + +nano::block_sideband::block_sideband (nano::account const & account_a, nano::block_hash const & successor_a, nano::amount const & balance_a, uint64_t const height_a, nano::seconds_t const timestamp_a, nano::block_details const & details_a, nano::epoch const source_epoch_a) : + successor (successor_a), + account (account_a), + balance (balance_a), + height (height_a), + timestamp (timestamp_a), + details (details_a), + source_epoch (source_epoch_a) +{ +} + +nano::block_sideband::block_sideband (nano::account const & account_a, nano::block_hash const & successor_a, nano::amount const & balance_a, uint64_t const height_a, nano::seconds_t const timestamp_a, nano::epoch const epoch_a, bool const is_send, bool const is_receive, bool const is_epoch, nano::epoch const source_epoch_a) : + successor (successor_a), + account (account_a), + balance (balance_a), + height (height_a), + timestamp (timestamp_a), + details (epoch_a, is_send, is_receive, is_epoch), + source_epoch (source_epoch_a) +{ +} + +size_t nano::block_sideband::size (nano::block_type type_a) +{ + size_t result (0); + result += sizeof (successor); + if (type_a != nano::block_type::state && type_a != nano::block_type::open) + { + result += sizeof (account); + } + if (type_a != nano::block_type::open) + { + result += sizeof (height); + } + if (type_a == nano::block_type::receive || type_a == nano::block_type::change || type_a == nano::block_type::open) + { + result += sizeof (balance); + } + result += sizeof (timestamp); + if (type_a == nano::block_type::state) + { + static_assert (sizeof (nano::epoch) == nano::block_details::size (), "block_details is larger than the epoch enum"); + result += nano::block_details::size () + sizeof (nano::epoch); + } + return result; +} + +void nano::block_sideband::serialize (nano::stream & stream_a, nano::block_type type_a) const +{ + nano::write (stream_a, successor.bytes); + if (type_a != nano::block_type::state && type_a != nano::block_type::open) + { + nano::write (stream_a, account.bytes); + } + if (type_a != nano::block_type::open) + { + nano::write (stream_a, boost::endian::native_to_big (height)); + } + if (type_a == nano::block_type::receive || type_a == nano::block_type::change || type_a == nano::block_type::open) + { + nano::write (stream_a, balance.bytes); + } + nano::write (stream_a, boost::endian::native_to_big (timestamp)); + if (type_a == nano::block_type::state) + { + details.serialize (stream_a); + nano::write (stream_a, static_cast (source_epoch)); + } +} + +bool nano::block_sideband::deserialize (nano::stream & stream_a, nano::block_type type_a) +{ + bool result (false); + try + { + nano::read (stream_a, successor.bytes); + if (type_a != nano::block_type::state && type_a != nano::block_type::open) + { + nano::read (stream_a, account.bytes); + } + if (type_a != nano::block_type::open) + { + nano::read (stream_a, height); + boost::endian::big_to_native_inplace (height); + } + else + { + height = 1; + } + if (type_a == nano::block_type::receive || type_a == nano::block_type::change || type_a == nano::block_type::open) + { + nano::read (stream_a, balance.bytes); + } + nano::read (stream_a, timestamp); + boost::endian::big_to_native_inplace (timestamp); + if (type_a == nano::block_type::state) + { + result = details.deserialize (stream_a); + uint8_t source_epoch_uint8_t{ 0 }; + nano::read (stream_a, source_epoch_uint8_t); + source_epoch = static_cast (source_epoch_uint8_t); + } + } + catch (std::runtime_error &) + { + result = true; + } + + return result; +} + +void nano::block_sideband::operator() (nano::object_stream & obs) const +{ + obs.write ("successor", successor); + obs.write ("account", account); + obs.write ("balance", balance); + obs.write ("height", height); + obs.write ("timestamp", timestamp); + obs.write ("source_epoch", source_epoch); + obs.write ("details", details); +} diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 81da54a85..acf3d0582 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -1909,213 +1909,3 @@ void nano::receive_block::operator() (nano::object_stream & obs) const obs.write ("signature", signature); obs.write ("work", work); } - -/* - * block_details - */ - -nano::block_details::block_details (nano::epoch const epoch_a, bool const is_send_a, bool const is_receive_a, bool const is_epoch_a) : - epoch (epoch_a), is_send (is_send_a), is_receive (is_receive_a), is_epoch (is_epoch_a) -{ -} - -bool nano::block_details::operator== (nano::block_details const & other_a) const -{ - return epoch == other_a.epoch && is_send == other_a.is_send && is_receive == other_a.is_receive && is_epoch == other_a.is_epoch; -} - -uint8_t nano::block_details::packed () const -{ - std::bitset<8> result (static_cast (epoch)); - result.set (7, is_send); - result.set (6, is_receive); - result.set (5, is_epoch); - return static_cast (result.to_ulong ()); -} - -void nano::block_details::unpack (uint8_t details_a) -{ - constexpr std::bitset<8> epoch_mask{ 0b00011111 }; - auto as_bitset = static_cast> (details_a); - is_send = as_bitset.test (7); - is_receive = as_bitset.test (6); - is_epoch = as_bitset.test (5); - epoch = static_cast ((as_bitset & epoch_mask).to_ulong ()); -} - -void nano::block_details::serialize (nano::stream & stream_a) const -{ - nano::write (stream_a, packed ()); -} - -bool nano::block_details::deserialize (nano::stream & stream_a) -{ - bool result (false); - try - { - uint8_t packed{ 0 }; - nano::read (stream_a, packed); - unpack (packed); - } - catch (std::runtime_error &) - { - result = true; - } - - return result; -} - -void nano::block_details::operator() (nano::object_stream & obs) const -{ - obs.write ("epoch", epoch); - obs.write ("is_send", is_send); - obs.write ("is_receive", is_receive); - obs.write ("is_epoch", is_epoch); -} - -std::string nano::state_subtype (nano::block_details const details_a) -{ - debug_assert (details_a.is_epoch + details_a.is_receive + details_a.is_send <= 1); - if (details_a.is_send) - { - return "send"; - } - else if (details_a.is_receive) - { - return "receive"; - } - else if (details_a.is_epoch) - { - return "epoch"; - } - else - { - return "change"; - } -} - -/* - * block_sideband - */ - -nano::block_sideband::block_sideband (nano::account const & account_a, nano::block_hash const & successor_a, nano::amount const & balance_a, uint64_t const height_a, nano::seconds_t const timestamp_a, nano::block_details const & details_a, nano::epoch const source_epoch_a) : - successor (successor_a), - account (account_a), - balance (balance_a), - height (height_a), - timestamp (timestamp_a), - details (details_a), - source_epoch (source_epoch_a) -{ -} - -nano::block_sideband::block_sideband (nano::account const & account_a, nano::block_hash const & successor_a, nano::amount const & balance_a, uint64_t const height_a, nano::seconds_t const timestamp_a, nano::epoch const epoch_a, bool const is_send, bool const is_receive, bool const is_epoch, nano::epoch const source_epoch_a) : - successor (successor_a), - account (account_a), - balance (balance_a), - height (height_a), - timestamp (timestamp_a), - details (epoch_a, is_send, is_receive, is_epoch), - source_epoch (source_epoch_a) -{ -} - -size_t nano::block_sideband::size (nano::block_type type_a) -{ - size_t result (0); - result += sizeof (successor); - if (type_a != nano::block_type::state && type_a != nano::block_type::open) - { - result += sizeof (account); - } - if (type_a != nano::block_type::open) - { - result += sizeof (height); - } - if (type_a == nano::block_type::receive || type_a == nano::block_type::change || type_a == nano::block_type::open) - { - result += sizeof (balance); - } - result += sizeof (timestamp); - if (type_a == nano::block_type::state) - { - static_assert (sizeof (nano::epoch) == nano::block_details::size (), "block_details is larger than the epoch enum"); - result += nano::block_details::size () + sizeof (nano::epoch); - } - return result; -} - -void nano::block_sideband::serialize (nano::stream & stream_a, nano::block_type type_a) const -{ - nano::write (stream_a, successor.bytes); - if (type_a != nano::block_type::state && type_a != nano::block_type::open) - { - nano::write (stream_a, account.bytes); - } - if (type_a != nano::block_type::open) - { - nano::write (stream_a, boost::endian::native_to_big (height)); - } - if (type_a == nano::block_type::receive || type_a == nano::block_type::change || type_a == nano::block_type::open) - { - nano::write (stream_a, balance.bytes); - } - nano::write (stream_a, boost::endian::native_to_big (timestamp)); - if (type_a == nano::block_type::state) - { - details.serialize (stream_a); - nano::write (stream_a, static_cast (source_epoch)); - } -} - -bool nano::block_sideband::deserialize (nano::stream & stream_a, nano::block_type type_a) -{ - bool result (false); - try - { - nano::read (stream_a, successor.bytes); - if (type_a != nano::block_type::state && type_a != nano::block_type::open) - { - nano::read (stream_a, account.bytes); - } - if (type_a != nano::block_type::open) - { - nano::read (stream_a, height); - boost::endian::big_to_native_inplace (height); - } - else - { - height = 1; - } - if (type_a == nano::block_type::receive || type_a == nano::block_type::change || type_a == nano::block_type::open) - { - nano::read (stream_a, balance.bytes); - } - nano::read (stream_a, timestamp); - boost::endian::big_to_native_inplace (timestamp); - if (type_a == nano::block_type::state) - { - result = details.deserialize (stream_a); - uint8_t source_epoch_uint8_t{ 0 }; - nano::read (stream_a, source_epoch_uint8_t); - source_epoch = static_cast (source_epoch_uint8_t); - } - } - catch (std::runtime_error &) - { - result = true; - } - - return result; -} - -void nano::block_sideband::operator() (nano::object_stream & obs) const -{ - obs.write ("successor", successor); - obs.write ("account", account); - obs.write ("balance", balance); - obs.write ("height", height); - obs.write ("timestamp", timestamp); - obs.write ("source_epoch", source_epoch); - obs.write ("details", details); -} From fc36f0896cc3017fec5811c7a828861cf179f411 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 21:59:03 +0000 Subject: [PATCH 09/25] Forward declare hash specialisations and move implementations to numbers_templ.hpp --- nano/core_test/numbers.cpp | 3 +- nano/lib/CMakeLists.txt | 1 + nano/lib/block_uniquer.hpp | 1 + nano/lib/numbers.hpp | 178 ++++------------------------- nano/lib/numbers_templ.hpp | 189 +++++++++++++++++++++++++++++++ nano/node/local_vote_history.hpp | 1 + nano/node/vote_spacing.hpp | 1 + nano/secure/pending_info.hpp | 1 + nano/secure/rep_weights.hpp | 1 + 9 files changed, 220 insertions(+), 156 deletions(-) create mode 100644 nano/lib/numbers_templ.hpp diff --git a/nano/core_test/numbers.cpp b/nano/core_test/numbers.cpp index a30b2eb10..ec8bed3f4 100644 --- a/nano/core_test/numbers.cpp +++ b/nano/core_test/numbers.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -647,4 +648,4 @@ TEST (uint512_union, hash) ASSERT_NE (h (x1), h (x2)); } } -} \ No newline at end of file +} diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index 7c781add2..e3d7375c8 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -72,6 +72,7 @@ add_library( network_filter.cpp numbers.hpp numbers.cpp + numbers_templ.hpp object_stream.hpp object_stream.cpp object_stream_adapters.hpp diff --git a/nano/lib/block_uniquer.hpp b/nano/lib/block_uniquer.hpp index d39bb3afc..4a0c7076b 100644 --- a/nano/lib/block_uniquer.hpp +++ b/nano/lib/block_uniquer.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include namespace nano diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index bf8137c65..ccf42ba35 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include @@ -516,185 +516,53 @@ namespace difficulty namespace std { template <> -struct hash<::nano::uint128_union> -{ - size_t operator() (::nano::uint128_union const & value) const noexcept - { - return value.qwords[0] + value.qwords[1]; - } -}; +struct hash<::nano::uint128_union>; template <> -struct hash<::nano::uint256_union> -{ - size_t operator() (::nano::uint256_union const & value) const noexcept - { - return value.qwords[0] + value.qwords[1] + value.qwords[2] + value.qwords[3]; - } -}; +struct hash<::nano::uint256_union>; template <> -struct hash<::nano::public_key> -{ - size_t operator() (::nano::public_key const & value) const noexcept - { - return hash<::nano::uint256_union>{}(value); - } -}; +struct hash<::nano::public_key>; template <> -struct hash<::nano::block_hash> -{ - size_t operator() (::nano::block_hash const & value) const noexcept - { - return hash<::nano::uint256_union>{}(value); - } -}; +struct hash<::nano::block_hash>; template <> -struct hash<::nano::hash_or_account> -{ - size_t operator() (::nano::hash_or_account const & value) const noexcept - { - return hash<::nano::block_hash>{}(value.as_block_hash ()); - } -}; +struct hash<::nano::hash_or_account>; template <> -struct hash<::nano::root> -{ - size_t operator() (::nano::root const & value) const noexcept - { - return hash<::nano::hash_or_account>{}(value); - } -}; +struct hash<::nano::root>; template <> -struct hash<::nano::link> -{ - size_t operator() (::nano::link const & value) const noexcept - { - return hash<::nano::hash_or_account>{}(value); - } -}; +struct hash<::nano::link>; template <> -struct hash<::nano::raw_key> -{ - size_t operator() (::nano::raw_key const & value) const noexcept - { - return hash<::nano::uint256_union>{}(value); - } -}; +struct hash<::nano::raw_key>; template <> -struct hash<::nano::wallet_id> -{ - size_t operator() (::nano::wallet_id const & value) const noexcept - { - return hash<::nano::uint256_union>{}(value); - } -}; +struct hash<::nano::wallet_id>; template <> -struct hash<::nano::uint512_union> -{ - size_t operator() (::nano::uint512_union const & value) const noexcept - { - return hash<::nano::uint256_union>{}(value.uint256s[0]) + hash<::nano::uint256_union> () (value.uint256s[1]); - } -}; +struct hash<::nano::uint512_union>; template <> -struct hash<::nano::qualified_root> -{ - size_t operator() (::nano::qualified_root const & value) const noexcept - { - return hash<::nano::uint512_union>{}(value); - } -}; +struct hash<::nano::qualified_root>; } namespace boost { template <> -struct hash<::nano::uint128_union> -{ - size_t operator() (::nano::uint128_union const & value) const noexcept - { - return std::hash<::nano::uint128_union> () (value); - } -}; +struct hash<::nano::uint128_union>; template <> -struct hash<::nano::uint256_union> -{ - size_t operator() (::nano::uint256_union const & value) const noexcept - { - return std::hash<::nano::uint256_union> () (value); - } -}; +struct hash<::nano::uint256_union>; template <> -struct hash<::nano::public_key> -{ - size_t operator() (::nano::public_key const & value) const noexcept - { - return std::hash<::nano::public_key> () (value); - } -}; +struct hash<::nano::public_key>; template <> -struct hash<::nano::block_hash> -{ - size_t operator() (::nano::block_hash const & value) const noexcept - { - return std::hash<::nano::block_hash> () (value); - } -}; +struct hash<::nano::block_hash>; template <> -struct hash<::nano::hash_or_account> -{ - size_t operator() (::nano::hash_or_account const & value) const noexcept - { - return std::hash<::nano::hash_or_account> () (value); - } -}; +struct hash<::nano::hash_or_account>; template <> -struct hash<::nano::root> -{ - size_t operator() (::nano::root const & value) const noexcept - { - return std::hash<::nano::root> () (value); - } -}; +struct hash<::nano::root>; template <> -struct hash<::nano::link> -{ - size_t operator() (::nano::link const & value) const noexcept - { - return std::hash<::nano::link> () (value); - } -}; +struct hash<::nano::link>; template <> -struct hash<::nano::raw_key> -{ - size_t operator() (::nano::raw_key const & value) const noexcept - { - return std::hash<::nano::raw_key> () (value); - } -}; +struct hash<::nano::raw_key>; template <> -struct hash<::nano::wallet_id> -{ - size_t operator() (::nano::wallet_id const & value) const noexcept - { - return std::hash<::nano::wallet_id> () (value); - } -}; +struct hash<::nano::wallet_id>; template <> -struct hash<::nano::uint512_union> -{ - size_t operator() (::nano::uint512_union const & value) const noexcept - { - return std::hash<::nano::uint512_union> () (value); - } -}; +struct hash<::nano::uint512_union>; template <> -struct hash<::nano::qualified_root> -{ - size_t operator() (::nano::qualified_root const & value) const noexcept - { - return std::hash<::nano::qualified_root> () (value); - } -}; +struct hash<::nano::qualified_root>; } /* diff --git a/nano/lib/numbers_templ.hpp b/nano/lib/numbers_templ.hpp new file mode 100644 index 000000000..d40de592a --- /dev/null +++ b/nano/lib/numbers_templ.hpp @@ -0,0 +1,189 @@ +#pragma once + +#include + +#include + +namespace std +{ +template <> +struct hash<::nano::uint128_union> +{ + size_t operator() (::nano::uint128_union const & value) const noexcept + { + return value.qwords[0] + value.qwords[1]; + } +}; +template <> +struct hash<::nano::uint256_union> +{ + size_t operator() (::nano::uint256_union const & value) const noexcept + { + return value.qwords[0] + value.qwords[1] + value.qwords[2] + value.qwords[3]; + } +}; +template <> +struct hash<::nano::public_key> +{ + size_t operator() (::nano::public_key const & value) const noexcept + { + return hash<::nano::uint256_union>{}(value); + } +}; +template <> +struct hash<::nano::block_hash> +{ + size_t operator() (::nano::block_hash const & value) const noexcept + { + return hash<::nano::uint256_union>{}(value); + } +}; +template <> +struct hash<::nano::hash_or_account> +{ + size_t operator() (::nano::hash_or_account const & value) const noexcept + { + return hash<::nano::block_hash>{}(value.as_block_hash ()); + } +}; +template <> +struct hash<::nano::root> +{ + size_t operator() (::nano::root const & value) const noexcept + { + return hash<::nano::hash_or_account>{}(value); + } +}; +template <> +struct hash<::nano::link> +{ + size_t operator() (::nano::link const & value) const noexcept + { + return hash<::nano::hash_or_account>{}(value); + } +}; +template <> +struct hash<::nano::raw_key> +{ + size_t operator() (::nano::raw_key const & value) const noexcept + { + return hash<::nano::uint256_union>{}(value); + } +}; +template <> +struct hash<::nano::wallet_id> +{ + size_t operator() (::nano::wallet_id const & value) const noexcept + { + return hash<::nano::uint256_union>{}(value); + } +}; +template <> +struct hash<::nano::uint512_union> +{ + size_t operator() (::nano::uint512_union const & value) const noexcept + { + return hash<::nano::uint256_union>{}(value.uint256s[0]) + hash<::nano::uint256_union> () (value.uint256s[1]); + } +}; +template <> +struct hash<::nano::qualified_root> +{ + size_t operator() (::nano::qualified_root const & value) const noexcept + { + return hash<::nano::uint512_union>{}(value); + } +}; +} + +namespace boost +{ +template <> +struct hash<::nano::uint128_union> +{ + size_t operator() (::nano::uint128_union const & value) const noexcept + { + return std::hash<::nano::uint128_union> () (value); + } +}; +template <> +struct hash<::nano::uint256_union> +{ + size_t operator() (::nano::uint256_union const & value) const noexcept + { + return std::hash<::nano::uint256_union> () (value); + } +}; +template <> +struct hash<::nano::public_key> +{ + size_t operator() (::nano::public_key const & value) const noexcept + { + return std::hash<::nano::public_key> () (value); + } +}; +template <> +struct hash<::nano::block_hash> +{ + size_t operator() (::nano::block_hash const & value) const noexcept + { + return std::hash<::nano::block_hash> () (value); + } +}; +template <> +struct hash<::nano::hash_or_account> +{ + size_t operator() (::nano::hash_or_account const & value) const noexcept + { + return std::hash<::nano::hash_or_account> () (value); + } +}; +template <> +struct hash<::nano::root> +{ + size_t operator() (::nano::root const & value) const noexcept + { + return std::hash<::nano::root> () (value); + } +}; +template <> +struct hash<::nano::link> +{ + size_t operator() (::nano::link const & value) const noexcept + { + return std::hash<::nano::link> () (value); + } +}; +template <> +struct hash<::nano::raw_key> +{ + size_t operator() (::nano::raw_key const & value) const noexcept + { + return std::hash<::nano::raw_key> () (value); + } +}; +template <> +struct hash<::nano::wallet_id> +{ + size_t operator() (::nano::wallet_id const & value) const noexcept + { + return std::hash<::nano::wallet_id> () (value); + } +}; +template <> +struct hash<::nano::uint512_union> +{ + size_t operator() (::nano::uint512_union const & value) const noexcept + { + return std::hash<::nano::uint512_union> () (value); + } +}; +template <> +struct hash<::nano::qualified_root> +{ + size_t operator() (::nano::qualified_root const & value) const noexcept + { + return std::hash<::nano::qualified_root> () (value); + } +}; +} diff --git a/nano/node/local_vote_history.hpp b/nano/node/local_vote_history.hpp index 311867e21..9ee4e38c6 100644 --- a/nano/node/local_vote_history.hpp +++ b/nano/node/local_vote_history.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/nano/node/vote_spacing.hpp b/nano/node/vote_spacing.hpp index f46cd6352..c5ee41827 100644 --- a/nano/node/vote_spacing.hpp +++ b/nano/node/vote_spacing.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/nano/secure/pending_info.hpp b/nano/secure/pending_info.hpp index c00e1cdb3..90e8f5246 100644 --- a/nano/secure/pending_info.hpp +++ b/nano/secure/pending_info.hpp @@ -2,6 +2,7 @@ #include #include +#include #include namespace nano diff --git a/nano/secure/rep_weights.hpp b/nano/secure/rep_weights.hpp index 9209bbf25..29a2c2804 100644 --- a/nano/secure/rep_weights.hpp +++ b/nano/secure/rep_weights.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include From 619a7f7e879769b775817a62e70d5a7bb9d8bfe9 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 23:06:44 +0000 Subject: [PATCH 10/25] Create stream_fwd.hpp header for stream forward declarations. --- nano/lib/CMakeLists.txt | 1 + nano/lib/block_sideband.cpp | 1 + nano/lib/block_sideband.hpp | 2 +- nano/lib/blocks.cpp | 1 + nano/lib/blocks.hpp | 2 +- nano/lib/stream_fwd.hpp | 10 ++++++++++ nano/node/bootstrap_ascending/account_sets.cpp | 4 +++- nano/node/distributed_work.cpp | 1 + nano/node/local_block_broadcaster.cpp | 4 +++- nano/node/messages.hpp | 2 +- nano/secure/account_info.cpp | 3 ++- nano/secure/account_info.hpp | 2 +- nano/secure/account_iterator_impl.hpp | 1 + nano/secure/common.cpp | 1 + nano/secure/pending_info.cpp | 1 + nano/secure/pending_info.hpp | 2 +- nano/secure/receivable_iterator_impl.hpp | 1 + nano/secure/vote.cpp | 3 ++- nano/secure/vote.hpp | 2 +- nano/store/component.hpp | 1 - 20 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 nano/lib/stream_fwd.hpp diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index e3d7375c8..36647fd88 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -97,6 +97,7 @@ add_library( stats_enums.cpp stats_sinks.hpp stream.hpp + stream_fwd.hpp thread_pool.hpp thread_roles.hpp thread_roles.cpp diff --git a/nano/lib/block_sideband.cpp b/nano/lib/block_sideband.cpp index 14fd1b3c8..8b37f71db 100644 --- a/nano/lib/block_sideband.cpp +++ b/nano/lib/block_sideband.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include diff --git a/nano/lib/block_sideband.hpp b/nano/lib/block_sideband.hpp index e150538ae..6ed9c6e9b 100644 --- a/nano/lib/block_sideband.hpp +++ b/nano/lib/block_sideband.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index acf3d0582..2c7510cd8 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 2312855cb..41e08f89e 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include diff --git a/nano/lib/stream_fwd.hpp b/nano/lib/stream_fwd.hpp new file mode 100644 index 000000000..1b8bddd24 --- /dev/null +++ b/nano/lib/stream_fwd.hpp @@ -0,0 +1,10 @@ +#pragma once + +#include +#include + +struct uint8_char_traits; +namespace nano +{ +using stream = std::basic_streambuf; +} diff --git a/nano/node/bootstrap_ascending/account_sets.cpp b/nano/node/bootstrap_ascending/account_sets.cpp index 4d0a276df..692ac43fd 100644 --- a/nano/node/bootstrap_ascending/account_sets.cpp +++ b/nano/node/bootstrap_ascending/account_sets.cpp @@ -3,6 +3,8 @@ #include #include +#include + #include #include #include @@ -354,4 +356,4 @@ nano::container_info nano::bootstrap_ascending::account_sets::container_info () info.put ("blocking", blocking); info.put ("blocking_unknown", blocking_unknown); return info; -} \ No newline at end of file +} diff --git a/nano/node/distributed_work.cpp b/nano/node/distributed_work.cpp index 81d771a5e..a7cb40598 100644 --- a/nano/node/distributed_work.cpp +++ b/nano/node/distributed_work.cpp @@ -5,6 +5,7 @@ #include #include +#include std::shared_ptr nano::distributed_work::peer_request::get_prepared_json_request (std::string const & request_string_a) const { diff --git a/nano/node/local_block_broadcaster.cpp b/nano/node/local_block_broadcaster.cpp index ad1a2201f..f136bd036 100644 --- a/nano/node/local_block_broadcaster.cpp +++ b/nano/node/local_block_broadcaster.cpp @@ -8,6 +8,8 @@ #include #include +#include + nano::local_block_broadcaster::local_block_broadcaster (local_block_broadcaster_config const & config_a, nano::node & node_a, nano::block_processor & block_processor_a, nano::network & network_a, nano::confirming_set & confirming_set_a, nano::stats & stats_a, nano::logger & logger_a, bool enabled_a) : config{ config_a }, node{ node_a }, @@ -230,4 +232,4 @@ nano::container_info nano::local_block_broadcaster::container_info () const nano::container_info info; info.put ("local", local_blocks); return info; -} \ No newline at end of file +} diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 2aeb4aef6..9b315f538 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/secure/account_info.cpp b/nano/secure/account_info.cpp index 1b18ca602..81bcec0c6 100644 --- a/nano/secure/account_info.cpp +++ b/nano/secure/account_info.cpp @@ -1,3 +1,4 @@ +#include #include nano::account_info::account_info (nano::block_hash const & head_a, nano::account const & representative_a, nano::block_hash const & open_block_a, nano::amount const & balance_a, nano::seconds_t modified_a, uint64_t block_count_a, nano::epoch epoch_a) : @@ -90,4 +91,4 @@ bool nano::account_info_v22::deserialize (nano::stream & stream_a) } return error; -} \ No newline at end of file +} diff --git a/nano/secure/account_info.hpp b/nano/secure/account_info.hpp index ee850d8d2..c8c018815 100644 --- a/nano/secure/account_info.hpp +++ b/nano/secure/account_info.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include namespace nano diff --git a/nano/secure/account_iterator_impl.hpp b/nano/secure/account_iterator_impl.hpp index a68f70b35..af8d0a7a1 100644 --- a/nano/secure/account_iterator_impl.hpp +++ b/nano/secure/account_iterator_impl.hpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index 920e20d51..2d912fb3c 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/secure/pending_info.cpp b/nano/secure/pending_info.cpp index a9d52588a..85a32a8aa 100644 --- a/nano/secure/pending_info.cpp +++ b/nano/secure/pending_info.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/nano/secure/pending_info.hpp b/nano/secure/pending_info.hpp index 90e8f5246..627db34aa 100644 --- a/nano/secure/pending_info.hpp +++ b/nano/secure/pending_info.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include namespace nano { diff --git a/nano/secure/receivable_iterator_impl.hpp b/nano/secure/receivable_iterator_impl.hpp index b2cbebef7..f2e1867df 100644 --- a/nano/secure/receivable_iterator_impl.hpp +++ b/nano/secure/receivable_iterator_impl.hpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/nano/secure/vote.cpp b/nano/secure/vote.cpp index 296886634..b7b7e6c63 100644 --- a/nano/secure/vote.cpp +++ b/nano/secure/vote.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -193,4 +194,4 @@ void nano::vote::operator() (nano::object_stream & obs) const obs.write ("final", is_final_timestamp (timestamp_m)); obs.write ("timestamp", timestamp_m); obs.write_range ("hashes", hashes); -} \ No newline at end of file +} diff --git a/nano/secure/vote.hpp b/nano/secure/vote.hpp index 0737acf00..e04f24789 100644 --- a/nano/secure/vote.hpp +++ b/nano/secure/vote.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/nano/store/component.hpp b/nano/store/component.hpp index f36f837ef..328ad88e6 100644 --- a/nano/store/component.hpp +++ b/nano/store/component.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include From d54e3d99156b6cf56f118f9b4886b4723d4e1a32 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 23:41:52 +0000 Subject: [PATCH 11/25] Rename nano/common.hpp to nano/endpoint.hpp and extract endpoint_templ.hpp template implementation file. --- nano/core_test/block.cpp | 2 +- nano/core_test/block_store.cpp | 2 +- nano/core_test/fakes/work_peer.hpp | 2 +- nano/core_test/message.cpp | 2 +- nano/core_test/network_filter.cpp | 4 +- nano/core_test/voting.cpp | 2 +- nano/node/CMakeLists.txt | 5 +- nano/node/bootstrap/bootstrap.cpp | 2 +- nano/node/bootstrap/bootstrap.hpp | 2 +- nano/node/bootstrap/bootstrap_bulk_push.hpp | 2 +- nano/node/bootstrap/bootstrap_connections.cpp | 2 +- nano/node/bootstrap/bootstrap_connections.hpp | 2 +- nano/node/bootstrap/bootstrap_lazy.cpp | 2 +- nano/node/cli.cpp | 2 +- nano/node/distributed_work.hpp | 2 +- nano/node/{common.cpp => endpoint.cpp} | 8 ++- nano/node/{common.hpp => endpoint.hpp} | 50 ++++-------------- nano/node/endpoint_templ.hpp | 52 +++++++++++++++++++ nano/node/json_handler.cpp | 2 +- nano/node/messages.cpp | 2 +- nano/node/messages.hpp | 3 +- nano/node/network.hpp | 2 +- nano/node/node.cpp | 2 +- nano/node/peer_exclusion.hpp | 3 +- nano/node/peer_history.hpp | 4 +- nano/node/request_aggregator.cpp | 2 +- nano/node/telemetry.hpp | 2 +- nano/node/transport/channel.cpp | 2 +- nano/node/transport/channel.hpp | 4 +- nano/node/transport/message_deserializer.hpp | 2 +- nano/node/transport/tcp_channels.hpp | 4 +- nano/node/transport/tcp_listener.hpp | 4 +- nano/node/transport/tcp_server.hpp | 2 +- nano/node/transport/transport.cpp | 4 +- nano/node/transport/transport.hpp | 4 +- nano/node/websocket.hpp | 2 +- nano/rpc_test/entry.cpp | 2 +- nano/test_common/network.hpp | 2 +- nano/test_common/system.cpp | 2 +- nano/test_common/telemetry.cpp | 4 +- 40 files changed, 117 insertions(+), 88 deletions(-) rename nano/node/{common.cpp => endpoint.cpp} (94%) rename nano/node/{common.hpp => endpoint.hpp} (61%) create mode 100644 nano/node/endpoint_templ.hpp diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index f5dd614b3..3c497ebed 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/nano/core_test/block_store.cpp b/nano/core_test/block_store.cpp index dfbd1a360..1b085c394 100644 --- a/nano/core_test/block_store.cpp +++ b/nano/core_test/block_store.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/core_test/fakes/work_peer.hpp b/nano/core_test/fakes/work_peer.hpp index bff40fee2..52eb8ff88 100644 --- a/nano/core_test/fakes/work_peer.hpp +++ b/nano/core_test/fakes/work_peer.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/core_test/message.cpp b/nano/core_test/message.cpp index 60d233821..e18c09c6c 100644 --- a/nano/core_test/message.cpp +++ b/nano/core_test/message.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/core_test/network_filter.cpp b/nano/core_test/network_filter.cpp index 788d7c271..12e816e2e 100644 --- a/nano/core_test/network_filter.cpp +++ b/nano/core_test/network_filter.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include @@ -163,4 +163,4 @@ TEST (network_filter, expire) ASSERT_FALSE (filter.check (2)); // Entry with epoch 1 should be expired ASSERT_FALSE (filter.apply (2)); // Entry with epoch 1 should be replaced -} \ No newline at end of file +} diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index 3389a8a96..241cd347b 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index fc87e502f..c27e6c0bb 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -59,8 +59,6 @@ add_library( bootstrap_ascending/service.cpp cli.hpp cli.cpp - common.hpp - common.cpp confirming_set.hpp confirming_set.cpp confirmation_solicitor.hpp @@ -76,6 +74,9 @@ add_library( election_behavior.hpp election_insertion_result.hpp election_status.hpp + endpoint.cpp + endpoint.hpp + endpoint_templ.hpp epoch_upgrader.hpp epoch_upgrader.cpp fair_queue.hpp diff --git a/nano/node/bootstrap/bootstrap.cpp b/nano/node/bootstrap/bootstrap.cpp index 8779400ee..fe021ffd2 100644 --- a/nano/node/bootstrap/bootstrap.cpp +++ b/nano/node/bootstrap/bootstrap.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index f06f83196..b02cd56fd 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/nano/node/bootstrap/bootstrap_bulk_push.hpp b/nano/node/bootstrap/bootstrap_bulk_push.hpp index d40e0fe5a..19f8db764 100644 --- a/nano/node/bootstrap/bootstrap_bulk_push.hpp +++ b/nano/node/bootstrap/bootstrap_bulk_push.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include diff --git a/nano/node/bootstrap/bootstrap_connections.cpp b/nano/node/bootstrap/bootstrap_connections.cpp index b3f1334b8..62e7bc07b 100644 --- a/nano/node/bootstrap/bootstrap_connections.cpp +++ b/nano/node/bootstrap/bootstrap_connections.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/node/bootstrap/bootstrap_connections.hpp b/nano/node/bootstrap/bootstrap_connections.hpp index d246c23bb..ee86e32a5 100644 --- a/nano/node/bootstrap/bootstrap_connections.hpp +++ b/nano/node/bootstrap/bootstrap_connections.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/nano/node/bootstrap/bootstrap_lazy.cpp b/nano/node/bootstrap/bootstrap_lazy.cpp index 2f8807439..79bbce58a 100644 --- a/nano/node/bootstrap/bootstrap_lazy.cpp +++ b/nano/node/bootstrap/bootstrap_lazy.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/node/cli.cpp b/nano/node/cli.cpp index 5ebe67bbf..fd65b4e3a 100644 --- a/nano/node/cli.cpp +++ b/nano/node/cli.cpp @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/nano/node/distributed_work.hpp b/nano/node/distributed_work.hpp index 17edecc60..4d83e0160 100644 --- a/nano/node/distributed_work.hpp +++ b/nano/node/distributed_work.hpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include diff --git a/nano/node/common.cpp b/nano/node/endpoint.cpp similarity index 94% rename from nano/node/common.cpp rename to nano/node/endpoint.cpp index 5edab1f7f..ccfd7361f 100644 --- a/nano/node/common.cpp +++ b/nano/node/endpoint.cpp @@ -2,8 +2,8 @@ #include #include #include -#include #include +#include #include #include @@ -27,6 +27,12 @@ uint64_t nano::ip_address_hash_raw (boost::asio::ip::address const & ip_a, uint1 return result; } +uint64_t nano::endpoint_hash_raw (nano::endpoint const & endpoint_a) +{ + uint64_t result (nano::ip_address_hash_raw (endpoint_a.address (), endpoint_a.port ())); + return result; +} + bool nano::parse_port (std::string const & string_a, uint16_t & port_a) { bool result = false; diff --git a/nano/node/common.hpp b/nano/node/endpoint.hpp similarity index 61% rename from nano/node/common.hpp rename to nano/node/endpoint.hpp index 92613306e..c1ed629ef 100644 --- a/nano/node/common.hpp +++ b/nano/node/endpoint.hpp @@ -1,9 +1,10 @@ #pragma once -#include #include +#include #include +#include namespace boost::asio::ip { @@ -19,16 +20,11 @@ bool parse_endpoint (std::string const &, nano::endpoint &); std::optional parse_endpoint (std::string const &); bool parse_tcp_endpoint (std::string const &, nano::tcp_endpoint &); uint64_t ip_address_hash_raw (boost::asio::ip::address const & ip_a, uint16_t port = 0); +uint64_t endpoint_hash_raw (nano::endpoint const & endpoint_a); } namespace { -uint64_t endpoint_hash_raw (nano::endpoint const & endpoint_a) -{ - uint64_t result (nano::ip_address_hash_raw (endpoint_a.address (), endpoint_a.port ())); - return result; -} - template struct endpoint_hash { @@ -39,7 +35,7 @@ struct endpoint_hash<8> { std::size_t operator() (nano::endpoint const & endpoint_a) const { - return endpoint_hash_raw (endpoint_a); + return nano::endpoint_hash_raw (endpoint_a); } }; @@ -48,7 +44,7 @@ struct endpoint_hash<4> { std::size_t operator() (nano::endpoint const & endpoint_a) const { - uint64_t big (endpoint_hash_raw (endpoint_a)); + uint64_t big = nano::endpoint_hash_raw (endpoint_a); uint32_t result (static_cast (big) ^ static_cast (big >> 32)); return result; } @@ -83,47 +79,19 @@ struct ip_address_hash<4> namespace std { template <> -struct hash<::nano::endpoint> -{ - std::size_t operator() (::nano::endpoint const & endpoint_a) const - { - endpoint_hash ehash; - return ehash (endpoint_a); - } -}; +struct hash<::nano::endpoint>; #ifndef BOOST_ASIO_HAS_STD_HASH template <> -struct hash -{ - std::size_t operator() (boost::asio::ip::address const & ip_a) const - { - ip_address_hash ihash; - return ihash (ip_a); - } -}; +struct hash; #endif } namespace boost { template <> -struct hash<::nano::endpoint> -{ - std::size_t operator() (::nano::endpoint const & endpoint_a) const - { - std::hash<::nano::endpoint> hash; - return hash (endpoint_a); - } -}; +struct hash<::nano::endpoint>; template <> -struct hash -{ - std::size_t operator() (boost::asio::ip::address const & ip_a) const - { - std::hash hash; - return hash (ip_a); - } -}; +struct hash; } diff --git a/nano/node/endpoint_templ.hpp b/nano/node/endpoint_templ.hpp new file mode 100644 index 000000000..22d17e963 --- /dev/null +++ b/nano/node/endpoint_templ.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include +#include + +namespace std +{ +template <> +struct hash<::nano::endpoint> +{ + std::size_t operator() (::nano::endpoint const & endpoint_a) const + { + endpoint_hash ehash; + return ehash (endpoint_a); + } +}; + +#ifndef BOOST_ASIO_HAS_STD_HASH +template <> +struct hash +{ + std::size_t operator() (boost::asio::ip::address const & ip_a) const + { + ip_address_hash ihash; + return ihash (ip_a); + } +}; +#endif +} + +namespace boost +{ +template <> +struct hash<::nano::endpoint> +{ + std::size_t operator() (::nano::endpoint const & endpoint_a) const + { + std::hash<::nano::endpoint> hash; + return hash (endpoint_a); + } +}; + +template <> +struct hash +{ + std::size_t operator() (boost::asio::ip::address const & ip_a) const + { + std::hash hash; + return hash (ip_a); + } +}; +} diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 2b90c682e..d62c3d09b 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -8,9 +8,9 @@ #include #include #include -#include #include #include +#include #include #include #include diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index 022c54d8e..c10f64199 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -8,8 +8,8 @@ #include #include #include -#include #include +#include #include #include diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 9b315f538..dd47fa8b3 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include @@ -11,7 +12,7 @@ #include #include #include -#include +#include #include #include diff --git a/nano/node/network.hpp b/nano/node/network.hpp index 0ab498ed2..d1130271d 100644 --- a/nano/node/network.hpp +++ b/nano/node/network.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include diff --git a/nano/node/node.cpp b/nano/node/node.cpp index b8de6fff0..12e6069fc 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -11,10 +11,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include diff --git a/nano/node/peer_exclusion.hpp b/nano/node/peer_exclusion.hpp index 3100bfe09..e209d5e63 100644 --- a/nano/node/peer_exclusion.hpp +++ b/nano/node/peer_exclusion.hpp @@ -1,6 +1,7 @@ #pragma once -#include +#include +#include #include #include diff --git a/nano/node/peer_history.hpp b/nano/node/peer_history.hpp index 15d13ffdd..6200446b5 100644 --- a/nano/node/peer_history.hpp +++ b/nano/node/peer_history.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -54,4 +54,4 @@ private: nano::condition_variable condition; std::thread thread; }; -} \ No newline at end of file +} diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index 8465b7d2b..75faab069 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -1,7 +1,7 @@ #include #include -#include #include +#include #include #include #include diff --git a/nano/node/telemetry.hpp b/nano/node/telemetry.hpp index cb9c337a9..8e0fe8c31 100644 --- a/nano/node/telemetry.hpp +++ b/nano/node/telemetry.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include diff --git a/nano/node/transport/channel.cpp b/nano/node/transport/channel.cpp index 6a4c6663e..8b7055c46 100644 --- a/nano/node/transport/channel.cpp +++ b/nano/node/transport/channel.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include diff --git a/nano/node/transport/channel.hpp b/nano/node/transport/channel.hpp index 212dc1c37..8f860f58c 100644 --- a/nano/node/transport/channel.hpp +++ b/nano/node/transport/channel.hpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include #include #include @@ -140,4 +140,4 @@ private: public: // Logging virtual void operator() (nano::object_stream &) const; }; -} \ No newline at end of file +} diff --git a/nano/node/transport/message_deserializer.hpp b/nano/node/transport/message_deserializer.hpp index 4c4d62c22..ca8d923f3 100644 --- a/nano/node/transport/message_deserializer.hpp +++ b/nano/node/transport/message_deserializer.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include diff --git a/nano/node/transport/tcp_channels.hpp b/nano/node/transport/tcp_channels.hpp index 1b6f1e363..a4d4b2bc8 100644 --- a/nano/node/transport/tcp_channels.hpp +++ b/nano/node/transport/tcp_channels.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include #include @@ -170,4 +170,4 @@ private: mutable nano::random_generator rng; }; -} \ No newline at end of file +} diff --git a/nano/node/transport/tcp_listener.hpp b/nano/node/transport/tcp_listener.hpp index 55c63da64..c6c5730ce 100644 --- a/nano/node/transport/tcp_listener.hpp +++ b/nano/node/transport/tcp_listener.hpp @@ -1,7 +1,7 @@ #pragma once #include -#include +#include #include #include @@ -176,4 +176,4 @@ private: static std::string_view to_string (connection_type); static nano::transport::socket_endpoint to_socket_endpoint (connection_type); }; -} \ No newline at end of file +} diff --git a/nano/node/transport/tcp_server.hpp b/nano/node/transport/tcp_server.hpp index 96085ae8b..c4971464d 100644 --- a/nano/node/transport/tcp_server.hpp +++ b/nano/node/transport/tcp_server.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include #include #include diff --git a/nano/node/transport/transport.cpp b/nano/node/transport/transport.cpp index 4a90626f9..21f5fea04 100644 --- a/nano/node/transport/transport.cpp +++ b/nano/node/transport/transport.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -164,4 +164,4 @@ bool nano::transport::reserved_address (nano::endpoint const & endpoint_a, bool } } return result; -} \ No newline at end of file +} diff --git a/nano/node/transport/transport.hpp b/nano/node/transport/transport.hpp index 3065bbd04..5703a8c73 100644 --- a/nano/node/transport/transport.hpp +++ b/nano/node/transport/transport.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include @@ -24,4 +24,4 @@ bool is_same_subnetwork (boost::asio::ip::address const &, boost::asio::ip::addr // Unassigned, reserved, self bool reserved_address (nano::endpoint const &, bool allow_local_peers = false); -} \ No newline at end of file +} diff --git a/nano/node/websocket.hpp b/nano/node/websocket.hpp index 2a3895606..1a5eb0dbb 100644 --- a/nano/node/websocket.hpp +++ b/nano/node/websocket.hpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include #include #include diff --git a/nano/rpc_test/entry.cpp b/nano/rpc_test/entry.cpp index 806f07645..e16a3f4e5 100644 --- a/nano/rpc_test/entry.cpp +++ b/nano/rpc_test/entry.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include diff --git a/nano/test_common/network.hpp b/nano/test_common/network.hpp index 3bfcd22c3..d201fee17 100644 --- a/nano/test_common/network.hpp +++ b/nano/test_common/network.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include #include namespace nano diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 758a5c72e..b336139c9 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -2,7 +2,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/test_common/telemetry.cpp b/nano/test_common/telemetry.cpp index db2465e07..a2aa36a3c 100644 --- a/nano/test_common/telemetry.cpp +++ b/nano/test_common/telemetry.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -61,4 +61,4 @@ bool nano::test::compare_telemetry (const nano::telemetry_data & data, const nan bool result = false; compare_telemetry_impl (data, node, result); return result; -} \ No newline at end of file +} From b4eb765a90961297effbd5392dd44a6e74b81d65 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Sun, 27 Oct 2024 23:51:52 +0000 Subject: [PATCH 12/25] Forward declare work_version and extract to its own file. --- nano/core_test/block.cpp | 1 + nano/core_test/difficulty.cpp | 1 + nano/core_test/distributed_work.cpp | 1 + nano/core_test/fakes/work_peer.hpp | 1 + nano/core_test/node.cpp | 3 ++- nano/core_test/system.cpp | 1 + nano/core_test/wallet.cpp | 1 + nano/core_test/websocket.cpp | 1 + nano/core_test/work_pool.cpp | 1 + nano/lib/CMakeLists.txt | 3 ++- nano/lib/blocks.cpp | 1 + nano/lib/blocks.hpp | 5 ++++- nano/lib/config.cpp | 1 + nano/lib/config.hpp | 6 +----- nano/lib/work.cpp | 1 + nano/lib/work_version.hpp | 10 ++++++++++ nano/nano_node/entry.cpp | 1 + nano/node/epoch_upgrader.cpp | 1 + nano/node/json_handler.cpp | 1 + nano/node/node.cpp | 1 + nano/node/wallet.cpp | 1 + nano/qt_test/qt.cpp | 1 + nano/rpc_test/rpc.cpp | 1 + nano/slow_test/node.cpp | 1 + nano/test_common/system.cpp | 1 + 25 files changed, 39 insertions(+), 8 deletions(-) create mode 100644 nano/lib/work_version.hpp diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index 3c497ebed..79037a9cd 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include diff --git a/nano/core_test/difficulty.cpp b/nano/core_test/difficulty.cpp index 98b4d4fc6..77fbc418d 100644 --- a/nano/core_test/difficulty.cpp +++ b/nano/core_test/difficulty.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/nano/core_test/distributed_work.cpp b/nano/core_test/distributed_work.cpp index 6eb843746..f5e040aa9 100644 --- a/nano/core_test/distributed_work.cpp +++ b/nano/core_test/distributed_work.cpp @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/nano/core_test/fakes/work_peer.hpp b/nano/core_test/fakes/work_peer.hpp index 52eb8ff88..0e9e80f90 100644 --- a/nano/core_test/fakes/work_peer.hpp +++ b/nano/core_test/fakes/work_peer.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 377d61ed5..e8b836847 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -3814,4 +3815,4 @@ TEST (node, container_info) // This should just execute, sanitizers will catch any problems ASSERT_NO_THROW (node1.container_info ()); ASSERT_NO_THROW (node2.container_info ()); -} \ No newline at end of file +} diff --git a/nano/core_test/system.cpp b/nano/core_test/system.cpp index 7f9f1088a..0ac3c28a3 100644 --- a/nano/core_test/system.cpp +++ b/nano/core_test/system.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/core_test/wallet.cpp b/nano/core_test/wallet.cpp index e9e170f6d..79068966e 100644 --- a/nano/core_test/wallet.cpp +++ b/nano/core_test/wallet.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index 65a18dd21..fd527f8fa 100644 --- a/nano/core_test/websocket.cpp +++ b/nano/core_test/websocket.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/work_pool.cpp b/nano/core_test/work_pool.cpp index 63eae4cf7..cb4eed460 100644 --- a/nano/core_test/work_pool.cpp +++ b/nano/core_test/work_pool.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index 36647fd88..2e60cf4dd 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -115,7 +115,8 @@ add_library( walletconfig.hpp walletconfig.cpp work.hpp - work.cpp) + work.cpp + work_version.hpp) include_directories(${CMAKE_SOURCE_DIR}/submodules) include_directories( diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index 2c7510cd8..ab667ee8f 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 41e08f89e..913c47913 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -18,7 +17,11 @@ namespace nano class block_visitor; class mutable_block_visitor; class object_stream; +enum class work_version; +} +namespace nano +{ class block { public: diff --git a/nano/lib/config.cpp b/nano/lib/config.cpp index e249b3106..41b73e510 100644 --- a/nano/lib/config.cpp +++ b/nano/lib/config.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/nano/lib/config.hpp b/nano/lib/config.hpp index c67095967..239f5ad8c 100644 --- a/nano/lib/config.hpp +++ b/nano/lib/config.hpp @@ -105,15 +105,11 @@ enum class networks : uint16_t std::string_view to_string (nano::networks); -enum class work_version -{ - unspecified, - work_1 -}; enum class block_type : uint8_t; class root; class block; class block_details; +enum class work_version; class work_thresholds { diff --git a/nano/lib/work.cpp b/nano/lib/work.cpp index 7d9165c19..3097bc412 100644 --- a/nano/lib/work.cpp +++ b/nano/lib/work.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include diff --git a/nano/lib/work_version.hpp b/nano/lib/work_version.hpp new file mode 100644 index 000000000..fb24b82d3 --- /dev/null +++ b/nano/lib/work_version.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace nano +{ +enum class work_version +{ + unspecified, + work_1 +}; +} diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 1a4f6da6a..96d9349f0 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/epoch_upgrader.cpp b/nano/node/epoch_upgrader.cpp index 69d2a5065..1a44e9f24 100644 --- a/nano/node/epoch_upgrader.cpp +++ b/nano/node/epoch_upgrader.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index d62c3d09b..08f911108 100644 --- a/nano/node/json_handler.cpp +++ b/nano/node/json_handler.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 12e6069fc..c115ebaa3 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 18dd7df7a..ba65fe0dc 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/qt_test/qt.cpp b/nano/qt_test/qt.cpp index b4070ca80..f79f35e7c 100644 --- a/nano/qt_test/qt.cpp +++ b/nano/qt_test/qt.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index bf3c5f60c..fe698dce8 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index b9c3731f6..d6e181a8b 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index b336139c9..4071ea462 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include From 7dce2d73f42df4f794b5bf70f443fd02e50fbbe4 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 28 Oct 2024 08:02:36 +0000 Subject: [PATCH 13/25] Forward declare block_uniquer --- nano/lib/blocks.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 913c47913..0c780c9a4 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include #include #include @@ -14,10 +13,15 @@ typedef struct blake2b_state__ blake2b_state; namespace nano { +class block; class block_visitor; class mutable_block_visitor; class object_stream; +template +class uniquer; enum class work_version; + +using block_uniquer = uniquer; } namespace nano From 7e6c41a95def28681654db18acdd1cf2223371ea Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 28 Oct 2024 20:49:02 +0000 Subject: [PATCH 14/25] Forward declaring block_uniquer. --- nano/node/messages.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index dd47fa8b3..d21a22868 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -24,7 +23,12 @@ namespace nano { +class block; class jsonconfig; +template +class uniquer; + +using block_uniquer = uniquer; } namespace nano From dc69e54751214f3af45d5bce903bb6a33036a2ac Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 28 Oct 2024 20:51:22 +0000 Subject: [PATCH 15/25] Removing unused channel header. --- nano/test_common/testutil.hpp | 1 - 1 file changed, 1 deletion(-) diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 716be359c..38096d36f 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include From d09940f645541ad14173affb3c6773e10b250548 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 28 Oct 2024 21:38:03 +0000 Subject: [PATCH 16/25] Remove inclusion of vote in common.hpp header. --- nano/core_test/active_elections.cpp | 1 + nano/core_test/block.cpp | 1 + nano/core_test/conflicts.cpp | 1 + nano/core_test/ledger.cpp | 1 + nano/core_test/memory_pool.cpp | 1 + nano/core_test/message.cpp | 1 + nano/core_test/message_deserializer.cpp | 1 + nano/core_test/node.cpp | 1 + nano/core_test/rep_crawler.cpp | 3 ++- nano/core_test/vote_processor.cpp | 1 + nano/core_test/voting.cpp | 1 + nano/lib/blocks.cpp | 1 + nano/nano_node/entry.cpp | 1 + nano/node/bandwidth_limiter.hpp | 7 ++++++- nano/node/bootstrap/bootstrap.hpp | 1 + nano/node/bootstrap/bootstrap_attempt.hpp | 2 ++ nano/node/bootstrap_ascending/account_sets.hpp | 6 +++++- nano/node/confirming_set.hpp | 8 ++++++++ nano/node/election.cpp | 1 + nano/node/endpoint.cpp | 1 + nano/node/ipc/ipc_config.cpp | 6 ++++++ nano/node/ipc/ipc_config.hpp | 11 ++++++----- nano/node/local_block_broadcaster.hpp | 1 + nano/node/message_processor.cpp | 3 ++- nano/node/messages.cpp | 1 + nano/node/messages.hpp | 2 ++ nano/node/node.cpp | 1 + nano/node/repcrawler.cpp | 1 + nano/node/scheduler/bucket.hpp | 2 ++ nano/node/vote_cache.cpp | 1 + nano/node/vote_generator.cpp | 3 ++- nano/node/vote_processor.cpp | 3 ++- nano/node/vote_router.cpp | 3 ++- nano/node/websocket.cpp | 1 + nano/rpc_test/rpc.cpp | 1 + nano/secure/common.hpp | 2 +- nano/slow_test/node.cpp | 1 + nano/slow_test/vote_processor.cpp | 1 + nano/store/component.hpp | 12 +++++++++--- nano/store/db_val.hpp | 1 + nano/test_common/testutil.cpp | 1 + 41 files changed, 83 insertions(+), 16 deletions(-) diff --git a/nano/core_test/active_elections.cpp b/nano/core_test/active_elections.cpp index f592ea133..8840c9dc9 100644 --- a/nano/core_test/active_elections.cpp +++ b/nano/core_test/active_elections.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index 79037a9cd..4da6e787f 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/core_test/conflicts.cpp b/nano/core_test/conflicts.cpp index 43c193815..f9469f3bf 100644 --- a/nano/core_test/conflicts.cpp +++ b/nano/core_test/conflicts.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 0dd6e786d..d43d41269 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/memory_pool.cpp b/nano/core_test/memory_pool.cpp index 6d5dd4ae9..087f84894 100644 --- a/nano/core_test/memory_pool.cpp +++ b/nano/core_test/memory_pool.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include diff --git a/nano/core_test/message.cpp b/nano/core_test/message.cpp index e18c09c6c..12ff989af 100644 --- a/nano/core_test/message.cpp +++ b/nano/core_test/message.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include diff --git a/nano/core_test/message_deserializer.cpp b/nano/core_test/message_deserializer.cpp index 44e9fa06d..7d65d6528 100644 --- a/nano/core_test/message_deserializer.cpp +++ b/nano/core_test/message_deserializer.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index e8b836847..87f91c04b 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/rep_crawler.cpp b/nano/core_test/rep_crawler.cpp index 1d52769df..e9d0ba8d4 100644 --- a/nano/core_test/rep_crawler.cpp +++ b/nano/core_test/rep_crawler.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -327,4 +328,4 @@ TEST (rep_crawler, ignore_rebroadcasted) }; ASSERT_NEVER (1s, tick () || node1.rep_crawler.representative_count () > 0); -} \ No newline at end of file +} diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index 3f656794e..8855b17f1 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index 241cd347b..55d63259f 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/nano/lib/blocks.cpp b/nano/lib/blocks.cpp index ab667ee8f..d61233e4a 100644 --- a/nano/lib/blocks.cpp +++ b/nano/lib/blocks.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/nano_node/entry.cpp b/nano/nano_node/entry.cpp index 96d9349f0..5477769e7 100644 --- a/nano/nano_node/entry.cpp +++ b/nano/nano_node/entry.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include diff --git a/nano/node/bandwidth_limiter.hpp b/nano/node/bandwidth_limiter.hpp index 1bd9e5833..4bd19ee7c 100644 --- a/nano/node/bandwidth_limiter.hpp +++ b/nano/node/bandwidth_limiter.hpp @@ -4,6 +4,11 @@ #include #include +namespace nano +{ +class node_config; +} + namespace nano { class bandwidth_limiter_config final @@ -50,4 +55,4 @@ private: nano::rate_limiter limiter_generic; nano::rate_limiter limiter_bootstrap; }; -} \ No newline at end of file +} diff --git a/nano/node/bootstrap/bootstrap.hpp b/nano/node/bootstrap/bootstrap.hpp index b02cd56fd..3d6ec25f1 100644 --- a/nano/node/bootstrap/bootstrap.hpp +++ b/nano/node/bootstrap/bootstrap.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/nano/node/bootstrap/bootstrap_attempt.hpp b/nano/node/bootstrap/bootstrap_attempt.hpp index ea64fe9fd..ce6c686ef 100644 --- a/nano/node/bootstrap/bootstrap_attempt.hpp +++ b/nano/node/bootstrap/bootstrap_attempt.hpp @@ -2,6 +2,8 @@ #include +#include + #include #include diff --git a/nano/node/bootstrap_ascending/account_sets.hpp b/nano/node/bootstrap_ascending/account_sets.hpp index d83d3a889..5a77e2eca 100644 --- a/nano/node/bootstrap_ascending/account_sets.hpp +++ b/nano/node/bootstrap_ascending/account_sets.hpp @@ -18,8 +18,12 @@ namespace mi = boost::multi_index; namespace nano { +class account_sets_config; class stats; +} +namespace nano +{ namespace bootstrap_ascending { /** This class tracks accounts various account sets which are shared among the multiple bootstrap threads */ @@ -161,4 +165,4 @@ namespace bootstrap_ascending info_t info () const; }; } -} \ No newline at end of file +} diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index 644b241c9..39fdec50e 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -20,6 +20,14 @@ namespace mi = boost::multi_index; +namespace nano +{ +class election; +class ledger; +class logger; +class stats; +} + namespace nano { class confirming_set_config final diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 06ea41350..7cd964aae 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -9,6 +9,7 @@ #include #include #include +#include using namespace std::chrono; diff --git a/nano/node/endpoint.cpp b/nano/node/endpoint.cpp index ccfd7361f..891f88728 100644 --- a/nano/node/endpoint.cpp +++ b/nano/node/endpoint.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include diff --git a/nano/node/ipc/ipc_config.cpp b/nano/node/ipc/ipc_config.cpp index 04d4901b3..323063976 100644 --- a/nano/node/ipc/ipc_config.cpp +++ b/nano/node/ipc/ipc_config.cpp @@ -2,6 +2,12 @@ #include #include +nano::ipc::ipc_config_tcp_socket::ipc_config_tcp_socket (nano::network_constants & network_constants) : + network_constants{ network_constants }, + port{ network_constants.default_ipc_port } +{ +} + nano::error nano::ipc::ipc_config::serialize_toml (nano::tomlconfig & toml) const { nano::tomlconfig tcp_l; diff --git a/nano/node/ipc/ipc_config.hpp b/nano/node/ipc/ipc_config.hpp index 4722177da..4be3fb0df 100644 --- a/nano/node/ipc/ipc_config.hpp +++ b/nano/node/ipc/ipc_config.hpp @@ -7,7 +7,12 @@ namespace nano { +class network_constants; class tomlconfig; +} + +namespace nano +{ namespace ipc { /** Base class for transport configurations */ @@ -46,11 +51,7 @@ namespace ipc class ipc_config_tcp_socket : public ipc_config_transport { public: - ipc_config_tcp_socket (nano::network_constants & network_constants) : - network_constants{ network_constants }, - port{ network_constants.default_ipc_port } - { - } + ipc_config_tcp_socket (nano::network_constants & network_constants); nano::network_constants & network_constants; /** Listening port */ uint16_t port; diff --git a/nano/node/local_block_broadcaster.hpp b/nano/node/local_block_broadcaster.hpp index d2bed33ce..a88ed25f9 100644 --- a/nano/node/local_block_broadcaster.hpp +++ b/nano/node/local_block_broadcaster.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include diff --git a/nano/node/message_processor.cpp b/nano/node/message_processor.cpp index 469c55bd1..a172f48df 100644 --- a/nano/node/message_processor.cpp +++ b/nano/node/message_processor.cpp @@ -3,6 +3,7 @@ #include #include #include +#include nano::message_processor::message_processor (message_processor_config const & config_a, nano::node & node_a) : config{ config_a }, @@ -317,4 +318,4 @@ nano::error nano::message_processor_config::deserialize (nano::tomlconfig & toml toml.get ("max_queue", max_queue); return toml.get_error (); -} \ No newline at end of file +} diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index c10f64199..d665ee3f8 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index d21a22868..85fa9d663 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -27,8 +27,10 @@ class block; class jsonconfig; template class uniquer; +class vote; using block_uniquer = uniquer; +using vote_uniquer = uniquer; } namespace nano diff --git a/nano/node/node.cpp b/nano/node/node.cpp index c115ebaa3..0c55b6e11 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include #include diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index b3dc58c40..b54eae4a5 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include diff --git a/nano/node/scheduler/bucket.hpp b/nano/node/scheduler/bucket.hpp index 668bbec6d..4994fa8b7 100644 --- a/nano/node/scheduler/bucket.hpp +++ b/nano/node/scheduler/bucket.hpp @@ -1,5 +1,7 @@ #pragma once +#include +#include #include #include diff --git a/nano/node/vote_cache.cpp b/nano/node/vote_cache.cpp index 36f9c4adf..dd190bc45 100644 --- a/nano/node/vote_cache.cpp +++ b/nano/node/vote_cache.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include diff --git a/nano/node/vote_generator.cpp b/nano/node/vote_generator.cpp index e29c88cc9..faf3c273b 100644 --- a/nano/node/vote_generator.cpp +++ b/nano/node/vote_generator.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -326,4 +327,4 @@ nano::container_info nano::vote_generator::container_info () const info.put ("requests", requests.size ()); info.add ("queue", vote_generation_queue.container_info ()); return info; -} \ No newline at end of file +} diff --git a/nano/node/vote_processor.cpp b/nano/node/vote_processor.cpp index 4d0c8ef54..283e78ac9 100644 --- a/nano/node/vote_processor.cpp +++ b/nano/node/vote_processor.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include @@ -376,4 +377,4 @@ nano::error nano::vote_processor_config::deserialize (nano::tomlconfig & toml) toml.get ("batch_size", batch_size); return toml.get_error (); -} \ No newline at end of file +} diff --git a/nano/node/vote_router.cpp b/nano/node/vote_router.cpp index acf3d069c..0f80e4995 100644 --- a/nano/node/vote_router.cpp +++ b/nano/node/vote_router.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -192,4 +193,4 @@ nano::container_info nano::vote_router::container_info () const nano::container_info info; info.put ("elections", elections); return info; -} \ No newline at end of file +} diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index 653c60f76..32a68d2bb 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index fe698dce8..de71a49c8 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index b3711d88e..6606ce5e5 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -8,10 +8,10 @@ #include #include #include +#include #include #include #include -#include #include #include diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index d6e181a8b..982c5b873 100644 --- a/nano/slow_test/node.cpp +++ b/nano/slow_test/node.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/slow_test/vote_processor.cpp b/nano/slow_test/vote_processor.cpp index 938aa2566..b3fcffa9f 100644 --- a/nano/slow_test/vote_processor.cpp +++ b/nano/slow_test/vote_processor.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include diff --git a/nano/store/component.hpp b/nano/store/component.hpp index 328ad88e6..a08985039 100644 --- a/nano/store/component.hpp +++ b/nano/store/component.hpp @@ -10,6 +10,7 @@ #include #include +#include #include @@ -25,10 +26,15 @@ namespace store class peer; class pending; class pruned; - class version; + class read_transaction; class rep_weight; + class transaction; + class version; + class write_transaction; } class ledger_cache; +class ledger_constants; +enum class tables; namespace store { @@ -89,8 +95,8 @@ namespace store virtual void rebuild_db (write_transaction const & transaction_a) = 0; /** Not applicable to all sub-classes */ - virtual void serialize_mdb_tracker (boost::property_tree::ptree &, std::chrono::milliseconds, std::chrono::milliseconds){}; - virtual void serialize_memory_stats (boost::property_tree::ptree &) = 0; + virtual void serialize_mdb_tracker (::boost::property_tree::ptree &, std::chrono::milliseconds, std::chrono::milliseconds){}; + virtual void serialize_memory_stats (::boost::property_tree::ptree &) = 0; virtual bool init_error () const = 0; diff --git a/nano/store/db_val.hpp b/nano/store/db_val.hpp index 7cc415a5f..12b81a143 100644 --- a/nano/store/db_val.hpp +++ b/nano/store/db_val.hpp @@ -16,6 +16,7 @@ class account_info_v22; class block; class pending_info; class pending_key; +class vote; } namespace nano::store diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index f2c3c7712..8218fd22c 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include From 342801bcddc46b1bf79cc6f91f6a26adfde33359 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 28 Oct 2024 21:56:44 +0000 Subject: [PATCH 17/25] Remove unused inclusion of utility.hpp --- nano/lib/network_filter.hpp | 1 + nano/lib/optional_ptr.hpp | 2 -- nano/lib/rate_limiting.hpp | 4 +++- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/nano/lib/network_filter.hpp b/nano/lib/network_filter.hpp index c9cca1030..84cb65f41 100644 --- a/nano/lib/network_filter.hpp +++ b/nano/lib/network_filter.hpp @@ -1,6 +1,7 @@ #pragma once +#include #include #include diff --git a/nano/lib/optional_ptr.hpp b/nano/lib/optional_ptr.hpp index 8c5fdc2fe..9939ebf30 100644 --- a/nano/lib/optional_ptr.hpp +++ b/nano/lib/optional_ptr.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include #include diff --git a/nano/lib/rate_limiting.hpp b/nano/lib/rate_limiting.hpp index f67246787..65f7bc21b 100644 --- a/nano/lib/rate_limiting.hpp +++ b/nano/lib/rate_limiting.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include #include @@ -73,4 +75,4 @@ private: nano::rate::token_bucket bucket; mutable nano::mutex mutex; }; -} \ No newline at end of file +} From fed751c18014bee358de81d3430bde3224b14b2e Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 28 Oct 2024 22:05:51 +0000 Subject: [PATCH 18/25] Forward declaring stats. --- nano/node/confirming_set.cpp | 1 + nano/node/rep_tiers.cpp | 3 ++- nano/node/transport/tcp_listener.hpp | 5 +++++ nano/node/vote_cache.hpp | 1 + nano/secure/common.cpp | 1 + nano/secure/common.hpp | 6 +++++- 6 files changed, 15 insertions(+), 2 deletions(-) diff --git a/nano/node/confirming_set.cpp b/nano/node/confirming_set.cpp index 2921881b5..3de7e7dc8 100644 --- a/nano/node/confirming_set.cpp +++ b/nano/node/confirming_set.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/node/rep_tiers.cpp b/nano/node/rep_tiers.cpp index 6bc532787..a0eb4fe43 100644 --- a/nano/node/rep_tiers.cpp +++ b/nano/node/rep_tiers.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -149,4 +150,4 @@ nano::container_info nano::rep_tiers::container_info () const nano::stat::detail nano::to_stat_detail (nano::rep_tier tier) { return nano::enum_util::cast (tier); -} \ No newline at end of file +} diff --git a/nano/node/transport/tcp_listener.hpp b/nano/node/transport/tcp_listener.hpp index c6c5730ce..3e188336c 100644 --- a/nano/node/transport/tcp_listener.hpp +++ b/nano/node/transport/tcp_listener.hpp @@ -20,6 +20,11 @@ namespace mi = boost::multi_index; namespace asio = boost::asio; +namespace nano::stat +{ +enum class dir; +} + namespace nano::transport { class tcp_config diff --git a/nano/node/vote_cache.hpp b/nano/node/vote_cache.hpp index c70bae9d3..86693d31e 100644 --- a/nano/node/vote_cache.hpp +++ b/nano/node/vote_cache.hpp @@ -26,6 +26,7 @@ namespace nano class node; class active_elections; class election; +class stats; class vote; enum class vote_code; enum class vote_source; diff --git a/nano/secure/common.cpp b/nano/secure/common.cpp index 2d912fb3c..92abdf01d 100644 --- a/nano/secure/common.cpp +++ b/nano/secure/common.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 6606ce5e5..dad2b6efb 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -16,6 +15,11 @@ #include #include +namespace nano::stat +{ +enum class detail; +} + namespace nano { /** From a23deff88e0b75c749a7ee01bd7671a2b23d9e5b Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 28 Oct 2024 22:15:25 +0000 Subject: [PATCH 19/25] Forward declare nano::transport::fake::channel --- nano/core_test/active_elections.cpp | 1 + nano/core_test/block.cpp | 1 + nano/core_test/bootstrap_server.cpp | 1 + nano/core_test/fair_queue.cpp | 1 + nano/core_test/network.cpp | 1 + nano/core_test/network_filter.cpp | 1 + nano/core_test/request_aggregator.cpp | 1 + nano/core_test/telemetry.cpp | 1 + nano/core_test/vote_processor.cpp | 1 + nano/test_common/testutil.hpp | 10 +++++++++- 10 files changed, 18 insertions(+), 1 deletion(-) diff --git a/nano/core_test/active_elections.cpp b/nano/core_test/active_elections.cpp index 8840c9dc9..cdf92cac1 100644 --- a/nano/core_test/active_elections.cpp +++ b/nano/core_test/active_elections.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/block.cpp b/nano/core_test/block.cpp index 4da6e787f..fe90835fe 100644 --- a/nano/core_test/block.cpp +++ b/nano/core_test/block.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include diff --git a/nano/core_test/bootstrap_server.cpp b/nano/core_test/bootstrap_server.cpp index 659ecd46b..45e493807 100644 --- a/nano/core_test/bootstrap_server.cpp +++ b/nano/core_test/bootstrap_server.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/fair_queue.cpp b/nano/core_test/fair_queue.cpp index 50fd6c8fc..83366b1ce 100644 --- a/nano/core_test/fair_queue.cpp +++ b/nano/core_test/fair_queue.cpp @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/nano/core_test/network.cpp b/nano/core_test/network.cpp index 3ae42f764..1037580eb 100644 --- a/nano/core_test/network.cpp +++ b/nano/core_test/network.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/network_filter.cpp b/nano/core_test/network_filter.cpp index 12e816e2e..8765b1118 100644 --- a/nano/core_test/network_filter.cpp +++ b/nano/core_test/network_filter.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index 2f85074e4..5e99210c2 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/telemetry.cpp b/nano/core_test/telemetry.cpp index 2d120fe26..859d3ffb3 100644 --- a/nano/core_test/telemetry.cpp +++ b/nano/core_test/telemetry.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index 8855b17f1..aa8b7e757 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 38096d36f..45d2972df 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -115,6 +114,15 @@ ASSERT_FALSE (condition); \ } +namespace nano::store +{ +class component; +} +namespace nano::transport::fake +{ +class channel; +} + namespace nano::test { template From 31a9e7b73f201798add9aa2ab7cce6871342ebe4 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 28 Oct 2024 22:31:22 +0000 Subject: [PATCH 20/25] Add missing deque include. --- nano/node/vote_cache.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/nano/node/vote_cache.hpp b/nano/node/vote_cache.hpp index 86693d31e..e7fc4e519 100644 --- a/nano/node/vote_cache.hpp +++ b/nano/node/vote_cache.hpp @@ -13,6 +13,7 @@ #include #include +#include #include #include #include From de9b40b6440f937c68f53aafe5c988d663ec35ec Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Mon, 28 Oct 2024 22:41:39 +0000 Subject: [PATCH 21/25] Removing include of rep_weights from common.hpp --- nano/node/confirming_set.hpp | 1 + nano/node/distributed_work_factory.hpp | 1 + nano/node/election.hpp | 1 + nano/node/online_reps.hpp | 1 + nano/node/recently_confirmed_cache.hpp | 1 + nano/node/rep_tiers.hpp | 3 ++- nano/node/scheduler/bucket.hpp | 1 + nano/node/transport/tcp_channels.hpp | 1 + nano/node/vote_cache.cpp | 1 + nano/node/vote_router.hpp | 1 + nano/secure/common.hpp | 1 - 11 files changed, 11 insertions(+), 2 deletions(-) diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index 39fdec50e..b5d79be2b 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include diff --git a/nano/node/distributed_work_factory.hpp b/nano/node/distributed_work_factory.hpp index 8024bb184..56daf3b85 100644 --- a/nano/node/distributed_work_factory.hpp +++ b/nano/node/distributed_work_factory.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/nano/node/election.hpp b/nano/node/election.hpp index 3ab73a765..718cbf680 100644 --- a/nano/node/election.hpp +++ b/nano/node/election.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include #include diff --git a/nano/node/online_reps.hpp b/nano/node/online_reps.hpp index 2838346f3..d8e60665d 100644 --- a/nano/node/online_reps.hpp +++ b/nano/node/online_reps.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/nano/node/recently_confirmed_cache.hpp b/nano/node/recently_confirmed_cache.hpp index 803039275..bdfc95611 100644 --- a/nano/node/recently_confirmed_cache.hpp +++ b/nano/node/recently_confirmed_cache.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/nano/node/rep_tiers.hpp b/nano/node/rep_tiers.hpp index 71c63ab0d..3c4b54ee1 100644 --- a/nano/node/rep_tiers.hpp +++ b/nano/node/rep_tiers.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -64,4 +65,4 @@ private: mutable nano::mutex mutex; std::thread thread; }; -} \ No newline at end of file +} diff --git a/nano/node/scheduler/bucket.hpp b/nano/node/scheduler/bucket.hpp index 4994fa8b7..a95878dab 100644 --- a/nano/node/scheduler/bucket.hpp +++ b/nano/node/scheduler/bucket.hpp @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/nano/node/transport/tcp_channels.hpp b/nano/node/transport/tcp_channels.hpp index a4d4b2bc8..8e1aeeccc 100644 --- a/nano/node/transport/tcp_channels.hpp +++ b/nano/node/transport/tcp_channels.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include #include diff --git a/nano/node/vote_cache.cpp b/nano/node/vote_cache.cpp index dd190bc45..4fedd3a04 100644 --- a/nano/node/vote_cache.cpp +++ b/nano/node/vote_cache.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/vote_router.hpp b/nano/node/vote_router.hpp index ed2d3d09c..37c6ef87c 100644 --- a/nano/node/vote_router.hpp +++ b/nano/node/vote_router.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index dad2b6efb..542c18cad 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -10,7 +10,6 @@ #include #include #include -#include #include #include From 909cdfcf3e98df51e8526d8d93164d95fd8b391b Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 29 Oct 2024 04:40:08 +0000 Subject: [PATCH 22/25] Suppress iterator warning on windows. --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b93fac65..4da28f153 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,6 +35,8 @@ endif() if(MSVC) add_definitions(/MP) + add_definitions( + -D_SILENCE_STDEXT_ARR_ITERS_DEPRECATION_WARNING) # Suppress iterator warning endif() set(CPACK_PACKAGE_VENDOR "Nano Currency") From 70afe41fd39fc173480ef8c1ec188f5e6b4f6fdb Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Tue, 29 Oct 2024 04:40:21 +0000 Subject: [PATCH 23/25] Include missing optional header. --- nano/lib/blocks.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index 0c780c9a4..d16d0ca40 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -9,6 +9,8 @@ #include +#include + typedef struct blake2b_state__ blake2b_state; namespace nano From a57f5d07cb61fe2801dc859ba634df44c1e3dd57 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 30 Oct 2024 21:23:59 +0000 Subject: [PATCH 24/25] Add existing fwd files to cmake project. --- nano/node/CMakeLists.txt | 2 ++ nano/secure/CMakeLists.txt | 1 + nano/store/CMakeLists.txt | 1 + 3 files changed, 4 insertions(+) diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index c27e6c0bb..ed081e372 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -80,6 +80,7 @@ add_library( epoch_upgrader.hpp epoch_upgrader.cpp fair_queue.hpp + fwd.hpp ipc/action_handler.hpp ipc/action_handler.cpp ipc/flatbuffers_handler.hpp @@ -166,6 +167,7 @@ add_library( transport/tcp_channel.cpp transport/fake.hpp transport/fake.cpp + transport/fwd.hpp transport/inproc.hpp transport/inproc.cpp transport/message_deserializer.hpp diff --git a/nano/secure/CMakeLists.txt b/nano/secure/CMakeLists.txt index c495c1270..a0cbea2a4 100644 --- a/nano/secure/CMakeLists.txt +++ b/nano/secure/CMakeLists.txt @@ -20,6 +20,7 @@ add_library( account_iterator_impl.hpp common.hpp common.cpp + fwd.hpp generate_cache_flags.hpp generate_cache_flags.cpp ledger.hpp diff --git a/nano/store/CMakeLists.txt b/nano/store/CMakeLists.txt index 0fb509489..e3f4ef175 100644 --- a/nano/store/CMakeLists.txt +++ b/nano/store/CMakeLists.txt @@ -9,6 +9,7 @@ add_library( db_val_impl.hpp iterator.hpp final_vote.hpp + fwd.hpp lmdb/account.hpp lmdb/block.hpp lmdb/confirmation_height.hpp From a7cfce13011900826f4d1eebfc3d96d5a45dea7f Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 30 Oct 2024 22:04:07 +0000 Subject: [PATCH 25/25] Move a number of forward declarations in to the fwd.hpp files. --- nano/lib/CMakeLists.txt | 2 +- nano/lib/block_sideband.hpp | 8 +---- nano/lib/blocks.hpp | 10 +----- nano/lib/fwd.hpp | 31 +++++++++++++++++++ nano/lib/stream_fwd.hpp | 10 ------ nano/node/bandwidth_limiter.hpp | 5 --- .../node/bootstrap_ascending/account_sets.hpp | 7 +---- nano/node/confirming_set.hpp | 9 +----- nano/node/epoch_upgrader.hpp | 16 +++------- nano/node/fwd.hpp | 15 +++------ nano/node/ipc/ipc_config.hpp | 7 +---- nano/node/messages.hpp | 9 ++---- nano/node/transport/fwd.hpp | 6 +++- nano/node/transport/tcp_listener.hpp | 6 +--- nano/node/vote_cache.hpp | 13 ++------ nano/secure/account_info.hpp | 2 +- nano/secure/common.hpp | 7 +---- nano/secure/fwd.hpp | 19 +++++++----- nano/secure/pending_info.hpp | 13 ++------ nano/secure/vote.hpp | 7 +---- nano/store/component.hpp | 22 ++----------- nano/store/fwd.hpp | 20 ++++++++++-- nano/test_common/testutil.hpp | 11 ++----- 23 files changed, 93 insertions(+), 162 deletions(-) create mode 100644 nano/lib/fwd.hpp delete mode 100644 nano/lib/stream_fwd.hpp diff --git a/nano/lib/CMakeLists.txt b/nano/lib/CMakeLists.txt index 2e60cf4dd..748df5439 100644 --- a/nano/lib/CMakeLists.txt +++ b/nano/lib/CMakeLists.txt @@ -49,6 +49,7 @@ add_library( epochs.hpp errors.hpp errors.cpp + fwd.hpp id_dispenser.hpp interval.hpp ipc.hpp @@ -97,7 +98,6 @@ add_library( stats_enums.cpp stats_sinks.hpp stream.hpp - stream_fwd.hpp thread_pool.hpp thread_roles.hpp thread_roles.cpp diff --git a/nano/lib/block_sideband.hpp b/nano/lib/block_sideband.hpp index 6ed9c6e9b..09dcc8a96 100644 --- a/nano/lib/block_sideband.hpp +++ b/nano/lib/block_sideband.hpp @@ -1,19 +1,13 @@ #pragma once #include +#include #include -#include #include #include #include -namespace nano -{ -enum class block_type : uint8_t; -class object_stream; -} - namespace nano { class block_details diff --git a/nano/lib/blocks.hpp b/nano/lib/blocks.hpp index d16d0ca40..14524e556 100644 --- a/nano/lib/blocks.hpp +++ b/nano/lib/blocks.hpp @@ -3,9 +3,9 @@ #include #include #include +#include #include #include -#include #include @@ -15,14 +15,6 @@ typedef struct blake2b_state__ blake2b_state; namespace nano { -class block; -class block_visitor; -class mutable_block_visitor; -class object_stream; -template -class uniquer; -enum class work_version; - using block_uniquer = uniquer; } diff --git a/nano/lib/fwd.hpp b/nano/lib/fwd.hpp new file mode 100644 index 000000000..0409d7629 --- /dev/null +++ b/nano/lib/fwd.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include + +struct uint8_char_traits; +namespace nano +{ +class block; +enum class block_type : uint8_t; +class block_visitor; +class container_info; +enum class epoch : uint8_t; +class jsonconfig; +class mutable_block_visitor; +class network_constants; +class object_stream; +class thread_pool; +class tomlconfig; +template +class uniquer; +enum class work_version; + +using stream = std::basic_streambuf; +} + +namespace nano::stat +{ +enum class detail; +enum class dir; +} diff --git a/nano/lib/stream_fwd.hpp b/nano/lib/stream_fwd.hpp deleted file mode 100644 index 1b8bddd24..000000000 --- a/nano/lib/stream_fwd.hpp +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include -#include - -struct uint8_char_traits; -namespace nano -{ -using stream = std::basic_streambuf; -} diff --git a/nano/node/bandwidth_limiter.hpp b/nano/node/bandwidth_limiter.hpp index 4bd19ee7c..7afafee75 100644 --- a/nano/node/bandwidth_limiter.hpp +++ b/nano/node/bandwidth_limiter.hpp @@ -4,11 +4,6 @@ #include #include -namespace nano -{ -class node_config; -} - namespace nano { class bandwidth_limiter_config final diff --git a/nano/node/bootstrap_ascending/account_sets.hpp b/nano/node/bootstrap_ascending/account_sets.hpp index 5a77e2eca..22d35e606 100644 --- a/nano/node/bootstrap_ascending/account_sets.hpp +++ b/nano/node/bootstrap_ascending/account_sets.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -16,12 +17,6 @@ namespace mi = boost::multi_index; -namespace nano -{ -class account_sets_config; -class stats; -} - namespace nano { namespace bootstrap_ascending diff --git a/nano/node/confirming_set.hpp b/nano/node/confirming_set.hpp index b5d79be2b..50ca65655 100644 --- a/nano/node/confirming_set.hpp +++ b/nano/node/confirming_set.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -21,14 +22,6 @@ namespace mi = boost::multi_index; -namespace nano -{ -class election; -class ledger; -class logger; -class stats; -} - namespace nano { class confirming_set_config final diff --git a/nano/node/epoch_upgrader.hpp b/nano/node/epoch_upgrader.hpp index d2de09b41..5cbb9b7b8 100644 --- a/nano/node/epoch_upgrader.hpp +++ b/nano/node/epoch_upgrader.hpp @@ -1,24 +1,16 @@ #pragma once +#include #include #include #include +#include +#include +#include #include #include -namespace nano -{ -enum class epoch : uint8_t; -class network_params; -class node; -class ledger; -} -namespace nano::store -{ -class component; -} - namespace nano { class epoch_upgrader final diff --git a/nano/node/fwd.hpp b/nano/node/fwd.hpp index 7bdcb5766..df857acfc 100644 --- a/nano/node/fwd.hpp +++ b/nano/node/fwd.hpp @@ -1,24 +1,17 @@ #pragma once +#include #include #include #include -// TODO: Move to lib/fwd.hpp -namespace nano -{ -class block; -class container_info; -class thread_pool; -} - namespace nano { +class account_sets_config; class active_elections; class block_processor; class confirming_set; class election; -class ledger; class local_block_broadcaster; class local_vote_history; class logger; @@ -35,6 +28,8 @@ class rep_crawler; class rep_tiers; class stats; class vote_cache; +enum class vote_code; +enum class vote_source; class vote_generator; class vote_processor; class vote_router; @@ -53,4 +48,4 @@ class hinted; class manual; class optimistic; class priority; -} \ No newline at end of file +} diff --git a/nano/node/ipc/ipc_config.hpp b/nano/node/ipc/ipc_config.hpp index 4be3fb0df..3cdb73bef 100644 --- a/nano/node/ipc/ipc_config.hpp +++ b/nano/node/ipc/ipc_config.hpp @@ -2,15 +2,10 @@ #include #include +#include #include -namespace nano -{ -class network_constants; -class tomlconfig; -} - namespace nano { namespace ipc diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 85fa9d663..8e1db8e8e 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -4,15 +4,16 @@ #include #include #include +#include #include #include #include #include #include #include -#include #include #include +#include #include #include @@ -23,12 +24,6 @@ namespace nano { -class block; -class jsonconfig; -template -class uniquer; -class vote; - using block_uniquer = uniquer; using vote_uniquer = uniquer; } diff --git a/nano/node/transport/fwd.hpp b/nano/node/transport/fwd.hpp index c62c47030..4be374eba 100644 --- a/nano/node/transport/fwd.hpp +++ b/nano/node/transport/fwd.hpp @@ -7,4 +7,8 @@ class tcp_channel; class tcp_channels; class tcp_server; class tcp_socket; -} \ No newline at end of file +} +namespace nano::transport::fake +{ +class channel; +} diff --git a/nano/node/transport/tcp_listener.hpp b/nano/node/transport/tcp_listener.hpp index 3e188336c..66644665d 100644 --- a/nano/node/transport/tcp_listener.hpp +++ b/nano/node/transport/tcp_listener.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include #include @@ -20,11 +21,6 @@ namespace mi = boost::multi_index; namespace asio = boost::asio; -namespace nano::stat -{ -enum class dir; -} - namespace nano::transport { class tcp_config diff --git a/nano/node/vote_cache.hpp b/nano/node/vote_cache.hpp index e7fc4e519..b371941ac 100644 --- a/nano/node/vote_cache.hpp +++ b/nano/node/vote_cache.hpp @@ -4,7 +4,9 @@ #include #include #include +#include #include +#include #include #include @@ -22,17 +24,6 @@ namespace mi = boost::multi_index; -namespace nano -{ -class node; -class active_elections; -class election; -class stats; -class vote; -enum class vote_code; -enum class vote_source; -} - namespace nano { class vote_cache_config final diff --git a/nano/secure/account_info.hpp b/nano/secure/account_info.hpp index c8c018815..a40136f64 100644 --- a/nano/secure/account_info.hpp +++ b/nano/secure/account_info.hpp @@ -1,8 +1,8 @@ #pragma once #include +#include #include -#include #include namespace nano diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 542c18cad..b8f8ee110 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -5,20 +5,15 @@ #include #include #include +#include #include #include -#include #include #include #include #include -namespace nano::stat -{ -enum class detail; -} - namespace nano { /** diff --git a/nano/secure/fwd.hpp b/nano/secure/fwd.hpp index 1d57ae0cf..f6bb2076a 100644 --- a/nano/secure/fwd.hpp +++ b/nano/secure/fwd.hpp @@ -1,14 +1,17 @@ #pragma once -namespace nano::secure -{ -class transaction; -class write_transaction; -class read_transaction; -} - namespace nano { class account_info; +class ledger; +class ledger_cache; +class ledger_constants; +class network_params; class vote; -} \ No newline at end of file +} +namespace nano::secure +{ +class read_transaction; +class transaction; +class write_transaction; +} diff --git a/nano/secure/pending_info.hpp b/nano/secure/pending_info.hpp index 627db34aa..43273cab8 100644 --- a/nano/secure/pending_info.hpp +++ b/nano/secure/pending_info.hpp @@ -1,19 +1,10 @@ #pragma once #include +#include #include #include -#include - -namespace nano -{ -class ledger; -} - -namespace nano::secure -{ -class transaction; -} +#include namespace nano { diff --git a/nano/secure/vote.hpp b/nano/secure/vote.hpp index e04f24789..c4e24f149 100644 --- a/nano/secure/vote.hpp +++ b/nano/secure/vote.hpp @@ -1,7 +1,7 @@ #pragma once +#include #include -#include #include #include @@ -10,11 +10,6 @@ #include -namespace nano -{ -class object_stream; -} - namespace nano { class vote final diff --git a/nano/store/component.hpp b/nano/store/component.hpp index a08985039..13f00910f 100644 --- a/nano/store/component.hpp +++ b/nano/store/component.hpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include #include #include #include @@ -16,26 +18,6 @@ namespace nano { -namespace store -{ - class account; - class block; - class confirmation_height; - class final_vote; - class online_weight; - class peer; - class pending; - class pruned; - class read_transaction; - class rep_weight; - class transaction; - class version; - class write_transaction; -} -class ledger_cache; -class ledger_constants; -enum class tables; - namespace store { /** diff --git a/nano/store/fwd.hpp b/nano/store/fwd.hpp index 9ecd1ff3a..febe31a89 100644 --- a/nano/store/fwd.hpp +++ b/nano/store/fwd.hpp @@ -1,9 +1,23 @@ #pragma once +namespace nano +{ +enum class tables; +} namespace nano::store { +class account; +class block; class component; -class transaction; -class write_transaction; +class confirmation_height; +class final_vote; +class online_weight; +class peer; +class pending; +class pruned; class read_transaction; -} \ No newline at end of file +class rep_weight; +class transaction; +class version; +class write_transaction; +} diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 45d2972df..017d61655 100644 --- a/nano/test_common/testutil.hpp +++ b/nano/test_common/testutil.hpp @@ -2,7 +2,9 @@ #include #include +#include #include +#include #include @@ -114,15 +116,6 @@ ASSERT_FALSE (condition); \ } -namespace nano::store -{ -class component; -} -namespace nano::transport::fake -{ -class channel; -} - namespace nano::test { template