From b963bc2a11e0aff81b944357959304bf9764cc8d Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Sat, 21 Mar 2020 08:53:01 +0300 Subject: [PATCH] Modify inactive cache conditions to prevent multiple insertions for confirmed entries --- nano/node/active_transactions.cpp | 51 ++++++++++++++++--------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index 993c04e3a7..e17b0830b9 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -914,33 +914,36 @@ void nano::active_transactions::add_inactive_votes_cache (nano::block_hash const { auto & inactive_by_hash (inactive_votes_cache.get ()); auto existing (inactive_by_hash.find (hash_a)); - if (existing != inactive_by_hash.end () && (!existing->confirmed || !existing->bootstrap_started)) + if (existing != inactive_by_hash.end ()) { - auto is_new (false); - inactive_by_hash.modify (existing, [representative_a, &is_new](nano::inactive_cache_information & info) { - auto it = std::find (info.voters.begin (), info.voters.end (), representative_a); - is_new = (it == info.voters.end ()); - if (is_new) - { - info.arrival = std::chrono::steady_clock::now (); - info.voters.push_back (representative_a); - } - }); - - if (is_new) + if (!existing->confirmed || !existing->bootstrap_started) { - bool confirmed (false); - if (inactive_votes_bootstrap_check (existing->voters, hash_a, confirmed) && !existing->bootstrap_started) - { - inactive_by_hash.modify (existing, [](nano::inactive_cache_information & info) { - info.bootstrap_started = true; - }); - } - if (confirmed && !existing->confirmed) + auto is_new (false); + inactive_by_hash.modify (existing, [representative_a, &is_new](nano::inactive_cache_information & info) { + auto it = std::find (info.voters.begin (), info.voters.end (), representative_a); + is_new = (it == info.voters.end ()); + if (is_new) + { + info.arrival = std::chrono::steady_clock::now (); + info.voters.push_back (representative_a); + } + }); + + if (is_new) { - inactive_by_hash.modify (existing, [](nano::inactive_cache_information & info) { - info.confirmed = true; - }); + bool confirmed (false); + if (inactive_votes_bootstrap_check (existing->voters, hash_a, confirmed) && !existing->bootstrap_started) + { + inactive_by_hash.modify (existing, [](nano::inactive_cache_information & info) { + info.bootstrap_started = true; + }); + } + if (confirmed && !existing->confirmed) + { + inactive_by_hash.modify (existing, [](nano::inactive_cache_information & info) { + info.confirmed = true; + }); + } } } }