diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 2322d1e46..f6aee9d06 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -94,7 +94,7 @@ void Client::init(p2p::Host* _extNet, std::string const& _dbPath, WithExisting _ m_lastGetWork = std::chrono::system_clock::now() - chrono::seconds(30); m_tqReady = m_tq.onReady([=](){ this->onTransactionQueueReady(); }); // TODO: should read m_tq->onReady(thisThread, syncTransactionQueue); - m_tqReplaced = m_tq.onReplaced([=](h256 const&){ this->resetState(); }); + m_tqReplaced = m_tq.onReplaced([=](h256 const&){ m_needStateReset = true; }); m_bqReady = m_bq.onReady([=](){ this->onBlockQueueReady(); }); // TODO: should read m_bq->onReady(thisThread, syncBlockQueue); m_bq.setOnBad([=](Exception& ex){ this->onBadBlock(ex); }); bc().setOnBad([=](Exception& ex){ this->onBadBlock(ex); }); @@ -753,6 +753,12 @@ void Client::doWork() if (m_syncBlockQueue.compare_exchange_strong(t, false)) syncBlockQueue(); + if (m_needStateReset) + { + resetState(); + m_needStateReset = false; + } + t = true; if (m_syncTransactionQueue.compare_exchange_strong(t, false) && !m_remoteWorking && !isSyncing()) syncTransactionQueue(); diff --git a/libethereum/Client.h b/libethereum/Client.h index 973270877..8d508b552 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -303,6 +303,7 @@ protected: BlockInfo m_miningInfo; ///< The header we're attempting to mine on (derived from m_postMine). bool remoteActive() const; ///< Is there an active and valid remote worker? bool m_remoteWorking = false; ///< Has the remote worker recently been reset? + std::atomic m_needStateReset = { false }; ///< Need reset working state to premin on next sync std::chrono::system_clock::time_point m_lastGetWork; ///< Is there an active and valid remote worker? std::weak_ptr m_host; ///< Our Ethereum Host. Don't do anything if we can't lock.