From e61fb01b97d752829c15643787a58b917fd9a266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Wo=CC=81jcik?= <3044353+pwojcikdev@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:58:45 +0100 Subject: [PATCH] Move republish vote logic --- nano/node/active_transactions.cpp | 23 +++-------------------- nano/node/node.cpp | 15 +++++++++++++++ 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index b266a437a9..a8286d01a6 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -480,27 +480,10 @@ std::unordered_map nano::active_transactions: } } - if (!process.empty ()) + for (auto const & [block_hash, election] : process) { - bool processed = false; - - for (auto const & [block_hash, election] : process) - { - auto const vote_result = election->vote (vote->account, vote->timestamp (), block_hash, source); - results[block_hash] = vote_result; - - processed |= (vote_result == nano::vote_code::vote); - } - - // Republish vote if it is new and the node does not host a principal representative (or close to) - if (processed) - { - auto const reps (node.wallets.reps ()); - if (!reps.have_half_rep () && !reps.exists (vote->account)) - { - node.network.flood_vote (vote, 0.5f); - } - } + auto const vote_result = election->vote (vote->account, vote->timestamp (), block_hash, source); + results[block_hash] = vote_result; } // All hashes should have their result set diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 3c1cf7b3a6..479c0df1f9 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -220,6 +220,21 @@ nano::node::node (std::shared_ptr io_ctx_a, std::filesy vote_cache.observe (vote, source, results); }); + // Republish vote if it is new and the node does not host a principal representative (or close to) + active.vote_processed.add ([this] (std::shared_ptr const & vote, nano::vote_source source, std::unordered_map const & results) { + bool processed = std::any_of (results.begin (), results.end (), [] (auto const & result) { + return result.second == nano::vote_code::vote; + }); + if (processed) + { + auto const reps = wallets.reps (); + if (!reps.have_half_rep () && !reps.exists (vote->account)) + { + network.flood_vote (vote, 0.5f); + } + } + }); + if (!init_error ()) { // Notify election schedulers when AEC frees election slot