Browse Source

Avoid div by zero.

Always prepare work, even when not apparently mining.
cl-refactor
Gav Wood 10 years ago
parent
commit
3efa477be6
  1. 6
      eth/main.cpp
  2. 2
      libethcore/BlockInfo.cpp
  3. 6
      libethcore/Miner.h
  4. 6
      libethereum/Client.cpp

6
eth/main.cpp

@ -379,8 +379,8 @@ void doFarm(MinerType _m, string const& _remote, unsigned _recheckPeriod)
{ {
current.headerHash = hh; current.headerHash = hh;
current.seedHash = h256(v[1].asString()); current.seedHash = h256(v[1].asString());
current.boundary = h256(v[2].asString()); current.boundary = h256(fromHex(v[2].asString()), h256::AlignRight);
cnote << "Got new work package."; cnote << "Got work package:" << current.headerHash.abridged() << " < " << current.boundary;
f.setWork(current); f.setWork(current);
} }
this_thread::sleep_for(chrono::milliseconds(_recheckPeriod)); this_thread::sleep_for(chrono::milliseconds(_recheckPeriod));
@ -395,7 +395,7 @@ void doFarm(MinerType _m, string const& _remote, unsigned _recheckPeriod)
} }
catch (jsonrpc::JsonRpcException&) catch (jsonrpc::JsonRpcException&)
{ {
for (auto i = 10; --i; this_thread::sleep_for(chrono::seconds(1))) for (auto i = 3; --i; this_thread::sleep_for(chrono::seconds(1)))
cerr << "JSON-RPC problem. Probably couldn't connect. Retrying in " << i << "... \r"; cerr << "JSON-RPC problem. Probably couldn't connect. Retrying in " << i << "... \r";
cerr << endl; cerr << endl;
} }

2
libethcore/BlockInfo.cpp

@ -77,7 +77,7 @@ h256 const& BlockInfo::hash() const
h256 const& BlockInfo::boundary() const h256 const& BlockInfo::boundary() const
{ {
if (!m_boundary) if (!m_boundary && difficulty)
m_boundary = (h256)(u256)((bigint(1) << 256) / difficulty); m_boundary = (h256)(u256)((bigint(1) << 256) / difficulty);
return m_boundary; return m_boundary;
} }

6
libethcore/Miner.h

@ -24,7 +24,9 @@
#include <thread> #include <thread>
#include <list> #include <list>
#include <atomic> #include <atomic>
#include <boost/timer.hpp>
#include <libdevcore/Common.h> #include <libdevcore/Common.h>
#include <libdevcore/Log.h>
#include <libdevcore/Worker.h> #include <libdevcore/Worker.h>
#include <libethcore/Common.h> #include <libethcore/Common.h>
@ -105,8 +107,12 @@ public:
} }
if (!!_work) if (!!_work)
{ {
boost::timer t;
pause(); pause();
cdebug << "pause took" << t.elapsed();
t.restart();
kickOff(); kickOff();
cdebug << "kickOff took" << t.elapsed();
} }
else if (!_work && !!old) else if (!_work && !!old)
pause(); pause();

6
libethereum/Client.cpp

@ -530,15 +530,15 @@ void Client::onChainChanged(ImportRoute const& _ir)
void Client::onPostStateChanged() void Client::onPostStateChanged()
{ {
cnote << "Post state changed: Restarting mining..."; cnote << "Post state changed: Restarting mining...";
if (isMining()) // if (isMining())
{ // {
{ {
WriteGuard l(x_postMine); WriteGuard l(x_postMine);
m_postMine.commitToMine(m_bc); m_postMine.commitToMine(m_bc);
m_miningInfo = m_postMine.info(); m_miningInfo = m_postMine.info();
} }
m_farm.setWork(m_miningInfo); m_farm.setWork(m_miningInfo);
} // }
m_remoteWorking = false; m_remoteWorking = false;
} }

Loading…
Cancel
Save