Skip to content

Commit

Permalink
Erase inactive votes cache after election stop / finish
Browse files Browse the repository at this point in the history
... and for forks elections
  • Loading branch information
SergiySW committed Dec 20, 2019
1 parent 39fbc20 commit 570cdc5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<1> ().find (hash_a));
if (existing != inactive_votes_cache.get<1> ().end ())
{
inactive_votes_cache.get<1> ().erase (existing);
}
}

size_t nano::active_transactions::dropped_elections_cache_size ()
{
nano::lock_guard<std::mutex> guard (mutex);
Expand Down
1 change: 1 addition & 0 deletions nano/node/active_transactions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions nano/node/election.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
6 changes: 6 additions & 0 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,12 @@ void nano::node::process_fork (nano::transaction const & transaction_a, std::sha
std::shared_ptr<nano::block> 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<std::mutex> lock (active.mutex);
active.erase_inactive_votes_cache (ledger_block->hash ());
active.erase_inactive_votes_cache (block_a->hash ());
}
std::weak_ptr<nano::node> this_w (shared_from_this ());
if (!active.start (ledger_block, false, [this_w, root](std::shared_ptr<nano::block>) {
if (auto this_l = this_w.lock ())
Expand Down

0 comments on commit 570cdc5

Please sign in to comment.