From 90c649ca845f5d66d49b822c3dcec275395a6cd4 Mon Sep 17 00:00:00 2001 From: Russel Waters Date: Mon, 6 May 2019 13:35:00 -0400 Subject: [PATCH] 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 --- nano/node/wallet.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) 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 (); } }