updating work_watcher::run (#1960)

* check for error codes before locking active, updating the existing elections, and then flooding blocks and updating the difficulty in roots

* ensure block is found before replacing
This commit is contained in:
Russel Waters 2019-05-06 13:35:00 -04:00 committed by GitHub
commit 90c649ca84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1449,11 +1449,30 @@ void nano::work_watcher::run ()
{
lock.unlock ();
nano::state_block_builder builder;
std::error_code ec;
builder.from (*i.second);
builder.work (node.work_generate_blocking (i.second->root (), node.active.active_difficulty ()));
std::shared_ptr<state_block> block (builder.build ());
node.network.flood_block (block);
node.active.update_difficulty (*block.get ());
std::shared_ptr<state_block> block (builder.build (ec));
if (!ec)
{
{
std::lock_guard<std::mutex> active_lock (node.active.mutex);
auto existing (node.active.roots.find (i.second->qualified_root ()));
if (existing != node.active.roots.end ())
{
auto election (existing->election);
if (election->status.winner->hash () == i.second->hash ())
{
election->status.winner = block;
}
auto current (election->blocks.find (block->hash ()));
assert (current != election->blocks.end ());
current->second = block;
}
}
node.network.flood_block (block);
node.active.update_difficulty (*block.get ());
}
lock.lock ();
}
}