Remove vote cache & generate new vote if election winner is changed (#2585)

This commit is contained in:
Sergey Kroshnin 2020-02-24 19:34:07 +03:00 committed by GitHub
commit e4915b13e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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))
{