diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index aa816fa9eb..c7411a4c63 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