Browse Source

Switch to using the Sealers API for precompute

cl-refactor
Lefteris Karapetsas 10 years ago
parent
commit
a700950765
  1. 1
      eth/main.cpp
  2. 1
      ethminer/MinerAux.h
  3. 4
      libethcore/Ethash.cpp
  4. 2
      libethcore/Ethash.h
  5. 3
      libethcore/EthashSealEngine.cpp
  6. 7
      libethereum/Client.cpp
  7. 2
      libethereum/Client.h

1
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);

1
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)

4
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);
}

2
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);

3
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<void(bytes const&)> const& _f)

7
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());

2
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; }

Loading…
Cancel
Save