From ce205f382cb1f2964f1edcbbb08e43e93bd200c9 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Tue, 19 May 2015 23:22:44 +0200 Subject: [PATCH] Remote mining fixes. --- alethzero/MainWin.cpp | 2 +- ethminer/MinerAux.h | 2 ++ libethereum/BlockQueue.h | 2 +- libethereum/Client.cpp | 8 +++++++- libethereum/Client.h | 3 +++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 076e9d547..4f236b3e8 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -1166,7 +1166,7 @@ void Main::on_turboMining_triggered() void Main::refreshBlockChain() { - if (!ui->blocks->isVisible() || !isVisible()) + if (!ui->blocks->isVisible() && isVisible()) return; DEV_TIMED_FUNCTION_ABOVE(500); diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index 53a5fa7e4..d99e36976 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -419,6 +419,8 @@ private: Json::Value v = rpc.eth_getWork(); h256 hh(v[0].asString()); h256 newSeedHash(v[1].asString()); + if (current.seedHash != newSeedHash) + cnote << "Grabbing DAG for" << newSeedHash; if (!(dag = EthashAux::full(newSeedHash, true, [&](unsigned _pc){ cout << "\rCreating DAG. " << _pc << "% done..." << flush; return 0; }))) BOOST_THROW_EXCEPTION(DAGCreationFailure()); if (hh != current.headerHash) diff --git a/libethereum/BlockQueue.h b/libethereum/BlockQueue.h index c865bac32..d0437739d 100644 --- a/libethereum/BlockQueue.h +++ b/libethereum/BlockQueue.h @@ -94,7 +94,7 @@ public: void retryAllUnknown(); /// Get information on the items queued. - std::pair items() const { ReadGuard l(m_lock); return std::make_pair(m_verified.size(), m_unknown.size()); } + std::pair items() const { ReadGuard l(m_lock); return std::make_pair(m_readySet.size(), m_unknownSet.size()); } /// Clear everything. void clear() { WriteGuard l(m_lock); DEV_INVARIANT_CHECK; Guard l2(m_verification); m_readySet.clear(); m_drainingSet.clear(); m_verified.clear(); m_unverified.clear(); m_unknownSet.clear(); m_unknown.clear(); m_future.clear(); } diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index e39126713..0fd27520d 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -455,8 +455,13 @@ 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. + bool oldShould = shouldServeWork(); m_lastGetWork = chrono::system_clock::now(); m_remoteWorking = true; + + // if this request has made us bother to serve work, prep it now. + if (!oldShould && shouldServeWork()) + onPostStateChanged(); return ProofOfWork::package(m_miningInfo); } @@ -612,7 +617,8 @@ bool Client::remoteActive() const void Client::onPostStateChanged() { cnote << "Post state changed"; - if (isMining() || remoteActive()) + + if (m_bq.items().first == 0 && (isMining() || remoteActive())) { cnote << "Restarting mining..."; DEV_WRITE_GUARDED(x_working) diff --git a/libethereum/Client.h b/libethereum/Client.h index 4fa6da8b1..c77cb6034 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -274,6 +274,9 @@ private: /// Ticks various system-level objects. void tick(); + /// @returns true only if it's worth bothering to prep the mining block. + bool shouldServeWork() const { return m_bq.items().first == 0 && (isMining() || remoteActive()); } + VersionChecker m_vc; ///< Dummy object to check & update the protocol version. CanonBlockChain m_bc; ///< Maintains block database. BlockQueue m_bq; ///< Maintains a list of incoming blocks not yet on the blockchain (to be imported).