diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 300b4b28be..84ccb36608 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -1126,6 +1126,15 @@ nano::gap_information nano::active_transactions::find_inactive_votes_cache (nano } } +void nano::active_transactions::erase_inactive_votes_cache (nano::block_hash const & hash_a) +{ + auto existing (inactive_votes_cache.get ().find (hash_a)); + if (existing != inactive_votes_cache.get ().end ()) + { + inactive_votes_cache.get ().erase (existing); + } +} + size_t nano::active_transactions::dropped_elections_cache_size () { nano::lock_guard guard (mutex); diff --git a/nano/node/active_transactions.hpp b/nano/node/active_transactions.hpp index 41300293de..f5253ba917 100644 --- a/nano/node/active_transactions.hpp +++ b/nano/node/active_transactions.hpp @@ -134,6 +134,7 @@ class active_transactions final void add_confirmed (nano::election_status const &, nano::qualified_root const &); void add_inactive_votes_cache (nano::block_hash const &, nano::account const &); nano::gap_information find_inactive_votes_cache (nano::block_hash const &); + void erase_inactive_votes_cache (nano::block_hash const &); nano::node & node; std::mutex mutex; std::chrono::seconds const long_election_threshold; diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 9944f22665..fc5499d158 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -298,6 +298,7 @@ void nano::election::clear_blocks () (void)erased; // clear_blocks () can be called in active_transactions::publish () before blocks insertion if election was confirmed assert (erased == 1 || confirmed); + node.active.erase_inactive_votes_cache (hash); // Notify observers about dropped elections & blocks lost confirmed elections if (stopped || hash != winner_hash) { diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 3aa11b83bd..e4825b499c 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -557,6 +557,12 @@ void nano::node::process_fork (nano::transaction const & transaction_a, std::sha std::shared_ptr ledger_block (ledger.forked_block (transaction_a, *block_a)); if (ledger_block && !block_confirmed_or_being_confirmed (transaction_a, ledger_block->hash ())) { + // Clear inactive votes cache for forks + { + nano::lock_guard lock (active.mutex); + active.erase_inactive_votes_cache (ledger_block->hash ()); + active.erase_inactive_votes_cache (block_a->hash ()); + } std::weak_ptr this_w (shared_from_this ()); if (!active.start (ledger_block, false, [this_w, root](std::shared_ptr) { if (auto this_l = this_w.lock ())