Skip to content

Commit

Permalink
Ignore duplicate hashes when processing votes
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Mar 21, 2024
1 parent 933efd2 commit 5617517
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,18 +441,21 @@ nano::election_insertion_result nano::active_transactions::insert (std::shared_p
std::unordered_map<nano::block_hash, nano::vote_code> nano::active_transactions::vote (std::shared_ptr<nano::vote> const & vote)
{
std::unordered_map<nano::block_hash, nano::vote_code> results;

std::vector<std::pair<std::shared_ptr<nano::election>, nano::block_hash>> process;
std::unordered_map<nano::block_hash, std::shared_ptr<nano::election>> process;
std::vector<nano::block_hash> inactive; // Hashes that should be added to inactive vote cache
{
nano::unique_lock<nano::mutex> lock{ mutex };
for (auto const & hash : vote->hashes)
{
debug_assert (results.find (hash) == results.end ());
// Ignore duplicate hashes (should not happen with a well-behaved voting node)
if (results.find (hash) != results.end ())
{
continue;
}

if (auto existing = blocks.find (hash); existing != blocks.end ())
{
process.emplace_back (existing->second, hash);
process[hash] = existing->second;
}
else if (!recently_confirmed.exists (hash))
{
Expand All @@ -476,7 +479,7 @@ std::unordered_map<nano::block_hash, nano::vote_code> nano::active_transactions:
{
bool processed = false;

for (auto const & [election, block_hash] : process)
for (auto const & [block_hash, election] : process)
{
auto const vote_result = election->vote (vote->account, vote->timestamp (), block_hash);
results[block_hash] = vote_result;
Expand Down

0 comments on commit 5617517

Please sign in to comment.