Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Erase inactive votes cache after election stop / finish #2448

Merged
merged 2 commits into from
Jan 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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<nano::gap_cache::tag_hash> ().find (hash_a));
if (existing != inactive_votes_cache.get<nano::gap_cache::tag_hash> ().end ())
{
inactive_votes_cache.get<nano::gap_cache::tag_hash> ().erase (existing);
}
guilhermelawless marked this conversation as resolved.
Show resolved Hide resolved
}

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