Erase inactive votes cache after election stop / finish (#2448)

* Erase inactive votes cache after election stop / finish and for forks elections
* Use tags for boost multiindex
This commit is contained in:
Sergey Kroshnin 2020-01-03 19:42:43 +03:00 committed by GitHub
commit fc5c764736
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 0 deletions

View file

@ -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);
}
}
size_t nano::active_transactions::dropped_elections_cache_size ()
{
nano::lock_guard<std::mutex> guard (mutex);

View file

@ -134,6 +134,7 @@ public:
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;

View file

@ -287,6 +287,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)
{

View file

@ -554,6 +554,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 ())