Active_transactions updates blocks when updating difficulty. (#2518)
* 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. * Using election attached to iterator. * Updating election fields inside election class. * Removing redundant code section.
This commit is contained in:
commit
ec177a2037
4 changed files with 8 additions and 33 deletions
|
|
@ -547,21 +547,6 @@ TEST (active_transactions, update_difficulty)
|
||||||
send2 = std::shared_ptr<nano::state_block> (builder1.from (*send2).work (*work2).build (ec));
|
send2 = std::shared_ptr<nano::state_block> (builder1.from (*send2).work (*work2).build (ec));
|
||||||
ASSERT_FALSE (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 (send1);
|
||||||
node1.process_active (send2);
|
node1.process_active (send2);
|
||||||
node1.block_processor.flush ();
|
node1.block_processor.flush ();
|
||||||
|
|
|
||||||
|
|
@ -685,6 +685,7 @@ void nano::active_transactions::update_difficulty (std::shared_ptr<nano::block>
|
||||||
roots.get<tag_root> ().modify (existing_election, [difficulty](nano::conflict_info & info_a) {
|
roots.get<tag_root> ().modify (existing_election, [difficulty](nano::conflict_info & info_a) {
|
||||||
info_a.difficulty = difficulty;
|
info_a.difficulty = difficulty;
|
||||||
});
|
});
|
||||||
|
existing_election->election->publish (block_a);
|
||||||
adjust_difficulty (block_a->hash ());
|
adjust_difficulty (block_a->hash ());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -210,7 +210,8 @@ bool nano::election::publish (std::shared_ptr<nano::block> block_a)
|
||||||
}
|
}
|
||||||
if (!result)
|
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));
|
blocks.emplace (std::make_pair (block_a->hash (), block_a));
|
||||||
insert_inactive_votes_cache (block_a->hash ());
|
insert_inactive_votes_cache (block_a->hash ());
|
||||||
|
|
@ -220,6 +221,11 @@ bool nano::election::publish (std::shared_ptr<nano::block> block_a)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
result = true;
|
result = true;
|
||||||
|
existing->second = block_a;
|
||||||
|
if (status.winner->hash () == block_a->hash ())
|
||||||
|
{
|
||||||
|
status.winner = block_a;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -1455,23 +1455,6 @@ void nano::work_watcher::watching (nano::qualified_root const & root_a, std::sha
|
||||||
|
|
||||||
if (!ec)
|
if (!ec)
|
||||||
{
|
{
|
||||||
{
|
|
||||||
auto hash (block_a->hash ());
|
|
||||||
nano::lock_guard<std::mutex> active_guard (watcher_l->node.active.mutex);
|
|
||||||
auto existing (watcher_l->node.active.roots.find (root_a));
|
|
||||||
if (existing != watcher_l->node.active.roots.end ())
|
|
||||||
{
|
|
||||||
auto election (existing->election);
|
|
||||||
if (election->status.winner->hash () == hash)
|
|
||||||
{
|
|
||||||
election->status.winner = block;
|
|
||||||
}
|
|
||||||
auto current (election->blocks.find (hash));
|
|
||||||
assert (current != election->blocks.end ());
|
|
||||||
current->second = block;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
watcher_l->node.network.flood_block (block, false);
|
|
||||||
watcher_l->node.active.update_difficulty (block);
|
watcher_l->node.active.update_difficulty (block);
|
||||||
watcher_l->update (root_a, block);
|
watcher_l->update (root_a, block);
|
||||||
updated_l = true;
|
updated_l = true;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue