From e4915b13e88c875d64d50a587d8575354fa33f83 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Mon, 24 Feb 2020 19:34:07 +0300 Subject: [PATCH] Remove vote cache & generate new vote if election winner is changed (#2585) --- nano/node/election.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 775a21dc..5e7b9c33 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -108,19 +108,22 @@ void nano::election::confirm_if_quorum () debug_assert (!tally_l.empty ()); auto winner (tally_l.begin ()); auto block_l (winner->second); + auto winner_hash_l (block_l->hash ()); status.tally = winner->first; + auto status_winner_hash_l (status.winner->hash ()); nano::uint128_t sum (0); for (auto & i : tally_l) { sum += i.first; } - if (sum >= node.config.online_weight_minimum.number () && block_l->hash () != status.winner->hash ()) + if (sum >= node.config.online_weight_minimum.number () && winner_hash_l != status_winner_hash_l) { - auto node_l (node.shared ()); - node_l->block_processor.force (block_l); + node.votes_cache.remove (status_winner_hash_l); + node.block_processor.generator.add (winner_hash_l); + node.block_processor.force (block_l); status.winner = block_l; update_dependent (); - node_l->active.adjust_difficulty (block_l->hash ()); + node.active.adjust_difficulty (winner_hash_l); } if (have_quorum (tally_l, sum)) {