Skip to content

Commit

Permalink
Move vote republishing out of active_transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 21, 2024
1 parent b7bb18b commit d05d98e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
23 changes: 3 additions & 20 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,27 +480,10 @@ std::unordered_map<nano::block_hash, nano::vote_code> 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
Expand Down
15 changes: 15 additions & 0 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,21 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> 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<nano::vote> const & vote, nano::vote_source source, std::unordered_map<nano::block_hash, nano::vote_code> 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
Expand Down

0 comments on commit d05d98e

Please sign in to comment.