Browse Source

Fix mining.

cl-refactor
Gav Wood 10 years ago
parent
commit
91050f2b4a
  1. 7
      eth/main.cpp
  2. 20
      libethcore/EthashCPUMiner.cpp
  3. 12
      libethcore/EthashCPUMiner.h
  4. 2
      libethcore/Farm.h
  5. 28
      libweb3jsonrpc/WebThreeStubServer.cpp

7
eth/main.cpp

@ -291,10 +291,13 @@ enum class Format
Human Human
}; };
void stopMiningAfterXBlocks(eth::Client* _c, unsigned _start, unsigned _mining) void stopMiningAfterXBlocks(eth::Client* _c, unsigned _start, unsigned& io_mining)
{
if (io_mining != ~(unsigned)0 && io_mining && _c->isMining() && _c->blockChain().details().number - _start == io_mining)
{ {
if (_c->isMining() && _c->blockChain().details().number - _start == _mining)
_c->stopMining(); _c->stopMining();
io_mining = ~(unsigned)0;
}
this_thread::sleep_for(chrono::milliseconds(100)); this_thread::sleep_for(chrono::milliseconds(100));
} }

20
libethcore/EthashCPUMiner.cpp

@ -53,6 +53,26 @@ static string jsonEncode(map<string, string> const& _m)
} }
#endif #endif
EthashCPUMiner::EthashCPUMiner(GenericMiner<EthashProofOfWork>::ConstructionInfo const& _ci):
GenericMiner<EthashProofOfWork>(_ci), Worker("miner" + toString(index()))
{
}
EthashCPUMiner::~EthashCPUMiner()
{
}
void EthashCPUMiner::kickOff()
{
stopWorking();
startWorking();
}
void EthashCPUMiner::pause()
{
stopWorking();
}
void EthashCPUMiner::workLoop() void EthashCPUMiner::workLoop()
{ {
auto tid = std::this_thread::get_id(); auto tid = std::this_thread::get_id();

12
libethcore/EthashCPUMiner.h

@ -35,7 +35,8 @@ namespace eth
class EthashCPUMiner: public GenericMiner<EthashProofOfWork>, Worker class EthashCPUMiner: public GenericMiner<EthashProofOfWork>, Worker
{ {
public: public:
EthashCPUMiner(GenericMiner<EthashProofOfWork>::ConstructionInfo const& _ci): GenericMiner<EthashProofOfWork>(_ci), Worker("miner" + toString(index())) {} EthashCPUMiner(GenericMiner<EthashProofOfWork>::ConstructionInfo const& _ci);
~EthashCPUMiner();
static unsigned instances() { return s_numInstances > 0 ? s_numInstances : std::thread::hardware_concurrency(); } static unsigned instances() { return s_numInstances > 0 ? s_numInstances : std::thread::hardware_concurrency(); }
static std::string platformInfo(); static std::string platformInfo();
@ -44,13 +45,8 @@ public:
static void setNumInstances(unsigned _instances) { s_numInstances = std::min<unsigned>(_instances, std::thread::hardware_concurrency()); } static void setNumInstances(unsigned _instances) { s_numInstances = std::min<unsigned>(_instances, std::thread::hardware_concurrency()); }
protected: protected:
void kickOff() override void kickOff() override;
{ void pause() override;
stopWorking();
startWorking();
}
void pause() override { stopWorking(); }
private: private:
void workLoop() override; void workLoop() override;

2
libethcore/Farm.h

@ -67,7 +67,6 @@ public:
void setWork(WorkPackage const& _wp) void setWork(WorkPackage const& _wp)
{ {
WriteGuard l(x_minerWork); WriteGuard l(x_minerWork);
cdebug << "Farm::setWork()";
if (_wp.headerHash == m_work.headerHash) if (_wp.headerHash == m_work.headerHash)
return; return;
m_work = _wp; m_work = _wp;
@ -84,7 +83,6 @@ public:
bool start(std::string const& _sealer) bool start(std::string const& _sealer)
{ {
WriteGuard l(x_minerWork); WriteGuard l(x_minerWork);
cdebug << "start()";
if (!m_miners.empty() && m_lastSealer == _sealer) if (!m_miners.empty() && m_lastSealer == _sealer)
return true; return true;
if (!m_sealers.count(_sealer)) if (!m_sealers.count(_sealer))

28
libweb3jsonrpc/WebThreeStubServer.cpp

@ -77,11 +77,11 @@ bool WebThreeStubServer::eth_notePassword(string const& _password)
return true; return true;
} }
#define ADMIN requires(_session, Privilege::Admin) #define ADMIN_GUARD requires(_session, Privilege::Admin)
Json::Value WebThreeStubServer::admin_eth_blockQueueStatus(string const& _session) Json::Value WebThreeStubServer::admin_eth_blockQueueStatus(string const& _session)
{ {
ADMIN; ADMIN_GUARD;
Json::Value ret; Json::Value ret;
BlockQueueStatus bqs = m_web3.ethereum()->blockQueue().status(); BlockQueueStatus bqs = m_web3.ethereum()->blockQueue().status();
ret["importing"] = (int)bqs.importing; ret["importing"] = (int)bqs.importing;
@ -96,14 +96,14 @@ Json::Value WebThreeStubServer::admin_eth_blockQueueStatus(string const& _sessio
bool WebThreeStubServer::admin_eth_setAskPrice(std::string const& _wei, std::string const& _session) bool WebThreeStubServer::admin_eth_setAskPrice(std::string const& _wei, std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
m_gp.setAsk(jsToU256(_wei)); m_gp.setAsk(jsToU256(_wei));
return true; return true;
} }
bool WebThreeStubServer::admin_eth_setBidPrice(std::string const& _wei, std::string const& _session) bool WebThreeStubServer::admin_eth_setBidPrice(std::string const& _wei, std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
m_gp.setBid(jsToU256(_wei)); m_gp.setBid(jsToU256(_wei));
return true; return true;
} }
@ -120,7 +120,7 @@ dev::eth::BlockQueue const& WebThreeStubServer::bq() const
Json::Value WebThreeStubServer::admin_eth_findBlock(std::string const& _blockHash, std::string const& _session) Json::Value WebThreeStubServer::admin_eth_findBlock(std::string const& _blockHash, std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
h256 h(_blockHash); h256 h(_blockHash);
if (bc().isKnown(h)) if (bc().isKnown(h))
return toJson(bc().info(h)); return toJson(bc().info(h));
@ -141,20 +141,20 @@ Json::Value WebThreeStubServer::admin_eth_findBlock(std::string const& _blockHas
std::string WebThreeStubServer::admin_eth_blockQueueFirstUnknown(std::string const& _session) std::string WebThreeStubServer::admin_eth_blockQueueFirstUnknown(std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
return bq().firstUnknown().hex(); return bq().firstUnknown().hex();
} }
bool WebThreeStubServer::admin_eth_blockQueueRetryUnknown(std::string const& _session) bool WebThreeStubServer::admin_eth_blockQueueRetryUnknown(std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
m_web3.ethereum()->retryUnknown(); m_web3.ethereum()->retryUnknown();
return true; return true;
} }
Json::Value WebThreeStubServer::admin_eth_allAccounts(std::string const& _session) Json::Value WebThreeStubServer::admin_eth_allAccounts(std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
Json::Value ret; Json::Value ret;
u256 total = 0; u256 total = 0;
u256 pendingtotal = 0; u256 pendingtotal = 0;
@ -184,7 +184,7 @@ Json::Value WebThreeStubServer::admin_eth_allAccounts(std::string const& _sessio
Json::Value WebThreeStubServer::admin_eth_newAccount(Json::Value const& _info, std::string const& _session) Json::Value WebThreeStubServer::admin_eth_newAccount(Json::Value const& _info, std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
if (!_info.isMember("name")) if (!_info.isMember("name"))
throw jsonrpc::JsonRpcException("No member found: name"); throw jsonrpc::JsonRpcException("No member found: name");
string name = _info["name"].asString(); string name = _info["name"].asString();
@ -206,7 +206,7 @@ Json::Value WebThreeStubServer::admin_eth_newAccount(Json::Value const& _info, s
bool WebThreeStubServer::admin_eth_setMiningBenefactor(std::string const& _uuidOrAddress, std::string const& _session) bool WebThreeStubServer::admin_eth_setMiningBenefactor(std::string const& _uuidOrAddress, std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
Address a; Address a;
h128 uuid = fromUUID(_uuidOrAddress); h128 uuid = fromUUID(_uuidOrAddress);
if (uuid) if (uuid)
@ -222,7 +222,7 @@ bool WebThreeStubServer::admin_eth_setMiningBenefactor(std::string const& _uuidO
Json::Value WebThreeStubServer::admin_eth_inspect(std::string const& _address, std::string const& _session) Json::Value WebThreeStubServer::admin_eth_inspect(std::string const& _address, std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
if (!isHash<Address>(_address)) if (!isHash<Address>(_address))
throw jsonrpc::JsonRpcException("Invalid address given."); throw jsonrpc::JsonRpcException("Invalid address given.");
@ -251,7 +251,7 @@ h256 WebThreeStubServer::blockHash(std::string const& _blockNumberOrHash) const
Json::Value WebThreeStubServer::admin_eth_reprocess(std::string const& _blockNumberOrHash, std::string const& _session) Json::Value WebThreeStubServer::admin_eth_reprocess(std::string const& _blockNumberOrHash, std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
Json::Value ret; Json::Value ret;
PopulationStatistics ps; PopulationStatistics ps;
m_web3.ethereum()->state(blockHash(_blockNumberOrHash), &ps); m_web3.ethereum()->state(blockHash(_blockNumberOrHash), &ps);
@ -263,7 +263,7 @@ Json::Value WebThreeStubServer::admin_eth_reprocess(std::string const& _blockNum
Json::Value WebThreeStubServer::admin_eth_vmTrace(std::string const& _blockNumberOrHash, int _txIndex, std::string const& _session) Json::Value WebThreeStubServer::admin_eth_vmTrace(std::string const& _blockNumberOrHash, int _txIndex, std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
Json::Value ret; Json::Value ret;
@ -299,7 +299,7 @@ Json::Value WebThreeStubServer::admin_eth_vmTrace(std::string const& _blockNumbe
Json::Value WebThreeStubServer::admin_eth_getReceiptByHashAndIndex(std::string const& _blockNumberOrHash, int _txIndex, std::string const& _session) Json::Value WebThreeStubServer::admin_eth_getReceiptByHashAndIndex(std::string const& _blockNumberOrHash, int _txIndex, std::string const& _session)
{ {
ADMIN; ADMIN_GUARD;
if (_txIndex < 0) if (_txIndex < 0)
throw jsonrpc::JsonRpcException("Negative index"); throw jsonrpc::JsonRpcException("Negative index");
auto h = blockHash(_blockNumberOrHash); auto h = blockHash(_blockNumberOrHash);

Loading…
Cancel
Save