Modifying update_difficulty test so it doesn't directly manipulate the election and instead relies on active_transactions updating itself on receipt of a higher difficulty block.
This commit is contained in:
parent
89a19deb16
commit
34d5152cf6
2 changed files with 6 additions and 16 deletions
|
@ -548,21 +548,6 @@ TEST (active_transactions, update_difficulty)
|
|||
send2 = std::shared_ptr<nano::state_block> (builder1.from (*send2).work (*work2).build (ec));
|
||||
ASSERT_FALSE (ec);
|
||||
|
||||
auto modify_election = [&node1](auto block) {
|
||||
auto hash (block->hash ());
|
||||
nano::lock_guard<std::mutex> active_guard (node1.active.mutex);
|
||||
auto existing (node1.active.roots.find (block->qualified_root ()));
|
||||
ASSERT_NE (existing, node1.active.roots.end ());
|
||||
auto election (existing->election);
|
||||
ASSERT_EQ (election->status.winner->hash (), hash);
|
||||
election->status.winner = block;
|
||||
auto current (election->blocks.find (hash));
|
||||
assert (current != election->blocks.end ());
|
||||
current->second = block;
|
||||
};
|
||||
|
||||
modify_election (send1);
|
||||
modify_election (send2);
|
||||
node1.process_active (send1);
|
||||
node1.process_active (send2);
|
||||
node1.block_processor.flush ();
|
||||
|
|
|
@ -632,8 +632,13 @@ void nano::active_transactions::update_difficulty (std::shared_ptr<nano::block>
|
|||
{
|
||||
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<tag_root> ().modify (existing_election, [difficulty](nano::conflict_info & info_a) {
|
||||
roots.get<tag_root> ().modify (existing_election, [election = existing_election->election, &block_a, difficulty](nano::conflict_info & info_a) {
|
||||
info_a.difficulty = difficulty;
|
||||
election->blocks[block_a->hash ()] = block_a;
|
||||
if (election->status.winner->hash () == block_a->hash ())
|
||||
{
|
||||
election->status.winner = block_a;
|
||||
}
|
||||
});
|
||||
adjust_difficulty (block_a->hash ());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue