From 1718d6c6486ca5ea9f346dd4eac0e5e42559fcd0 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Mon, 20 Jul 2015 14:51:40 +0200 Subject: [PATCH 1/3] ensurePrecomputed should respect --no-precompute --- libethcore/Ethash.cpp | 4 +++- libethcore/Ethash.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index f1149966a..538e56cdf 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -212,6 +212,8 @@ std::string Ethash::name() return "Ethash"; } +bool Ethash::s_precompute = false; + unsigned Ethash::revision() { return ETHASH_REVISION; @@ -219,7 +221,7 @@ unsigned Ethash::revision() void Ethash::ensurePrecomputed(unsigned _number) { - if (_number % ETHASH_EPOCH_LENGTH > ETHASH_EPOCH_LENGTH * 9 / 10) + if (s_precompute && _number % ETHASH_EPOCH_LENGTH > ETHASH_EPOCH_LENGTH * 9 / 10) // 90% of the way to the new epoch EthashAux::computeFull(EthashAux::seedHash(_number + ETHASH_EPOCH_LENGTH), true); } diff --git a/libethcore/Ethash.h b/libethcore/Ethash.h index 0ea80f5e1..de200b2bf 100644 --- a/libethcore/Ethash.h +++ b/libethcore/Ethash.h @@ -49,12 +49,14 @@ class EthashCLHook; class Ethash { public: + static bool s_precompute; static std::string name(); static unsigned revision(); static SealEngineFace* createSealEngine(); using Nonce = h64; + static void setPrecompute(bool _shouldPrecompute) { s_precompute = _shouldPrecompute; } static void manuallySubmitWork(SealEngineFace* _engine, h256 const& _mixHash, Nonce _nonce); static bool isWorking(SealEngineFace* _engine); static WorkingProgress workingProgress(SealEngineFace* _engine); From a7009507653f0f06ff3fdce77effd8b0bb79d8f0 Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 21 Jul 2015 12:58:33 +0200 Subject: [PATCH 2/3] Switch to using the Sealers API for precompute --- eth/main.cpp | 1 + ethminer/MinerAux.h | 1 + libethcore/Ethash.cpp | 4 +--- libethcore/Ethash.h | 2 -- libethcore/EthashSealEngine.cpp | 3 ++- libethereum/Client.cpp | 7 +++++++ libethereum/Client.h | 2 ++ 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/eth/main.cpp b/eth/main.cpp index 6128f30b6..45902c96c 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -1700,6 +1700,7 @@ int main(int argc, char** argv) c->setGasPricer(gasPricer); c->setForceMining(forceMining); // TODO: expose sealant interface. + c->setShouldPrecomputeDAG(m.shouldPrecompute()); c->setTurboMining(m.minerType() == MinerCLI::MinerType::GPU); c->setAddress(beneficiary); c->setNetworkId(networkId); diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index c72f5a045..3d4457483 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -380,6 +380,7 @@ public: }; MinerType minerType() const { return m_minerType; } + bool shouldPrecompute() const { return m_precompute; } private: void doInitDAG(unsigned _n) diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index 538e56cdf..f1149966a 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -212,8 +212,6 @@ std::string Ethash::name() return "Ethash"; } -bool Ethash::s_precompute = false; - unsigned Ethash::revision() { return ETHASH_REVISION; @@ -221,7 +219,7 @@ unsigned Ethash::revision() void Ethash::ensurePrecomputed(unsigned _number) { - if (s_precompute && _number % ETHASH_EPOCH_LENGTH > ETHASH_EPOCH_LENGTH * 9 / 10) + if (_number % ETHASH_EPOCH_LENGTH > ETHASH_EPOCH_LENGTH * 9 / 10) // 90% of the way to the new epoch EthashAux::computeFull(EthashAux::seedHash(_number + ETHASH_EPOCH_LENGTH), true); } diff --git a/libethcore/Ethash.h b/libethcore/Ethash.h index de200b2bf..0ea80f5e1 100644 --- a/libethcore/Ethash.h +++ b/libethcore/Ethash.h @@ -49,14 +49,12 @@ class EthashCLHook; class Ethash { public: - static bool s_precompute; static std::string name(); static unsigned revision(); static SealEngineFace* createSealEngine(); using Nonce = h64; - static void setPrecompute(bool _shouldPrecompute) { s_precompute = _shouldPrecompute; } static void manuallySubmitWork(SealEngineFace* _engine, h256 const& _mixHash, Nonce _nonce); static bool isWorking(SealEngineFace* _engine); static WorkingProgress workingProgress(SealEngineFace* _engine); diff --git a/libethcore/EthashSealEngine.cpp b/libethcore/EthashSealEngine.cpp index 290ec427b..dc865f787 100644 --- a/libethcore/EthashSealEngine.cpp +++ b/libethcore/EthashSealEngine.cpp @@ -54,7 +54,8 @@ void EthashSealEngine::generateSeal(BlockInfo const& _bi) m_farm.setWork(m_sealing); m_farm.start(m_sealer); m_farm.setWork(m_sealing); // TODO: take out one before or one after... - Ethash::ensurePrecomputed((unsigned)_bi.number()); + if (option("precomputeDAG")[0] == 1) + Ethash::ensurePrecomputed((unsigned)_bi.number()); } void EthashSealEngine::onSealGenerated(std::function const& _f) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 16e5ba318..205d4ba96 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -443,6 +443,13 @@ void Client::setForceMining(bool _enable) startMining(); } +void Client::setShouldPrecomputeDAG(bool _precompute) +{ + bytes trueBytes {1}; + bytes falseBytes {0}; + sealEngine()->setOption("precomputeDAG", _precompute ? trueBytes: falseBytes); +} + bool Client::isMining() const { return Ethash::isWorking(m_sealEngine.get()); diff --git a/libethereum/Client.h b/libethereum/Client.h index 9839c5617..56afe68b1 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -140,6 +140,8 @@ public: bool turboMining() const { return m_turboMining; } /// Enable/disable GPU mining. void setTurboMining(bool _enable = true) { m_turboMining = _enable; if (isMining()) startMining(); } + /// Enable/disable precomputing of the DAG for next epoch + void setShouldPrecomputeDAG(bool _precompute); /// Check to see if we'd mine on an apparently bad chain. bool mineOnBadChain() const { return m_mineOnBadChain; } From 69e8b01115eb1a4b14c1ecf8726c297de5d924ec Mon Sep 17 00:00:00 2001 From: Lefteris Karapetsas Date: Tue, 21 Jul 2015 15:50:02 +0200 Subject: [PATCH 3/3] Check if precompute seal option exists plus indentation style fix --- libethcore/EthashSealEngine.cpp | 3 ++- libethereum/Client.h | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libethcore/EthashSealEngine.cpp b/libethcore/EthashSealEngine.cpp index dc865f787..4803d9ed4 100644 --- a/libethcore/EthashSealEngine.cpp +++ b/libethcore/EthashSealEngine.cpp @@ -54,7 +54,8 @@ void EthashSealEngine::generateSeal(BlockInfo const& _bi) m_farm.setWork(m_sealing); m_farm.start(m_sealer); m_farm.setWork(m_sealing); // TODO: take out one before or one after... - if (option("precomputeDAG")[0] == 1) + bytes shouldPrecompute = option("precomputeDAG"); + if (!shouldPrecompute.empty() && shouldPrecompute[0] == 1) Ethash::ensurePrecomputed((unsigned)_bi.number()); } diff --git a/libethereum/Client.h b/libethereum/Client.h index 56afe68b1..9e88775f9 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -140,8 +140,8 @@ public: bool turboMining() const { return m_turboMining; } /// Enable/disable GPU mining. void setTurboMining(bool _enable = true) { m_turboMining = _enable; if (isMining()) startMining(); } - /// Enable/disable precomputing of the DAG for next epoch - void setShouldPrecomputeDAG(bool _precompute); + /// Enable/disable precomputing of the DAG for next epoch + void setShouldPrecomputeDAG(bool _precompute); /// Check to see if we'd mine on an apparently bad chain. bool mineOnBadChain() const { return m_mineOnBadChain; }