From 0e441a91281bff7a4ae05c7cb798728a1aacd852 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 20 Mar 2024 11:10:19 +0000 Subject: [PATCH 1/5] Remove inclusion of election.hpp from other headers Moves election_behavior enum and vote_with_weight_info classes in to their own files. Before: [118/118] Linking CXX executable rpc_test ninja 1208.77s user 85.03s system 875% cpu 2:27.78 total After: [39/39] Linking CXX executable rpc_test ninja 338.18s user 25.74s system 714% cpu 50.953 total --- nano/core_test/confirmation_solicitor.cpp | 1 + nano/core_test/election_scheduler.cpp | 1 + nano/core_test/request_aggregator.cpp | 1 + nano/core_test/vote_processor.cpp | 1 + nano/core_test/wallet.cpp | 1 + nano/core_test/wallets.cpp | 1 + nano/node/CMakeLists.txt | 2 ++ nano/node/active_transactions.hpp | 3 ++- nano/node/election.hpp | 30 ++--------------------- nano/node/election_behavior.hpp | 22 +++++++++++++++++ nano/node/node.hpp | 1 - nano/node/scheduler/manual.cpp | 1 + nano/node/scheduler/priority.cpp | 1 + nano/node/vote_cache.cpp | 3 ++- nano/node/vote_with_weight_info.hpp | 18 ++++++++++++++ nano/node/websocket.hpp | 2 +- nano/qt/qt.cpp | 1 + nano/rpc_test/rpc.cpp | 1 + nano/test_common/testutil.cpp | 1 + 19 files changed, 60 insertions(+), 32 deletions(-) create mode 100644 nano/node/election_behavior.hpp create mode 100644 nano/node/vote_with_weight_info.hpp diff --git a/nano/core_test/confirmation_solicitor.cpp b/nano/core_test/confirmation_solicitor.cpp index 7afa210a2f..a35ff98912 100644 --- a/nano/core_test/confirmation_solicitor.cpp +++ b/nano/core_test/confirmation_solicitor.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/election_scheduler.cpp b/nano/core_test/election_scheduler.cpp index c453bfe00e..92afc9b2d1 100644 --- a/nano/core_test/election_scheduler.cpp +++ b/nano/core_test/election_scheduler.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index 7b1913f411..3851fa82e1 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index f755eb8ac0..6e271568ed 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.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 de2cfb42c0..358ee2d2af 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/wallets.cpp b/nano/core_test/wallets.cpp index af4b953b1f..48c0e79dc0 100644 --- a/nano/core_test/wallets.cpp +++ b/nano/core_test/wallets.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 9602dc0a2a..439ee94fdf 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -75,6 +75,7 @@ add_library( distributed_work_factory.cpp election.hpp election.cpp + election_behavior.hpp election_insertion_result.hpp epoch_upgrader.hpp epoch_upgrader.cpp @@ -164,6 +165,7 @@ add_library( vote_cache.cpp vote_processor.hpp vote_processor.cpp + vote_with_weight_info.hpp voting.hpp voting.cpp wallet.hpp diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 7323bf51dc..e1dececf0e 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -1,8 +1,9 @@ #pragma once #include -#include +#include #include +#include #include #include diff --git a/nano/node/election.hpp b/nano/node/election.hpp index 59cf2ea9e0..5ea0c43cef 100644 --- a/nano/node/election.hpp +++ b/nano/node/election.hpp @@ -2,6 +2,8 @@ #include #include +#include +#include #include #include @@ -24,34 +26,6 @@ class vote_info final nano::block_hash hash; }; -class vote_with_weight_info final -{ -public: - nano::account representative; - std::chrono::steady_clock::time_point time; - uint64_t timestamp; - nano::block_hash hash; - nano::uint128_t weight; -}; - -enum class election_behavior -{ - normal, - /** - * Hinted elections: - * - shorter timespan - * - limited space inside AEC - */ - hinted, - /** - * Optimistic elections: - * - shorter timespan - * - limited space inside AEC - * - more frequent confirmation requests - */ - optimistic, -}; - nano::stat::detail to_stat_detail (nano::election_behavior); // map of vote weight per block, ordered greater first diff --git a/nano/node/election_behavior.hpp b/nano/node/election_behavior.hpp new file mode 100644 index 0000000000..c78733a30e --- /dev/null +++ b/nano/node/election_behavior.hpp @@ -0,0 +1,22 @@ +#pragma once + +namespace nano +{ +enum class election_behavior +{ + normal, + /** + * Hinted elections: + * - shorter timespan + * - limited space inside AEC + */ + hinted, + /** + * Optimistic elections: + * - shorter timespan + * - limited space inside AEC + * - more frequent confirmation requests + */ + optimistic, +}; +} diff --git a/nano/node/node.hpp b/nano/node/node.hpp index fe7e901a0c..5c0e705a3c 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -16,7 +16,6 @@ #include #include #include -#include #include #include #include diff --git a/nano/node/scheduler/manual.cpp b/nano/node/scheduler/manual.cpp index 7fc908bd32..f84774bc4e 100644 --- a/nano/node/scheduler/manual.cpp +++ b/nano/node/scheduler/manual.cpp @@ -1,3 +1,4 @@ +#include #include #include diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index f8e03ff396..b37276e069 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/node/vote_cache.cpp b/nano/node/vote_cache.cpp index 4d40807d25..7779b0afff 100644 --- a/nano/node/vote_cache.cpp +++ b/nano/node/vote_cache.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -280,4 +281,4 @@ nano::error nano::vote_cache_config::deserialize (nano::tomlconfig & toml) age_cutoff = std::chrono::seconds{ age_cutoff_l }; return toml.get_error (); -} \ No newline at end of file +} diff --git a/nano/node/vote_with_weight_info.hpp b/nano/node/vote_with_weight_info.hpp new file mode 100644 index 0000000000..02daa9bb82 --- /dev/null +++ b/nano/node/vote_with_weight_info.hpp @@ -0,0 +1,18 @@ +#pragma once + +#include + +#include + +namespace nano +{ +class vote_with_weight_info final +{ +public: + nano::account representative; + std::chrono::steady_clock::time_point time; + uint64_t timestamp; + nano::block_hash hash; + nano::uint128_t weight; +}; +} diff --git a/nano/node/websocket.hpp b/nano/node/websocket.hpp index 6212198400..db470f7439 100644 --- a/nano/node/websocket.hpp +++ b/nano/node/websocket.hpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 6c578f06b4..744cf095ae 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 7d4e0705f7..5d5e4190c5 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index ce80cfeae0..114a7813bb 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include From c5b24e8000cb92da74d93f6fcea57397827b3fb8 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 20 Mar 2024 11:26:35 +0000 Subject: [PATCH 2/5] Reduce headers needed by election.hpp and moves election_status in to its own file Before: [39/39] Linking CXX executable rpc_test ninja 338.18s user 25.74s system 714% cpu 50.953 total After: [39/39] Linking CXX executable rpc_test ninja 339.33s user 27.66s system 778% cpu 47.155 total --- nano/node/CMakeLists.txt | 1 + nano/node/active_transactions.hpp | 1 + nano/node/election.hpp | 5 ++-- nano/node/election_status.hpp | 39 +++++++++++++++++++++++++++++++ nano/node/node_observers.hpp | 1 + nano/secure/common.hpp | 25 -------------------- 6 files changed, 45 insertions(+), 27 deletions(-) create mode 100644 nano/node/election_status.hpp diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index 439ee94fdf..aee2e628fb 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -77,6 +77,7 @@ add_library( election.cpp election_behavior.hpp election_insertion_result.hpp + election_status.hpp epoch_upgrader.hpp epoch_upgrader.cpp ipc/action_handler.hpp diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index e1dececf0e..8d966dbba5 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/election.hpp b/nano/node/election.hpp index 5ea0c43cef..22dc8ab5c8 100644 --- a/nano/node/election.hpp +++ b/nano/node/election.hpp @@ -2,10 +2,10 @@ #include #include +#include #include +#include #include -#include -#include #include #include @@ -13,6 +13,7 @@ namespace nano { +class block; class channel; class confirmation_solicitor; class inactive_cache_information; diff --git a/nano/node/election_status.hpp b/nano/node/election_status.hpp new file mode 100644 index 0000000000..014a14ad73 --- /dev/null +++ b/nano/node/election_status.hpp @@ -0,0 +1,39 @@ +#pragma once + +#include + +#include +#include + +namespace nano +{ +class block; +} + +namespace nano +{ +/* Defines the possible states for an election to stop in */ +enum class election_status_type : uint8_t +{ + ongoing = 0, + active_confirmed_quorum = 1, + active_confirmation_height = 2, + inactive_confirmation_height = 3, + stopped = 5 +}; + +/* Holds a summary of an election */ +class election_status final +{ +public: + std::shared_ptr winner; + nano::amount tally{ 0 }; + nano::amount final_tally{ 0 }; + std::chrono::milliseconds election_end{ std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()) }; + std::chrono::milliseconds election_duration{ std::chrono::duration_values::zero () }; + unsigned confirmation_request_count{ 0 }; + unsigned block_count{ 0 }; + unsigned voter_count{ 0 }; + election_status_type type{ nano::election_status_type::inactive_confirmation_height }; +}; +} diff --git a/nano/node/node_observers.hpp b/nano/node/node_observers.hpp index 8825655c5d..083be5c374 100644 --- a/nano/node/node_observers.hpp +++ b/nano/node/node_observers.hpp @@ -7,6 +7,7 @@ namespace nano { +class election_status; class telemetry; class node_observers final { diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index d585e1b222..9ce8c55e10 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -345,30 +345,5 @@ enum class confirmation_height_mode bounded }; -/* Defines the possible states for an election to stop in */ -enum class election_status_type : uint8_t -{ - ongoing = 0, - active_confirmed_quorum = 1, - active_confirmation_height = 2, - inactive_confirmation_height = 3, - stopped = 5 -}; - -/* Holds a summary of an election */ -class election_status final -{ -public: - std::shared_ptr winner; - nano::amount tally{ 0 }; - nano::amount final_tally{ 0 }; - std::chrono::milliseconds election_end{ std::chrono::duration_cast (std::chrono::system_clock::now ().time_since_epoch ()) }; - std::chrono::milliseconds election_duration{ std::chrono::duration_values::zero () }; - unsigned confirmation_request_count{ 0 }; - unsigned block_count{ 0 }; - unsigned voter_count{ 0 }; - election_status_type type{ nano::election_status_type::inactive_confirmation_height }; -}; - nano::wallet_id random_wallet_id (); } From f430d8fb150fa6015a276eec7974c09806959b47 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 20 Mar 2024 12:14:49 +0000 Subject: [PATCH 3/5] Move local_vote_history in to its own file. --- nano/core_test/node.cpp | 1 + nano/core_test/request_aggregator.cpp | 1 + nano/core_test/voting.cpp | 1 + nano/lib/numbers.hpp | 8 ++ nano/node/CMakeLists.txt | 2 + nano/node/active_transactions.hpp | 3 +- nano/node/blockprocessor.cpp | 1 + nano/node/election.cpp | 1 + nano/node/local_vote_history.cpp | 115 ++++++++++++++++++++++++++ nano/node/local_vote_history.hpp | 74 +++++++++++++++++ nano/node/node.cpp | 6 +- nano/node/node.hpp | 3 +- nano/node/request_aggregator.cpp | 1 + nano/node/voting.cpp | 113 +------------------------ nano/node/voting.hpp | 54 +----------- nano/secure/common.hpp | 8 -- nano/secure/vote.hpp | 7 +- 17 files changed, 222 insertions(+), 177 deletions(-) create mode 100644 nano/node/local_vote_history.cpp create mode 100644 nano/node/local_vote_history.hpp diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 03c05211b1..f139d752d9 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index 3851fa82e1..3bb865f9f3 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index d6d644292e..c1122bc8a3 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/lib/numbers.hpp b/nano/lib/numbers.hpp index 3021524c4c..7396de3a08 100644 --- a/nano/lib/numbers.hpp +++ b/nano/lib/numbers.hpp @@ -389,4 +389,12 @@ struct hash> return hash (hash_a); } }; +template <> +struct hash<::nano::root> +{ + size_t operator() (::nano::root const & value_a) const + { + return std::hash<::nano::root> () (value_a); + } +}; } diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index aee2e628fb..f3283f2224 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -98,6 +98,8 @@ add_library( json_handler.cpp local_block_broadcaster.cpp local_block_broadcaster.hpp + local_vote_history.cpp + local_vote_history.hpp make_store.hpp make_store.cpp network.hpp diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 8d966dbba5..0ef5dcbd4d 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -53,8 +53,9 @@ class recently_confirmed_cache final private: // clang-format off - class tag_root {}; class tag_hash {}; + class tag_root {}; + class tag_sequence {}; using ordered_recent_confirmations = boost::multi_index_container #include #include +#include #include #include #include diff --git a/nano/node/election.cpp b/nano/node/election.cpp index a41136e4c0..3349d01621 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/local_vote_history.cpp b/nano/node/local_vote_history.cpp new file mode 100644 index 0000000000..8569c225f0 --- /dev/null +++ b/nano/node/local_vote_history.cpp @@ -0,0 +1,115 @@ +#include +#include +#include + +bool nano::local_vote_history::consistency_check (nano::root const & root_a) const +{ + auto & history_by_root (history.get ()); + auto const range (history_by_root.equal_range (root_a)); + // All cached votes for a root must be for the same hash, this is actively enforced in local_vote_history::add + auto consistent_same = std::all_of (range.first, range.second, [hash = range.first->hash] (auto const & info_a) { return info_a.hash == hash; }); + std::vector accounts; + std::transform (range.first, range.second, std::back_inserter (accounts), [] (auto const & info_a) { return info_a.vote->account; }); + std::sort (accounts.begin (), accounts.end ()); + // All cached votes must be unique by account, this is actively enforced in local_vote_history::add + auto consistent_unique = accounts.size () == std::unique (accounts.begin (), accounts.end ()) - accounts.begin (); + auto result = consistent_same && consistent_unique; + debug_assert (result); + return result; +} + +void nano::local_vote_history::add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a) +{ + nano::lock_guard guard{ mutex }; + clean (); + auto add_vote (true); + auto & history_by_root (history.get ()); + // Erase any vote that is not for this hash, or duplicate by account, and if new timestamp is higher + auto range (history_by_root.equal_range (root_a)); + for (auto i (range.first); i != range.second;) + { + if (i->hash != hash_a || (vote_a->account == i->vote->account && i->vote->timestamp () <= vote_a->timestamp ())) + { + i = history_by_root.erase (i); + } + else if (vote_a->account == i->vote->account && i->vote->timestamp () > vote_a->timestamp ()) + { + add_vote = false; + ++i; + } + else + { + ++i; + } + } + // Do not add new vote to cache if representative account is same and timestamp is lower + if (add_vote) + { + auto result (history_by_root.emplace (root_a, hash_a, vote_a)); + (void)result; + debug_assert (result.second); + } + debug_assert (consistency_check (root_a)); +} + +void nano::local_vote_history::erase (nano::root const & root_a) +{ + nano::lock_guard guard{ mutex }; + auto & history_by_root (history.get ()); + auto range (history_by_root.equal_range (root_a)); + history_by_root.erase (range.first, range.second); +} + +std::vector> nano::local_vote_history::votes (nano::root const & root_a) const +{ + nano::lock_guard guard{ mutex }; + std::vector> result; + auto range (history.get ().equal_range (root_a)); + std::transform (range.first, range.second, std::back_inserter (result), [] (auto const & entry) { return entry.vote; }); + return result; +} + +std::vector> nano::local_vote_history::votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a) const +{ + nano::lock_guard guard{ mutex }; + std::vector> result; + auto range (history.get ().equal_range (root_a)); + // clang-format off + nano::transform_if (range.first, range.second, std::back_inserter (result), + [&hash_a, is_final_a](auto const & entry) { return entry.hash == hash_a && (!is_final_a || entry.vote->timestamp () == std::numeric_limits::max ()); }, + [](auto const & entry) { return entry.vote; }); + // clang-format on + return result; +} + +bool nano::local_vote_history::exists (nano::root const & root_a) const +{ + nano::lock_guard guard{ mutex }; + return history.get ().find (root_a) != history.get ().end (); +} + +void nano::local_vote_history::clean () +{ + debug_assert (constants.max_cache > 0); + auto & history_by_sequence (history.get ()); + while (history_by_sequence.size () > constants.max_cache) + { + history_by_sequence.erase (history_by_sequence.begin ()); + } +} + +std::size_t nano::local_vote_history::size () const +{ + nano::lock_guard guard{ mutex }; + return history.size (); +} + +std::unique_ptr nano::local_vote_history::collect_container_info (std::string const & name) const +{ + std::size_t history_count = size (); + auto sizeof_element = sizeof (decltype (history)::value_type); + auto composite = std::make_unique (name); + /* This does not currently loop over each element inside the cache to get the sizes of the votes inside history*/ + composite->add_component (std::make_unique (container_info{ "history", history_count, sizeof_element })); + return composite; +} diff --git a/nano/node/local_vote_history.hpp b/nano/node/local_vote_history.hpp new file mode 100644 index 0000000000..2cf603ec4c --- /dev/null +++ b/nano/node/local_vote_history.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include +#include + +#include +#include +#include +#include + +#include +#include + +namespace mi = boost::multi_index; + +namespace nano +{ +class container_info_component; +class vote; +class voting_constants; +} + +namespace nano +{ +class local_vote_history final +{ + class local_vote final + { + public: + local_vote (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a) : + root (root_a), + hash (hash_a), + vote (vote_a) + { + } + nano::root root; + nano::block_hash hash; + std::shared_ptr vote; + }; + +public: + local_vote_history (nano::voting_constants const & constants) : + constants{ constants } + { + } + void add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a); + void erase (nano::root const & root_a); + + std::vector> votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a = false) const; + bool exists (nano::root const &) const; + std::size_t size () const; + + std::unique_ptr collect_container_info (std::string const & name) const; + +private: + // clang-format off + boost::multi_index_container, + mi::member>, + mi::sequenced>>> + history; + // clang-format on + + nano::voting_constants const & constants; + void clean (); + std::vector> votes (nano::root const & root_a) const; + // Only used in Debug + bool consistency_check (nano::root const &) const; + mutable nano::mutex mutex; + + friend class local_vote_history_basic_Test; +}; +} diff --git a/nano/node/node.cpp b/nano/node/node.cpp index a7babb7944..6a3dbd8ac5 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -171,7 +172,8 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy warmed_up (0), block_processor (*this, write_database_queue), online_reps (ledger, config), - history{ config.network_params.voting }, + history_impl{ std::make_unique (config.network_params.voting) }, + history{ *history_impl }, vote_uniquer{}, confirmation_height_processor (ledger, write_database_queue, config.conf_height_processor_batch_min_time, logger, node_initialized_latch, flags.confirmation_height_processor_mode), vote_cache{ config.vote_cache, stats }, @@ -537,7 +539,7 @@ std::unique_ptr nano::collect_container_info (no composite->add_component (node.rep_crawler.collect_container_info ("rep_crawler")); composite->add_component (node.block_processor.collect_container_info ("block_processor")); composite->add_component (collect_container_info (node.online_reps, "online_reps")); - composite->add_component (collect_container_info (node.history, "history")); + composite->add_component (node.history.collect_container_info ("history")); composite->add_component (node.block_uniquer.collect_container_info ("block_uniquer")); composite->add_component (node.vote_uniquer.collect_container_info ("vote_uniquer")); composite->add_component (collect_container_info (node.confirmation_height_processor, "confirmation_height_processor")); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 5c0e705a3c..5f62ba54eb 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -166,7 +166,8 @@ class node final : public std::enable_shared_from_this nano::vote_processor vote_processor; unsigned warmed_up; nano::block_processor block_processor; - nano::local_vote_history history; + std::unique_ptr history_impl; + nano::local_vote_history & history; nano::block_uniquer block_uniquer; nano::vote_uniquer vote_uniquer; nano::confirmation_height_processor confirmation_height_processor; diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index 32ad38d61d..62d37146da 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/voting.cpp b/nano/node/voting.cpp index 13a66ea9e2..5101ca51db 100644 --- a/nano/node/voting.cpp +++ b/nano/node/voting.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -50,118 +51,6 @@ std::size_t nano::vote_spacing::size () const return recent.size (); } -bool nano::local_vote_history::consistency_check (nano::root const & root_a) const -{ - auto & history_by_root (history.get ()); - auto const range (history_by_root.equal_range (root_a)); - // All cached votes for a root must be for the same hash, this is actively enforced in local_vote_history::add - auto consistent_same = std::all_of (range.first, range.second, [hash = range.first->hash] (auto const & info_a) { return info_a.hash == hash; }); - std::vector accounts; - std::transform (range.first, range.second, std::back_inserter (accounts), [] (auto const & info_a) { return info_a.vote->account; }); - std::sort (accounts.begin (), accounts.end ()); - // All cached votes must be unique by account, this is actively enforced in local_vote_history::add - auto consistent_unique = accounts.size () == std::unique (accounts.begin (), accounts.end ()) - accounts.begin (); - auto result = consistent_same && consistent_unique; - debug_assert (result); - return result; -} - -void nano::local_vote_history::add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a) -{ - nano::lock_guard guard{ mutex }; - clean (); - auto add_vote (true); - auto & history_by_root (history.get ()); - // Erase any vote that is not for this hash, or duplicate by account, and if new timestamp is higher - auto range (history_by_root.equal_range (root_a)); - for (auto i (range.first); i != range.second;) - { - if (i->hash != hash_a || (vote_a->account == i->vote->account && i->vote->timestamp () <= vote_a->timestamp ())) - { - i = history_by_root.erase (i); - } - else if (vote_a->account == i->vote->account && i->vote->timestamp () > vote_a->timestamp ()) - { - add_vote = false; - ++i; - } - else - { - ++i; - } - } - // Do not add new vote to cache if representative account is same and timestamp is lower - if (add_vote) - { - auto result (history_by_root.emplace (root_a, hash_a, vote_a)); - (void)result; - debug_assert (result.second); - } - debug_assert (consistency_check (root_a)); -} - -void nano::local_vote_history::erase (nano::root const & root_a) -{ - nano::lock_guard guard{ mutex }; - auto & history_by_root (history.get ()); - auto range (history_by_root.equal_range (root_a)); - history_by_root.erase (range.first, range.second); -} - -std::vector> nano::local_vote_history::votes (nano::root const & root_a) const -{ - nano::lock_guard guard{ mutex }; - std::vector> result; - auto range (history.get ().equal_range (root_a)); - std::transform (range.first, range.second, std::back_inserter (result), [] (auto const & entry) { return entry.vote; }); - return result; -} - -std::vector> nano::local_vote_history::votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a) const -{ - nano::lock_guard guard{ mutex }; - std::vector> result; - auto range (history.get ().equal_range (root_a)); - // clang-format off - nano::transform_if (range.first, range.second, std::back_inserter (result), - [&hash_a, is_final_a](auto const & entry) { return entry.hash == hash_a && (!is_final_a || entry.vote->timestamp () == std::numeric_limits::max ()); }, - [](auto const & entry) { return entry.vote; }); - // clang-format on - return result; -} - -bool nano::local_vote_history::exists (nano::root const & root_a) const -{ - nano::lock_guard guard{ mutex }; - return history.get ().find (root_a) != history.get ().end (); -} - -void nano::local_vote_history::clean () -{ - debug_assert (constants.max_cache > 0); - auto & history_by_sequence (history.get ()); - while (history_by_sequence.size () > constants.max_cache) - { - history_by_sequence.erase (history_by_sequence.begin ()); - } -} - -std::size_t nano::local_vote_history::size () const -{ - nano::lock_guard guard{ mutex }; - return history.size (); -} - -std::unique_ptr nano::collect_container_info (nano::local_vote_history & history, std::string const & name) -{ - std::size_t history_count = history.size (); - auto sizeof_element = sizeof (decltype (history.history)::value_type); - auto composite = std::make_unique (name); - /* This does not currently loop over each element inside the cache to get the sizes of the votes inside history*/ - composite->add_component (std::make_unique (container_info{ "history", history_count, sizeof_element })); - return composite; -} - nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::node & node_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::local_vote_history & history_a, nano::network & network_a, nano::stats & stats_a, nano::logger & logger_a, bool is_final_a) : config (config_a), node (node_a), diff --git a/nano/node/voting.hpp b/nano/node/voting.hpp index 24c5813dd1..0ed940e35a 100644 --- a/nano/node/voting.hpp +++ b/nano/node/voting.hpp @@ -22,9 +22,10 @@ namespace mi = boost::multi_index; namespace nano { -class node; class ledger; +class local_vote_history; class network; +class node; class node_config; class stats; class vote_processor; @@ -64,57 +65,6 @@ class vote_spacing final std::size_t size () const; }; -class local_vote_history final -{ - class local_vote final - { - public: - local_vote (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a) : - root (root_a), - hash (hash_a), - vote (vote_a) - { - } - nano::root root; - nano::block_hash hash; - std::shared_ptr vote; - }; - -public: - local_vote_history (nano::voting_constants const & constants) : - constants{ constants } - { - } - void add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr const & vote_a); - void erase (nano::root const & root_a); - - std::vector> votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a = false) const; - bool exists (nano::root const &) const; - std::size_t size () const; - -private: - // clang-format off - boost::multi_index_container, - mi::member>, - mi::sequenced>>> - history; - // clang-format on - - nano::voting_constants const & constants; - void clean (); - std::vector> votes (nano::root const & root_a) const; - // Only used in Debug - bool consistency_check (nano::root const &) const; - mutable nano::mutex mutex; - - friend std::unique_ptr collect_container_info (local_vote_history & history, std::string const & name); - friend class local_vote_history_basic_Test; -}; - -std::unique_ptr collect_container_info (local_vote_history & history, std::string const & name); - class vote_generator final { private: diff --git a/nano/secure/common.hpp b/nano/secure/common.hpp index 9ce8c55e10..aab26e8be9 100644 --- a/nano/secure/common.hpp +++ b/nano/secure/common.hpp @@ -73,14 +73,6 @@ struct hash<::nano::qualified_root> return std::hash<::nano::qualified_root> () (value_a); } }; -template <> -struct hash<::nano::root> -{ - size_t operator() (::nano::root const & value_a) const - { - return std::hash<::nano::root> () (value_a); - } -}; } namespace nano { diff --git a/nano/secure/vote.hpp b/nano/secure/vote.hpp index 9ae7b0689f..7c29d53842 100644 --- a/nano/secure/vote.hpp +++ b/nano/secure/vote.hpp @@ -10,6 +10,11 @@ #include +namespace nano +{ +class object_stream; +} + namespace nano { class vote final @@ -77,4 +82,4 @@ class vote final }; using vote_uniquer = nano::uniquer; -} \ No newline at end of file +} From 14860eaa09c3dd9f4f68e81a2f1019386806e1b7 Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 20 Mar 2024 13:32:41 +0000 Subject: [PATCH 4/5] Move vote_generator and vote_spacing in to their own files. Recompile time for voting.hpp before and vote headers after Before: [117/117] Linking CXX executable rpc_test ninja 1262.92s user 87.90s system 869% cpu 2:35.28 total After: [16/16] Linking CXX executable nano_node ninja 98.05s user 11.24s system 377% cpu 28.917 total --- nano/core_test/node.cpp | 1 + nano/core_test/voting.cpp | 3 +- nano/lib/processing_queue.hpp | 2 +- nano/node/CMakeLists.txt | 6 +- nano/node/active_transactions.hpp | 9 ++- nano/node/backlog_population.cpp | 2 + nano/node/election.cpp | 1 + nano/node/node.cpp | 13 +++-- nano/node/node.hpp | 6 +- nano/node/node_observers.hpp | 8 +++ nano/node/request_aggregator.cpp | 2 +- nano/node/scheduler/priority.hpp | 4 ++ nano/node/{voting.cpp => vote_generator.cpp} | 58 ++++---------------- nano/node/{voting.hpp => vote_generator.hpp} | 45 +++------------ nano/node/vote_spacing.cpp | 39 +++++++++++++ nano/node/vote_spacing.hpp | 45 +++++++++++++++ nano/test_common/ledger.hpp | 1 + 17 files changed, 149 insertions(+), 96 deletions(-) rename nano/node/{voting.cpp => vote_generator.cpp} (84%) rename nano/node/{voting.hpp => vote_generator.hpp} (75%) create mode 100644 nano/node/vote_spacing.cpp create mode 100644 nano/node/vote_spacing.hpp diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index f139d752d9..48fd15a04b 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/voting.cpp b/nano/core_test/voting.cpp index c1122bc8a3..3c08618ac5 100644 --- a/nano/core_test/voting.cpp +++ b/nano/core_test/voting.cpp @@ -1,7 +1,8 @@ #include #include #include -#include +#include +#include #include #include #include diff --git a/nano/lib/processing_queue.hpp b/nano/lib/processing_queue.hpp index e9f317373e..4570c95210 100644 --- a/nano/lib/processing_queue.hpp +++ b/nano/lib/processing_queue.hpp @@ -108,7 +108,7 @@ class processing_queue final } public: // Container info - std::unique_ptr collect_container_info (std::string const & name) + std::unique_ptr collect_container_info (std::string const & name) const { nano::lock_guard guard{ mutex }; diff --git a/nano/node/CMakeLists.txt b/nano/node/CMakeLists.txt index f3283f2224..3e3dd1dd37 100644 --- a/nano/node/CMakeLists.txt +++ b/nano/node/CMakeLists.txt @@ -166,11 +166,13 @@ add_library( unchecked_map.hpp vote_cache.hpp vote_cache.cpp + vote_generator.hpp + vote_generator.cpp vote_processor.hpp vote_processor.cpp + vote_spacing.hpp + vote_spacing.cpp vote_with_weight_info.hpp - voting.hpp - voting.cpp wallet.hpp wallet.cpp websocket.hpp diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 0ef5dcbd4d..da475cfd68 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -17,6 +16,7 @@ #include #include #include +#include #include namespace mi = boost::multi_index; @@ -32,7 +32,14 @@ class election; class vote; class confirmation_height_processor; class stats; +} +namespace nano::store +{ +class read_transaction; +} +namespace nano +{ class recently_confirmed_cache final { public: diff --git a/nano/node/backlog_population.cpp b/nano/node/backlog_population.cpp index 6b2a45156e..f459b50697 100644 --- a/nano/node/backlog_population.cpp +++ b/nano/node/backlog_population.cpp @@ -2,7 +2,9 @@ #include #include #include +#include #include +#include nano::backlog_population::backlog_population (const config & config_a, nano::store::component & store_a, nano::stats & stats_a) : config_m{ config_a }, diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 3349d01621..865593ab41 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 6a3dbd8ac5..57e52b3d01 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -4,8 +4,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -177,8 +178,10 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy vote_uniquer{}, confirmation_height_processor (ledger, write_database_queue, config.conf_height_processor_batch_min_time, logger, node_initialized_latch, flags.confirmation_height_processor_mode), vote_cache{ config.vote_cache, stats }, - generator{ config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* non-final */ false }, - final_generator{ config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true }, + generator_impl{ std::make_unique (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* non-final */ false) }, + generator{ *generator_impl }, + final_generator_impl{ std::make_unique (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true) }, + final_generator{ *final_generator_impl }, active{ *this, confirmation_height_processor, block_processor }, scheduler_impl{ std::make_unique (*this) }, scheduler{ *scheduler_impl }, @@ -547,8 +550,8 @@ std::unique_ptr nano::collect_container_info (no composite->add_component (collect_container_info (node.aggregator, "request_aggregator")); composite->add_component (node.scheduler.collect_container_info ("election_scheduler")); composite->add_component (node.vote_cache.collect_container_info ("vote_cache")); - composite->add_component (collect_container_info (node.generator, "vote_generator")); - composite->add_component (collect_container_info (node.final_generator, "vote_generator_final")); + composite->add_component (node.generator.collect_container_info ("vote_generator")); + composite->add_component (node.final_generator.collect_container_info ("vote_generator_final")); composite->add_component (node.ascendboot.collect_container_info ("bootstrap_ascending")); composite->add_component (node.unchecked.collect_container_info ("unchecked")); composite->add_component (node.local_block_broadcaster.collect_container_info ("local_block_broadcaster")); diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 5f62ba54eb..6d807463cd 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -172,8 +172,10 @@ class node final : public std::enable_shared_from_this nano::vote_uniquer vote_uniquer; nano::confirmation_height_processor confirmation_height_processor; nano::vote_cache vote_cache; - nano::vote_generator generator; - nano::vote_generator final_generator; + std::unique_ptr generator_impl; + nano::vote_generator & generator; + std::unique_ptr final_generator_impl; + nano::vote_generator & final_generator; nano::active_transactions active; private: // Placed here to maintain initialization order diff --git a/nano/node/node_observers.hpp b/nano/node/node_observers.hpp index 083be5c374..d1b074f2a4 100644 --- a/nano/node/node_observers.hpp +++ b/nano/node/node_observers.hpp @@ -9,6 +9,14 @@ namespace nano { class election_status; class telemetry; +} +namespace nano::transport +{ +class channel; +} + +namespace nano +{ class node_observers final { public: diff --git a/nano/node/request_aggregator.cpp b/nano/node/request_aggregator.cpp index 62d37146da..1c399bc9c0 100644 --- a/nano/node/request_aggregator.cpp +++ b/nano/node/request_aggregator.cpp @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index e232b3d971..d8a7b2daf8 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -17,6 +17,10 @@ class block; class container_info_component; class node; } +namespace nano::store +{ +class transaction; +} namespace nano::scheduler { diff --git a/nano/node/voting.cpp b/nano/node/vote_generator.cpp similarity index 84% rename from nano/node/voting.cpp rename to nano/node/vote_generator.cpp index 5101ca51db..addc721921 100644 --- a/nano/node/voting.cpp +++ b/nano/node/vote_generator.cpp @@ -5,52 +5,15 @@ #include #include #include +#include #include -#include +#include #include #include #include #include -void nano::vote_spacing::trim () -{ - recent.get ().erase (recent.get ().begin (), recent.get ().upper_bound (std::chrono::steady_clock::now () - delay)); -} - -bool nano::vote_spacing::votable (nano::root const & root_a, nano::block_hash const & hash_a) const -{ - bool result = true; - for (auto range = recent.get ().equal_range (root_a); result && range.first != range.second; ++range.first) - { - auto & item = *range.first; - result = hash_a == item.hash || item.time < std::chrono::steady_clock::now () - delay; - } - return result; -} - -void nano::vote_spacing::flag (nano::root const & root_a, nano::block_hash const & hash_a) -{ - trim (); - auto now = std::chrono::steady_clock::now (); - auto existing = recent.get ().find (root_a); - if (existing != recent.end ()) - { - recent.get ().modify (existing, [now] (entry & entry) { - entry.time = now; - }); - } - else - { - recent.insert ({ root_a, now, hash_a }); - } -} - -std::size_t nano::vote_spacing::size () const -{ - return recent.size (); -} - nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::node & node_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::local_vote_history & history_a, nano::network & network_a, nano::stats & stats_a, nano::logger & logger_a, bool is_final_a) : config (config_a), node (node_a), @@ -58,7 +21,8 @@ nano::vote_generator::vote_generator (nano::node_config const & config_a, nano:: wallets (wallets_a), vote_processor (vote_processor_a), history (history_a), - spacing{ config_a.network_params.voting.delay }, + spacing_impl{ std::make_unique (config_a.network_params.voting.delay) }, + spacing{ *spacing_impl }, network (network_a), stats (stats_a), logger (logger_a), @@ -318,20 +282,20 @@ void nano::vote_generator::run () } } -std::unique_ptr nano::collect_container_info (nano::vote_generator & vote_generator, std::string const & name) +std::unique_ptr nano::vote_generator::collect_container_info (std::string const & name) const { std::size_t candidates_count = 0; std::size_t requests_count = 0; { - nano::lock_guard guard{ vote_generator.mutex }; - candidates_count = vote_generator.candidates.size (); - requests_count = vote_generator.requests.size (); + nano::lock_guard guard{ mutex }; + candidates_count = candidates.size (); + requests_count = requests.size (); } - auto sizeof_candidate_element = sizeof (decltype (vote_generator.candidates)::value_type); - auto sizeof_request_element = sizeof (decltype (vote_generator.requests)::value_type); + auto sizeof_candidate_element = sizeof (decltype (candidates)::value_type); + auto sizeof_request_element = sizeof (decltype (requests)::value_type); auto composite = std::make_unique (name); composite->add_component (std::make_unique (container_info{ "candidates", candidates_count, sizeof_candidate_element })); composite->add_component (std::make_unique (container_info{ "requests", requests_count, sizeof_request_element })); - composite->add_component (vote_generator.vote_generation_queue.collect_container_info ("vote_generation_queue")); + composite->add_component (vote_generation_queue.collect_container_info ("vote_generation_queue")); return composite; } diff --git a/nano/node/voting.hpp b/nano/node/vote_generator.hpp similarity index 75% rename from nano/node/voting.hpp rename to nano/node/vote_generator.hpp index 0ed940e35a..4fc3d65e12 100644 --- a/nano/node/voting.hpp +++ b/nano/node/vote_generator.hpp @@ -29,42 +29,16 @@ class node; class node_config; class stats; class vote_processor; +class vote_spacing; class wallets; -namespace transport +} +namespace nano::transport { - class channel; +class channel; } -class vote_spacing final +namespace nano { - class entry - { - public: - nano::root root; - std::chrono::steady_clock::time_point time; - nano::block_hash hash; - }; - - boost::multi_index_container, - mi::member>, - mi::ordered_non_unique, - mi::member>>> - recent; - std::chrono::milliseconds const delay; - void trim (); - -public: - vote_spacing (std::chrono::milliseconds const & delay) : - delay{ delay } - { - } - bool votable (nano::root const & root_a, nano::block_hash const & hash_a) const; - void flag (nano::root const & root_a, nano::block_hash const & hash_a); - std::size_t size () const; -}; - class vote_generator final { private: @@ -85,6 +59,8 @@ class vote_generator final void start (); void stop (); + std::unique_ptr collect_container_info (std::string const & name) const; + private: void run (); void broadcast (nano::unique_lock &); @@ -109,7 +85,8 @@ class vote_generator final nano::wallets & wallets; nano::vote_processor & vote_processor; nano::local_vote_history & history; - nano::vote_spacing spacing; + std::unique_ptr spacing_impl; + nano::vote_spacing & spacing; nano::network & network; nano::stats & stats; nano::logger & logger; @@ -126,9 +103,5 @@ class vote_generator final std::deque candidates; std::atomic stopped{ false }; std::thread thread; - - friend std::unique_ptr collect_container_info (vote_generator & vote_generator, std::string const & name); }; - -std::unique_ptr collect_container_info (vote_generator & generator, std::string const & name); } diff --git a/nano/node/vote_spacing.cpp b/nano/node/vote_spacing.cpp new file mode 100644 index 0000000000..201a9d7b57 --- /dev/null +++ b/nano/node/vote_spacing.cpp @@ -0,0 +1,39 @@ +#include + +void nano::vote_spacing::trim () +{ + recent.get ().erase (recent.get ().begin (), recent.get ().upper_bound (std::chrono::steady_clock::now () - delay)); +} + +bool nano::vote_spacing::votable (nano::root const & root_a, nano::block_hash const & hash_a) const +{ + bool result = true; + for (auto range = recent.get ().equal_range (root_a); result && range.first != range.second; ++range.first) + { + auto & item = *range.first; + result = hash_a == item.hash || item.time < std::chrono::steady_clock::now () - delay; + } + return result; +} + +void nano::vote_spacing::flag (nano::root const & root_a, nano::block_hash const & hash_a) +{ + trim (); + auto now = std::chrono::steady_clock::now (); + auto existing = recent.get ().find (root_a); + if (existing != recent.end ()) + { + recent.get ().modify (existing, [now] (entry & entry) { + entry.time = now; + }); + } + else + { + recent.insert ({ root_a, now, hash_a }); + } +} + +std::size_t nano::vote_spacing::size () const +{ + return recent.size (); +} diff --git a/nano/node/vote_spacing.hpp b/nano/node/vote_spacing.hpp new file mode 100644 index 0000000000..f46cd6352a --- /dev/null +++ b/nano/node/vote_spacing.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include + +#include +#include +#include +#include + +#include + +namespace mi = boost::multi_index; + +namespace nano +{ +class vote_spacing final +{ + class entry + { + public: + nano::root root; + std::chrono::steady_clock::time_point time; + nano::block_hash hash; + }; + + boost::multi_index_container, + mi::member>, + mi::ordered_non_unique, + mi::member>>> + recent; + std::chrono::milliseconds const delay; + void trim (); + +public: + vote_spacing (std::chrono::milliseconds const & delay) : + delay{ delay } + { + } + bool votable (nano::root const & root_a, nano::block_hash const & hash_a) const; + void flag (nano::root const & root_a, nano::block_hash const & hash_a); + std::size_t size () const; +}; +} diff --git a/nano/test_common/ledger.hpp b/nano/test_common/ledger.hpp index 6c81f46bf6..e968f4d171 100644 --- a/nano/test_common/ledger.hpp +++ b/nano/test_common/ledger.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include namespace nano From 194003405148d7fa8e9c8ce553c47a82620be47a Mon Sep 17 00:00:00 2001 From: Colin LeMahieu Date: Wed, 20 Mar 2024 13:56:45 +0000 Subject: [PATCH 5/5] Remove inclusion of active_transactions.hpp from other headers Changes that edit active_transactions.hpp changed: Before: [116/116] Linking CXX executable rpc_test ninja 1194.40s user 83.30s system 860% cpu 2:28.51 total After: [49/49] Linking CXX executable rpc_test ninja 465.39s user 35.25s system 762% cpu 1:05.67 total --- nano/core_test/active_transactions.cpp | 1 + nano/core_test/bootstrap.cpp | 1 + nano/core_test/confirmation_height.cpp | 1 + nano/core_test/confirmation_solicitor.cpp | 1 + nano/core_test/conflicts.cpp | 1 + nano/core_test/election.cpp | 1 + nano/core_test/election_scheduler.cpp | 1 + nano/core_test/ledger.cpp | 1 + nano/core_test/node.cpp | 1 + nano/core_test/optimistic_scheduler.cpp | 1 + nano/core_test/rep_crawler.cpp | 1 + nano/core_test/request_aggregator.cpp | 1 + nano/core_test/vote_processor.cpp | 1 + nano/core_test/wallet.cpp | 1 + nano/core_test/wallets.cpp | 1 + nano/core_test/websocket.cpp | 1 + nano/nano_node/entry.cpp | 1 + nano/node/blockprocessor.cpp | 1 + nano/node/election.cpp | 1 + nano/node/json_handler.cpp | 1 + nano/node/node.cpp | 9 ++++++--- nano/node/node.hpp | 9 +++++---- nano/node/node_observers.hpp | 2 +- nano/node/repcrawler.cpp | 1 + nano/node/scheduler/hinted.cpp | 2 ++ nano/node/scheduler/manual.cpp | 1 + nano/node/scheduler/manual.hpp | 2 +- nano/node/scheduler/optimistic.cpp | 2 ++ nano/node/scheduler/priority.cpp | 1 + nano/node/scheduler/priority.hpp | 2 +- nano/node/websocket.cpp | 1 + nano/qt/qt.cpp | 1 + nano/rpc_test/rpc.cpp | 1 + nano/slow_test/node.cpp | 1 + nano/slow_test/vote_cache.cpp | 1 + nano/test_common/system.cpp | 1 + nano/test_common/testutil.cpp | 1 + 37 files changed, 48 insertions(+), 10 deletions(-) diff --git a/nano/core_test/active_transactions.cpp b/nano/core_test/active_transactions.cpp index e40e817015..ed9fef2da6 100644 --- a/nano/core_test/active_transactions.cpp +++ b/nano/core_test/active_transactions.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/core_test/bootstrap.cpp b/nano/core_test/bootstrap.cpp index 34617b1d0a..b78b65d5d3 100644 --- a/nano/core_test/bootstrap.cpp +++ b/nano/core_test/bootstrap.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/confirmation_height.cpp b/nano/core_test/confirmation_height.cpp index 352d04d4b7..b35eadc711 100644 --- a/nano/core_test/confirmation_height.cpp +++ b/nano/core_test/confirmation_height.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/core_test/confirmation_solicitor.cpp b/nano/core_test/confirmation_solicitor.cpp index a35ff98912..20e2ee5af5 100644 --- a/nano/core_test/confirmation_solicitor.cpp +++ b/nano/core_test/confirmation_solicitor.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/core_test/conflicts.cpp b/nano/core_test/conflicts.cpp index 943bb75699..323154046f 100644 --- a/nano/core_test/conflicts.cpp +++ b/nano/core_test/conflicts.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/election.cpp b/nano/core_test/election.cpp index 766b41c069..c46731aa76 100644 --- a/nano/core_test/election.cpp +++ b/nano/core_test/election.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/election_scheduler.cpp b/nano/core_test/election_scheduler.cpp index 92afc9b2d1..48ccac7682 100644 --- a/nano/core_test/election_scheduler.cpp +++ b/nano/core_test/election_scheduler.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/ledger.cpp b/nano/core_test/ledger.cpp index 773057e894..3ee507cb2b 100644 --- a/nano/core_test/ledger.cpp +++ b/nano/core_test/ledger.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/node.cpp b/nano/core_test/node.cpp index 48fd15a04b..77029005c7 100644 --- a/nano/core_test/node.cpp +++ b/nano/core_test/node.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/optimistic_scheduler.cpp b/nano/core_test/optimistic_scheduler.cpp index 789eb66b3c..1fc1deac86 100644 --- a/nano/core_test/optimistic_scheduler.cpp +++ b/nano/core_test/optimistic_scheduler.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/rep_crawler.cpp b/nano/core_test/rep_crawler.cpp index 6e78d3a674..0dc098ada9 100644 --- a/nano/core_test/rep_crawler.cpp +++ b/nano/core_test/rep_crawler.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/core_test/request_aggregator.cpp b/nano/core_test/request_aggregator.cpp index 3bb865f9f3..9860075c47 100644 --- a/nano/core_test/request_aggregator.cpp +++ b/nano/core_test/request_aggregator.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/core_test/vote_processor.cpp b/nano/core_test/vote_processor.cpp index 6e271568ed..2af6b1e9fe 100644 --- a/nano/core_test/vote_processor.cpp +++ b/nano/core_test/vote_processor.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 358ee2d2af..ef40fe8c72 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/wallets.cpp b/nano/core_test/wallets.cpp index 48c0e79dc0..fd5c54318b 100644 --- a/nano/core_test/wallets.cpp +++ b/nano/core_test/wallets.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/core_test/websocket.cpp b/nano/core_test/websocket.cpp index 0d147dba4f..8d90ef3eb3 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/nano_node/entry.cpp b/nano/nano_node/entry.cpp index fa4534e6ec..0d2898ab4e 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/blockprocessor.cpp b/nano/node/blockprocessor.cpp index a63206ca7d..564b6dd389 100644 --- a/nano/node/blockprocessor.cpp +++ b/nano/node/blockprocessor.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 865593ab41..3b2b5be479 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/node/json_handler.cpp b/nano/node/json_handler.cpp index 1d98e73cb9..1ba7f100e6 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/node.cpp b/nano/node/node.cpp index 57e52b3d01..95916058db 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -2,8 +2,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -167,22 +169,23 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy tcp_listener{ std::make_shared (network.port, *this, config.tcp_incoming_connections_max) }, application_path (application_path_a), port_mapping (*this), + block_processor (*this, write_database_queue), + confirmation_height_processor (ledger, write_database_queue, config.conf_height_processor_batch_min_time, logger, node_initialized_latch, flags.confirmation_height_processor_mode), + active_impl{ std::make_unique (*this, confirmation_height_processor, block_processor) }, + active{ *active_impl }, rep_crawler (config.rep_crawler, *this), rep_tiers{ ledger, network_params, online_reps, stats, logger }, vote_processor{ active, observers, stats, config, flags, logger, online_reps, rep_crawler, ledger, network_params, rep_tiers }, warmed_up (0), - block_processor (*this, write_database_queue), online_reps (ledger, config), history_impl{ std::make_unique (config.network_params.voting) }, history{ *history_impl }, vote_uniquer{}, - confirmation_height_processor (ledger, write_database_queue, config.conf_height_processor_batch_min_time, logger, node_initialized_latch, flags.confirmation_height_processor_mode), vote_cache{ config.vote_cache, stats }, generator_impl{ std::make_unique (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* non-final */ false) }, generator{ *generator_impl }, final_generator_impl{ std::make_unique (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true) }, final_generator{ *final_generator_impl }, - active{ *this, confirmation_height_processor, block_processor }, scheduler_impl{ std::make_unique (*this) }, scheduler{ *scheduler_impl }, aggregator (config, stats, generator, final_generator, history, ledger, wallets, active), diff --git a/nano/node/node.hpp b/nano/node/node.hpp index 6d807463cd..7bace7a735 100644 --- a/nano/node/node.hpp +++ b/nano/node/node.hpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -47,6 +46,7 @@ namespace nano { +class active_transactions; namespace rocksdb { } // Declare a namespace rocksdb inside nano so all references to the rocksdb library need to be globally scoped e.g. ::rocksdb::Slice @@ -160,23 +160,24 @@ class node final : public std::enable_shared_from_this std::filesystem::path application_path; nano::node_observers observers; nano::port_mapping port_mapping; + nano::block_processor block_processor; + nano::confirmation_height_processor confirmation_height_processor; + std::unique_ptr active_impl; + nano::active_transactions & active; nano::online_reps online_reps; nano::rep_crawler rep_crawler; nano::rep_tiers rep_tiers; nano::vote_processor vote_processor; unsigned warmed_up; - nano::block_processor block_processor; std::unique_ptr history_impl; nano::local_vote_history & history; nano::block_uniquer block_uniquer; nano::vote_uniquer vote_uniquer; - nano::confirmation_height_processor confirmation_height_processor; nano::vote_cache vote_cache; std::unique_ptr generator_impl; nano::vote_generator & generator; std::unique_ptr final_generator_impl; nano::vote_generator & final_generator; - nano::active_transactions active; private: // Placed here to maintain initialization order std::unique_ptr scheduler_impl; diff --git a/nano/node/node_observers.hpp b/nano/node/node_observers.hpp index d1b074f2a4..9a97987c14 100644 --- a/nano/node/node_observers.hpp +++ b/nano/node/node_observers.hpp @@ -2,8 +2,8 @@ #include #include -#include #include +#include namespace nano { diff --git a/nano/node/repcrawler.cpp b/nano/node/repcrawler.cpp index adf2fd2fe1..42f6d210d7 100644 --- a/nano/node/repcrawler.cpp +++ b/nano/node/repcrawler.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/scheduler/hinted.cpp b/nano/node/scheduler/hinted.cpp index 33e008fa53..a6f976864f 100644 --- a/nano/node/scheduler/hinted.cpp +++ b/nano/node/scheduler/hinted.cpp @@ -1,5 +1,7 @@ #include #include +#include +#include #include #include #include diff --git a/nano/node/scheduler/manual.cpp b/nano/node/scheduler/manual.cpp index f84774bc4e..3bcc83c163 100644 --- a/nano/node/scheduler/manual.cpp +++ b/nano/node/scheduler/manual.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/nano/node/scheduler/manual.hpp b/nano/node/scheduler/manual.hpp index f29f42d2b2..947c2fe4d8 100644 --- a/nano/node/scheduler/manual.hpp +++ b/nano/node/scheduler/manual.hpp @@ -1,7 +1,7 @@ #pragma once #include #include -#include +#include #include diff --git a/nano/node/scheduler/optimistic.cpp b/nano/node/scheduler/optimistic.cpp index 2c14251607..a11e1540e3 100644 --- a/nano/node/scheduler/optimistic.cpp +++ b/nano/node/scheduler/optimistic.cpp @@ -1,6 +1,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/nano/node/scheduler/priority.cpp b/nano/node/scheduler/priority.cpp index b37276e069..c6eb0d9961 100644 --- a/nano/node/scheduler/priority.cpp +++ b/nano/node/scheduler/priority.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/node/scheduler/priority.hpp b/nano/node/scheduler/priority.hpp index d8a7b2daf8..693200217b 100644 --- a/nano/node/scheduler/priority.hpp +++ b/nano/node/scheduler/priority.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include @@ -16,6 +15,7 @@ namespace nano class block; class container_info_component; class node; +class stats; } namespace nano::store { diff --git a/nano/node/websocket.cpp b/nano/node/websocket.cpp index 68f870a3c0..1cebbf7508 100644 --- a/nano/node/websocket.cpp +++ b/nano/node/websocket.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/qt/qt.cpp b/nano/qt/qt.cpp index 744cf095ae..d33db65ccc 100644 --- a/nano/qt/qt.cpp +++ b/nano/qt/qt.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 5d5e4190c5..32a3248159 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include diff --git a/nano/slow_test/node.cpp b/nano/slow_test/node.cpp index 06b8728ebf..73a9ebe303 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/slow_test/vote_cache.cpp b/nano/slow_test/vote_cache.cpp index 1e0b4abae8..73ecba40e9 100644 --- a/nano/slow_test/vote_cache.cpp +++ b/nano/slow_test/vote_cache.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/nano/test_common/system.cpp b/nano/test_common/system.cpp index 379d0ec7b3..914d472e53 100644 --- a/nano/test_common/system.cpp +++ b/nano/test_common/system.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/nano/test_common/testutil.cpp b/nano/test_common/testutil.cpp index 114a7813bb..c7b126f2ad 100644 --- a/nano/test_common/testutil.cpp +++ b/nano/test_common/testutil.cpp @@ -1,5 +1,6 @@ #include #include +#include #include #include #include