From 56175171301e2d4e5031e932618acc7f3a41e29b 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 12:17:23 +0100 Subject: [PATCH] Ignore duplicate hashes when processing votes --- nano/node/active_transactions.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index b5955175f7..9603721af3 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -441,18 +441,21 @@ nano::election_insertion_result nano::active_transactions::insert (std::shared_p std::unordered_map nano::active_transactions::vote (std::shared_ptr const & vote) { std::unordered_map results; - - std::vector, nano::block_hash>> process; + std::unordered_map> process; std::vector inactive; // Hashes that should be added to inactive vote cache { nano::unique_lock 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)) { @@ -476,7 +479,7 @@ std::unordered_map 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;