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 70ec28b40c..5be00af002 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 020722e315..591c799992 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 4fc527eb0d..294a0ceb09 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 a2e819cc37..1d6d0fb614 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 491741708f..dfbd1a360d 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 2e65afacbf..98b4d4fc6b 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 871f9bfcfc..e150538aed 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 294a0ceb09..81da54a859 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 4dda3dcf15..e249b3106c 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 37c2786bf2..1a4f6da6a1 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 4d8c953f56..758752a08e 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 34d6956a8b..7f47f79d00 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 c023ec1fe5..5d101fab48 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 439aa0ced0..2f88074398 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 bb6f4183e1..107c9d0344 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 f8265733fe..c4d3a0355f 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 288296d052..344910ae99 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 1d6d0fb614..c6e5dc4795 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 e556fda038..b8de6fff08 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 d2b8eab72d..4742c7dd79 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 ce050df029..8198cc9cab 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 d2857974de..4533eddccd 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 fe6026fdfb..75f3e51497 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 | 12 +++++++---- nano/secure/common.hpp | 2 +- 7 files changed, 95 insertions(+), 81 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 76d53944f0..3861893421 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 8fb6cd20f4..1de1a0476f 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 df0a24f7ba..4fae5e1a52 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 0000000000..426d5ab10d --- /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 0000000000..c81ade7f2d --- /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 d9bccad98e..d2de09b414 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 +} +namespace nano::store { - class component; +class component; } -class network_params; +namespace nano +{ class epoch_upgrader final { public: diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index e1639bd265..d79e314a33 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 7ee17cd1f9..7d9165c19b 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 1640648934..0336d10a09 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 @@ class work_pool final 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 9d08284dd0..7c51ce85b9 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 333a5ff980..3d0a248a22 100644 --- a/nano/lib/memory.hpp +++ b/nano/lib/memory.hpp @@ -48,6 +48,16 @@ class cleanup_guard final 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 5dd98516df..c62c301322 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 b3ce57fd8f..1847ff850d 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 d79e314a33..b3711d88e2 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 096c7dc6a9..83d12130de 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 3861893421..7c781add2e 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 bd1f309948..1e54097d05 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 c62c301322..92613306ec 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 cc542896ad..437852e945 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 f5fd8e44fc..920e20d51e 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 90991493d3..65a18dd215 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 344910ae99..2b90c682ef 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 c6e5dc4795..022c54d8e0 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 00f1070b0e..2aeb4aef67 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 c7892399e1..cd9d680096 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 4742c7dd79..653c60f760 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 8198cc9cab..bf3c5f60c6 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 e69de29bb2..14fd1b3c8c 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 81da54a859..acf3d05829 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 a30b2eb108..ec8bed3f4e 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 7c781add2e..e3d7375c86 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 d39bb3afc4..4a0c7076b9 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 bf8137c657..ccf42ba357 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 0000000000..d40de592a0 --- /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 311867e21a..9ee4e38c64 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 f46cd6352a..c5ee41827f 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 c00e1cdb39..90e8f52463 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 9209bbf255..29a2c28044 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 e3d7375c86..36647fd888 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 14fd1b3c8c..8b37f71dba 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 e150538aed..6ed9c6e9ba 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 acf3d05829..2c7510cd88 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 2312855cb6..41e08f89e7 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 0000000000..1b8bddd24c --- /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 4d0a276dfc..692ac43fd7 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 81d771a5e1..a7cb40598e 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 ad1a2201fe..f136bd036c 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 2aeb4aef67..9b315f538d 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 1b18ca6024..81bcec0c6b 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 ee850d8d2f..c8c0188151 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 a68f70b352..af8d0a7a19 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 920e20d51e..2d912fb3ca 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 a9d52588a6..85a32a8aaa 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 90e8f52463..627db34aa1 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 b2cbebef72..f2e1867dfa 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 296886634b..b7b7e6c633 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 0737acf00e..e04f247898 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 f36f837efe..328ad88e6c 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 f5dd614b3d..3c497ebedf 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 dfbd1a360d..1b085c394e 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 bff40fee21..52eb8ff885 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 60d2338218..e18c09c6c0 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 788d7c2715..12e816e2e9 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 3389a8a96f..241cd347bc 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 fc87e502f6..c27e6c0bba 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 8779400eec..fe021ffd27 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 f06f83196b..b02cd56fdc 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 d40e0fe5a4..19f8db7646 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 b3f1334b8f..62e7bc07bf 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 d246c23bb7..ee86e32a5c 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 2f88074398..79bbce58a8 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 5ebe67bbf1..fd65b4e3a3 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 17edecc60b..4d83e0160a 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 5edab1f7f9..ccfd7361fd 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 92613306ec..c1ed629ef3 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 0000000000..22d17e9630 --- /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 2b90c682ef..d62c3d09bd 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 022c54d8e0..c10f64199c 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 9b315f538d..dd47fa8b37 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 0ab498ed2b..d1130271d1 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 b8de6fff08..12e6069fc8 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 3100bfe09c..e209d5e638 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 15d13ffdde..6200446b57 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 @@ class peer_history final 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 8465b7d2b0..75faab069d 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 cb9c337a91..8e0fe8c314 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 6a4c6663e8..8b7055c46a 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 212dc1c373..8f860f58c3 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 @@ class channel 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 4c4d62c229..ca8d923f37 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 1b6f1e363d..a4d4b2bc8f 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 @@ class tcp_channels final 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 55c63da64a..c6c5730ced 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 @@ class tcp_listener final 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 96085ae8b1..c4971464d7 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 4a90626f9e..21f5fea047 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 3065bbd049..5703a8c73d 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 2a38956060..1a5eb0dbb8 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 806f07645b..e16a3f4e5f 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 3bfcd22c38..d201fee17d 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 758a5c72ee..b336139c97 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 db2465e074..a2aa36a3ce 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 3c497ebedf..79037a9cd0 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 98b4d4fc6b..77fbc418d8 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 6eb8437464..f5e040aa9a 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 52eb8ff885..0e9e80f90d 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 377d61ed54..e8b836847d 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 7f9f1088a0..0ac3c28a3e 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 e9e170f6d5..79068966e8 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 65a18dd215..fd527f8fa4 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 63eae4cf7f..cb4eed4606 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 36647fd888..2e60cf4ddd 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 2c7510cd88..ab667ee8f2 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 41e08f89e7..913c47913c 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 e249b3106c..41b73e5106 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 c67095967b..239f5ad8ce 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 7d9165c19b..3097bc4125 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 0000000000..fb24b82d32 --- /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 1a4f6da6a1..96d9349f0f 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 69d2a50657..1a44e9f244 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 d62c3d09bd..08f911108f 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 12e6069fc8..c115ebaa3a 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 18dd7df7a8..ba65fe0dc5 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 b4070ca80e..f79f35e7c1 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 bf3c5f60c6..fe698dce87 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 b9c3731f69..d6e181a8bc 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 b336139c97..4071ea4624 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 913c47913c..0c780c9a40 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 dd47fa8b37..d21a22868f 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 716be359cf..38096d36f7 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 f592ea133c..8840c9dc9e 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 79037a9cd0..4da6e787f2 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 43c1938158..f9469f3bf0 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 0dd6e786db..d43d412690 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 6d5dd4ae90..087f848947 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 e18c09c6c0..12ff989afd 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 44e9fa06df..7d65d6528a 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 e8b836847d..87f91c04bd 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 1d52769df9..e9d0ba8d41 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 3f656794e8..8855b17f1e 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 241cd347bc..55d63259fc 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 ab667ee8f2..d61233e4a1 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 96d9349f0f..5477769e7d 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 1bd9e58339..4bd19ee7c3 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 @@ class bandwidth_limiter final 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 b02cd56fdc..3d6ec25f12 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 ea64fe9fd0..ce6c686ef8 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 d83d3a8898..5a77e2eca2 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 644b241c92..39fdec50e9 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 06ea41350d..7cd964aae6 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 ccfd7361fd..891f887282 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 04d4901b3e..323063976d 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 4722177da8..4be3fb0df3 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 d2bed33ce3..a88ed25f95 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 469c55bd18..a172f48df9 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 c10f64199c..d665ee3f86 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 d21a22868f..85fa9d6638 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 c115ebaa3a..0c55b6e114 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 b3dc58c405..b54eae4a50 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 668bbec6d6..4994fa8b74 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 36f9c4adf9..dd190bc456 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 e29c88cc97..faf3c273ba 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 4d0c8ef547..283e78ac90 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 acf3d069c3..0f80e4995a 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 653c60f760..32a68d2bb5 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 fe698dce87..de71a49c8c 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 b3711d88e2..6606ce5e52 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 d6e181a8bc..982c5b873e 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 938aa2566a..b3fcffa9f7 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 328ad88e6c..a08985039d 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 7cc415a5fd..12b81a143f 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 f2c3c77129..8218fd22c4 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 c9cca1030f..84cb65f412 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 8c5fdc2fe7..9939ebf30d 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 f672467872..65f7bc21b7 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 @@ class rate_limiter final 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 2921881b52..3de7e7dc8d 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 6bc532787e..a0eb4fe433 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 c6c5730ced..3e188336c5 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 c70bae9d37..86693d31ee 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 2d912fb3ca..92abdf01d4 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 6606ce5e52..dad2b6efb5 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 8840c9dc9e..cdf92cac11 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 4da6e787f2..fe90835fea 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 659ecd46ba..45e493807a 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 50fd6c8fc2..83366b1cea 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 3ae42f764b..1037580eb2 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 12e816e2e9..8765b11180 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 2f85074e40..5e99210c28 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 2d120fe260..859d3ffb39 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 8855b17f1e..aa8b7e7578 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 38096d36f7..45d2972dfa 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 86693d31ee..e7fc4e519d 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 39fdec50e9..b5d79be2b4 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 8024bb1841..56daf3b853 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 3ab73a765f..718cbf680c 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 2838346f3b..d8e60665de 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 803039275e..bdfc95611a 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 71c63ab0df..3c4b54ee11 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 @@ class rep_tiers final 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 4994fa8b74..a95878dabf 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 a4d4b2bc8f..8e1aeeccc0 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 dd190bc456..4fedd3a04c 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 ed2d3d09c5..37c6ef87c0 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 dad2b6efb5..542c18cad3 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 5b93fac654..4da28f153a 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 0c780c9a40..d16d0ca401 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 c27e6c0bba..ed081e3724 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 c495c12700..a0cbea2a44 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 0fb509489a..e3f4ef175a 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 | 17 +++++----- nano/secure/pending_info.hpp | 13 ++------ nano/secure/vote.hpp | 7 +---- nano/store/component.hpp | 22 ++----------- nano/store/fwd.hpp | 18 +++++++++-- nano/test_common/testutil.hpp | 11 ++----- 23 files changed, 91 insertions(+), 160 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 2e60cf4ddd..748df54398 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 6ed9c6e9ba..09dcc8a96a 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 d16d0ca401..14524e556d 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 0000000000..0409d7629d --- /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 1b8bddd24c..0000000000 --- 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 4bd19ee7c3..7afafee75c 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 5a77e2eca2..22d35e6060 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 b5d79be2b4..50ca656552 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 d2de09b414..5cbb9b7b88 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 7bdcb57665..df857acfc1 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 4be3fb0df3..3cdb73bef3 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 85fa9d6638..8e1db8e8eb 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 c62c470304..4be374eba9 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 3e188336c5..66644665d1 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 e7fc4e519d..b371941ac7 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 c8c0188151..a40136f64f 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 542c18cad3..b8f8ee1108 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 1d57ae0cfc..f6bb2076a3 100644 --- a/nano/secure/fwd.hpp +++ b/nano/secure/fwd.hpp @@ -1,14 +1,17 @@ #pragma once +namespace nano +{ +class account_info; +class ledger; +class ledger_cache; +class ledger_constants; +class network_params; +class vote; +} namespace nano::secure { +class read_transaction; class transaction; class write_transaction; -class read_transaction; } - -namespace nano -{ -class account_info; -class vote; -} \ No newline at end of file diff --git a/nano/secure/pending_info.hpp b/nano/secure/pending_info.hpp index 627db34aa1..43273cab8f 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 e04f247898..c4e24f149d 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 a08985039d..13f00910f5 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 9ecd1ff3a5..febe31a892 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 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 read_transaction; -} \ No newline at end of file +} diff --git a/nano/test_common/testutil.hpp b/nano/test_common/testutil.hpp index 45d2972dfa..017d616550 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