From ccf0724b074a6cb3dc9141036b631ded51278ce1 Mon Sep 17 00:00:00 2001 From: gr0vity Date: Mon, 25 Nov 2024 22:12:38 +0100 Subject: [PATCH] election transition active one final vote --- nano/lib/config.hpp | 2 +- nano/node/active_elections.cpp | 23 ++++++++++++++++++++++- nano/node/active_elections.hpp | 1 + nano/node/election.cpp | 6 ++++++ nano/node/transport/tcp_channel.hpp | 2 +- submodules/boost | 2 +- submodules/miniupnp | 2 +- submodules/rocksdb | 2 +- 8 files changed, 34 insertions(+), 6 deletions(-) diff --git a/nano/lib/config.hpp b/nano/lib/config.hpp index 239f5ad8ce..1d48938aaf 100644 --- a/nano/lib/config.hpp +++ b/nano/lib/config.hpp @@ -169,7 +169,7 @@ class network_constants default_rpc_port (45000), default_ipc_port (46000), default_websocket_port (47000), - aec_loop_interval_ms (300), // Update AEC ~3 times per second + aec_loop_interval_ms (100), // Update AEC ~3 times per second cleanup_period (default_cleanup_period), merge_period (std::chrono::milliseconds (250)), keepalive_period (std::chrono::seconds (15)), diff --git a/nano/node/active_elections.cpp b/nano/node/active_elections.cpp index 758752a08e..4ba024d952 100644 --- a/nano/node/active_elections.cpp +++ b/nano/node/active_elections.cpp @@ -239,8 +239,26 @@ void nano::active_elections::request_confirm (nano::unique_lock & l std::size_t const this_loop_target_l (roots.size ()); auto const elections_l{ list_active_impl (this_loop_target_l) }; + // Get pending solicitations and clear the queue + auto pending_solicitations_l = std::move (pending_solicitations); + pending_solicitations.clear (); + lock_a.unlock (); + // Process pending solicitations with limited representatives + if (!pending_solicitations_l.empty ()) + { + nano::confirmation_solicitor solicitor_new (node.network, node.config); + solicitor_new.prepare (node.rep_crawler.principal_representatives (1)); // Only use 2 reps for new elections + + for (auto const & election_l : pending_solicitations_l) + { + solicitor_new.add (*election_l); + } + solicitor_new.flush (); + } + + // Process active elections with full representative set nano::confirmation_solicitor solicitor (node.network, node.config); solicitor.prepare (node.rep_crawler.principal_representatives (std::numeric_limits::max ())); @@ -398,6 +416,10 @@ nano::election_insertion_result nano::active_elections::insert (std::shared_ptr< node.online_reps.observe (rep_a); }; result.election = nano::make_shared (node, block_a, nullptr, observe_rep_cb, election_behavior_a); + + // Queue for next solicitation round instead of immediate solicitation + pending_solicitations.push_back (result.election); + roots.get ().emplace (entry{ root, result.election, std::move (erased_callback_a) }); node.vote_router.connect (hash, result.election); @@ -431,7 +453,6 @@ nano::election_insertion_result nano::active_elections::insert (std::shared_ptr< if (result.inserted) { debug_assert (result.election); - node.vote_cache_processor.trigger (hash); node.observers.active_started.notify (hash); vacancy_updated.notify (); diff --git a/nano/node/active_elections.hpp b/nano/node/active_elections.hpp index 8b831112b9..6d344c52ae 100644 --- a/nano/node/active_elections.hpp +++ b/nano/node/active_elections.hpp @@ -158,6 +158,7 @@ class active_elections final private: /** Keeps track of number of elections by election behavior (normal, hinted, optimistic) */ nano::enum_array count_by_behavior{}; + std::vector> pending_solicitations; nano::condition_variable condition; bool stopped{ false }; diff --git a/nano/node/election.cpp b/nano/node/election.cpp index b267841265..513d0af98b 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -457,6 +457,12 @@ nano::vote_code nano::election::vote (nano::account const & rep, uint64_t timest nano::unique_lock lock{ mutex }; + // If we receive a final vote and election is passive, transition to active + if (state_m == nano::election_state::passive && nano::vote::is_final_timestamp (timestamp_a)) + { + state_change (nano::election_state::passive, nano::election_state::active); + } + auto last_vote_it (last_votes.find (rep)); if (last_vote_it != last_votes.end ()) { diff --git a/nano/node/transport/tcp_channel.hpp b/nano/node/transport/tcp_channel.hpp index 4169ffecd1..0de1698e0b 100644 --- a/nano/node/transport/tcp_channel.hpp +++ b/nano/node/transport/tcp_channel.hpp @@ -29,7 +29,7 @@ class tcp_channel_queue final bool full (traffic_type) const; constexpr static size_t max_size = 8; - constexpr static size_t full_size = 4 * max_size; + constexpr static size_t full_size = 4 * max_size; private: void seek_next (); diff --git a/submodules/boost b/submodules/boost index 65c1319bb9..b6928ae5c9 160000 --- a/submodules/boost +++ b/submodules/boost @@ -1 +1 @@ -Subproject commit 65c1319bb92fe7a9a4abd588eff5818d9c2bccf9 +Subproject commit b6928ae5c92e21a04bbe17a558e6e066dbe632f6 diff --git a/submodules/miniupnp b/submodules/miniupnp index 7f189988a0..2df8120326 160000 --- a/submodules/miniupnp +++ b/submodules/miniupnp @@ -1 +1 @@ -Subproject commit 7f189988a0decca0ab7da89000051ab91751f70d +Subproject commit 2df8120326ed4246e049a7a6de707539604cd514 diff --git a/submodules/rocksdb b/submodules/rocksdb index d9787264a8..41214f0b4e 160000 --- a/submodules/rocksdb +++ b/submodules/rocksdb @@ -1 +1 @@ -Subproject commit d9787264a8eb0528966ded06499dff46a4f8739c +Subproject commit 41214f0b4e05aa8123583968df039c0d35228a4f