From dba4578fe826765a778df0439ae6970b5dcfa790 Mon Sep 17 00:00:00 2001 From: gr0vity-dev Date: Thu, 24 Oct 2024 20:19:16 +0200 Subject: [PATCH 1/2] Publish votes to all PRs and a subset of non PRs This avoids potential duplicate votes to PRs and better confirmation times for non PRs --- nano/node/network.cpp | 9 +++++++++ nano/node/network.hpp | 1 + nano/node/vote_generator.cpp | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/nano/node/network.cpp b/nano/node/network.cpp index 6a74df915d..81cd77afe8 100644 --- a/nano/node/network.cpp +++ b/nano/node/network.cpp @@ -281,6 +281,15 @@ void nano::network::flood_vote (std::shared_ptr const & vote, float } } +void nano::network::flood_vote_non_pr (std::shared_ptr const & vote, float scale, bool rebroadcasted) +{ + nano::confirm_ack message{ node.network_params.network, vote, rebroadcasted }; + for (auto & i : list_non_pr (fanout (scale))) + { + i->send (message, nullptr); + } +} + void nano::network::flood_vote_pr (std::shared_ptr const & vote, bool rebroadcasted) { nano::confirm_ack message{ node.network_params.network, vote, rebroadcasted }; diff --git a/nano/node/network.hpp b/nano/node/network.hpp index 5aa6ec8772..0ab498ed2b 100644 --- a/nano/node/network.hpp +++ b/nano/node/network.hpp @@ -95,6 +95,7 @@ class network final void flood_keepalive_self (float const scale_a = 0.5f); void flood_vote (std::shared_ptr const &, float scale, bool rebroadcasted = false); void flood_vote_pr (std::shared_ptr const &, bool rebroadcasted = false); + void flood_vote_non_pr (std::shared_ptr const &, float scale, bool rebroadcasted = false); // Flood block to all PRs and a random selection of non-PRs void flood_block_initial (std::shared_ptr const &); // Flood block to a random selection of peers diff --git a/nano/node/vote_generator.cpp b/nano/node/vote_generator.cpp index 68792d690d..e29c88cc97 100644 --- a/nano/node/vote_generator.cpp +++ b/nano/node/vote_generator.cpp @@ -277,7 +277,7 @@ void nano::vote_generator::vote (std::vector const & hashes_a, void nano::vote_generator::broadcast_action (std::shared_ptr const & vote_a) const { network.flood_vote_pr (vote_a); - network.flood_vote (vote_a, 2.0f); + network.flood_vote_non_pr (vote_a, 2.0f); vote_processor.vote (vote_a, inproc_channel); } From 5bc04e842fb116ec17018ed95c26905d91ab3dbd Mon Sep 17 00:00:00 2001 From: gr0vity-dev Date: Thu, 24 Oct 2024 20:22:24 +0200 Subject: [PATCH 2/2] small optimisation for list_non_pr --- nano/node/network.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nano/node/network.cpp b/nano/node/network.cpp index 81cd77afe8..269edcd87f 100644 --- a/nano/node/network.cpp +++ b/nano/node/network.cpp @@ -386,11 +386,13 @@ std::deque> nano::network::list_non_pr { std::deque> result; tcp_channels.list (result); + + auto partition_point = std::partition (result.begin (), result.end (), + [this] (std::shared_ptr const & channel) { + return !node.rep_crawler.is_pr (channel); + }); + result.resize (std::distance (result.begin (), partition_point)); nano::random_pool_shuffle (result.begin (), result.end ()); - result.erase (std::remove_if (result.begin (), result.end (), [this] (std::shared_ptr const & channel) { - return node.rep_crawler.is_pr (channel); - }), - result.end ()); if (result.size () > count_a) { result.resize (count_a, nullptr);