From 66a4752cf2e127b93b0cdb2c1ec52288edb4c55a Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Mon, 20 Apr 2015 01:09:13 +0200 Subject: [PATCH] Don't prep mining if no need. --- libethereum/Client.cpp | 12 +++++++++--- libethereum/Client.h | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index d84acf42f..7ab4a99f4 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -408,6 +408,7 @@ ProofOfWork::WorkPackage Client::getWork() { // lock the work so a later submission isn't invalidated by processing a transaction elsewhere. // this will be reset as soon as a new block arrives, allowing more transactions to be processed. + m_lastGetWork = chrono::system_clock::now(); m_remoteWorking = true; return ProofOfWork::package(m_miningInfo); } @@ -527,18 +528,23 @@ void Client::onChainChanged(ImportRoute const& _ir) noteChanged(changeds); } +bool Client::remoteActive() const +{ + return chrono::system_clock::now() - m_lastGetWork < chrono::seconds(30); +} + void Client::onPostStateChanged() { cnote << "Post state changed: Restarting mining..."; -// if (isMining()) -// { + if (isMining() || remoteActive()) + { { WriteGuard l(x_postMine); m_postMine.commitToMine(m_bc); m_miningInfo = m_postMine.info(); } m_farm.setWork(m_miningInfo); -// } + } m_remoteWorking = false; } diff --git a/libethereum/Client.h b/libethereum/Client.h index 96afe0030..b1cfaf4ac 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -287,7 +287,9 @@ private: mutable SharedMutex x_postMine; ///< Lock on the OverlayDB and other attributes of m_postMine. State m_postMine; ///< The state of the client which we're mining (i.e. it'll have all the rewards added). BlockInfo m_miningInfo; ///< The header we're attempting to mine on (derived from m_postMine). - bool m_remoteWorking = false; ///< Is there an acive and valid remote worker? + bool remoteActive() const; ///< Is there an active and valid remote worker? + bool m_remoteWorking = false; ///< Has the remote worker recently been reset? + std::chrono::system_clock::time_point m_lastGetWork = std::chrono::system_clock::time_point::min(); ///< 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.