diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index d9da6fdb..c32dc0db 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -632,14 +632,10 @@ void nano::active_transactions::update_difficulty (std::shared_ptr { node.logger.try_log (boost::str (boost::format ("Block %1% was updated from difficulty %2% to %3%") % block_a->hash ().to_string () % nano::to_string_hex (existing_election->difficulty) % nano::to_string_hex (difficulty))); } - roots.get ().modify (existing_election, [&block_a, difficulty](nano::conflict_info & info_a) { + roots.get ().modify (existing_election, [difficulty](nano::conflict_info & info_a) { info_a.difficulty = difficulty; - info_a.election->blocks[block_a->hash ()] = block_a; - if (info_a.election->status.winner->hash () == block_a->hash ()) - { - info_a.election->status.winner = block_a; - } }); + existing_election->election->publish (block_a); adjust_difficulty (block_a->hash ()); } } diff --git a/nano/node/election.cpp b/nano/node/election.cpp index 028b579e..7794bbf4 100644 --- a/nano/node/election.cpp +++ b/nano/node/election.cpp @@ -211,7 +211,8 @@ bool nano::election::publish (std::shared_ptr block_a) } if (!result) { - if (blocks.find (block_a->hash ()) == blocks.end ()) + auto existing = blocks.find (block_a->hash ()); + if (existing == blocks.end ()) { blocks.emplace (std::make_pair (block_a->hash (), block_a)); insert_inactive_votes_cache (block_a->hash ()); @@ -221,6 +222,11 @@ bool nano::election::publish (std::shared_ptr block_a) else { result = true; + existing->second = block_a; + if (status.winner->hash () == block_a->hash ()) + { + status.winner = block_a; + } } } return result;