diff --git a/nano/node/wallet.cpp b/nano/node/wallet.cpp index 84b0b338..b89b23e8 100644 --- a/nano/node/wallet.cpp +++ b/nano/node/wallet.cpp @@ -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 block (builder.build ()); - node.network.flood_block (block); - node.active.update_difficulty (*block.get ()); + std::shared_ptr block (builder.build (ec)); + if (!ec) + { + { + std::lock_guard 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 (); } }