diff --git a/eth/main.cpp b/eth/main.cpp index e17a6ebaf..fefac5138 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -291,10 +291,13 @@ enum class Format Human }; -void stopMiningAfterXBlocks(eth::Client* _c, unsigned _start, unsigned _mining) +void stopMiningAfterXBlocks(eth::Client* _c, unsigned _start, unsigned& io_mining) { - if (_c->isMining() && _c->blockChain().details().number - _start == _mining) + if (io_mining != ~(unsigned)0 && io_mining && _c->isMining() && _c->blockChain().details().number - _start == io_mining) + { _c->stopMining(); + io_mining = ~(unsigned)0; + } this_thread::sleep_for(chrono::milliseconds(100)); } diff --git a/libethcore/EthashCPUMiner.cpp b/libethcore/EthashCPUMiner.cpp index f14c7b625..0c645c831 100644 --- a/libethcore/EthashCPUMiner.cpp +++ b/libethcore/EthashCPUMiner.cpp @@ -53,6 +53,26 @@ static string jsonEncode(map const& _m) } #endif +EthashCPUMiner::EthashCPUMiner(GenericMiner::ConstructionInfo const& _ci): + GenericMiner(_ci), Worker("miner" + toString(index())) +{ +} + +EthashCPUMiner::~EthashCPUMiner() +{ +} + +void EthashCPUMiner::kickOff() +{ + stopWorking(); + startWorking(); +} + +void EthashCPUMiner::pause() +{ + stopWorking(); +} + void EthashCPUMiner::workLoop() { auto tid = std::this_thread::get_id(); diff --git a/libethcore/EthashCPUMiner.h b/libethcore/EthashCPUMiner.h index ff3c58df1..ce464b0e2 100644 --- a/libethcore/EthashCPUMiner.h +++ b/libethcore/EthashCPUMiner.h @@ -35,7 +35,8 @@ namespace eth class EthashCPUMiner: public GenericMiner, Worker { public: - EthashCPUMiner(GenericMiner::ConstructionInfo const& _ci): GenericMiner(_ci), Worker("miner" + toString(index())) {} + EthashCPUMiner(GenericMiner::ConstructionInfo const& _ci); + ~EthashCPUMiner(); static unsigned instances() { return s_numInstances > 0 ? s_numInstances : std::thread::hardware_concurrency(); } static std::string platformInfo(); @@ -44,13 +45,8 @@ public: static void setNumInstances(unsigned _instances) { s_numInstances = std::min(_instances, std::thread::hardware_concurrency()); } protected: - void kickOff() override - { - stopWorking(); - startWorking(); - } - - void pause() override { stopWorking(); } + void kickOff() override; + void pause() override; private: void workLoop() override; diff --git a/libethcore/Farm.h b/libethcore/Farm.h index c86b4804e..146bf1caa 100644 --- a/libethcore/Farm.h +++ b/libethcore/Farm.h @@ -67,7 +67,6 @@ public: void setWork(WorkPackage const& _wp) { WriteGuard l(x_minerWork); - cdebug << "Farm::setWork()"; if (_wp.headerHash == m_work.headerHash) return; m_work = _wp; @@ -84,7 +83,6 @@ public: bool start(std::string const& _sealer) { WriteGuard l(x_minerWork); - cdebug << "start()"; if (!m_miners.empty() && m_lastSealer == _sealer) return true; if (!m_sealers.count(_sealer)) diff --git a/libweb3jsonrpc/WebThreeStubServer.cpp b/libweb3jsonrpc/WebThreeStubServer.cpp index 7dd1ed246..b90c43cf3 100644 --- a/libweb3jsonrpc/WebThreeStubServer.cpp +++ b/libweb3jsonrpc/WebThreeStubServer.cpp @@ -77,11 +77,11 @@ bool WebThreeStubServer::eth_notePassword(string const& _password) return true; } -#define ADMIN requires(_session, Privilege::Admin) +#define ADMIN_GUARD requires(_session, Privilege::Admin) Json::Value WebThreeStubServer::admin_eth_blockQueueStatus(string const& _session) { - ADMIN; + ADMIN_GUARD; Json::Value ret; BlockQueueStatus bqs = m_web3.ethereum()->blockQueue().status(); 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) { - ADMIN; + ADMIN_GUARD; m_gp.setAsk(jsToU256(_wei)); return true; } bool WebThreeStubServer::admin_eth_setBidPrice(std::string const& _wei, std::string const& _session) { - ADMIN; + ADMIN_GUARD; m_gp.setBid(jsToU256(_wei)); 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) { - ADMIN; + ADMIN_GUARD; h256 h(_blockHash); if (bc().isKnown(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) { - ADMIN; + ADMIN_GUARD; return bq().firstUnknown().hex(); } bool WebThreeStubServer::admin_eth_blockQueueRetryUnknown(std::string const& _session) { - ADMIN; + ADMIN_GUARD; m_web3.ethereum()->retryUnknown(); return true; } Json::Value WebThreeStubServer::admin_eth_allAccounts(std::string const& _session) { - ADMIN; + ADMIN_GUARD; Json::Value ret; u256 total = 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) { - ADMIN; + ADMIN_GUARD; if (!_info.isMember("name")) throw jsonrpc::JsonRpcException("No member found: name"); 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) { - ADMIN; + ADMIN_GUARD; Address a; h128 uuid = fromUUID(_uuidOrAddress); 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) { - ADMIN; + ADMIN_GUARD; if (!isHash
(_address)) 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) { - ADMIN; + ADMIN_GUARD; Json::Value ret; PopulationStatistics 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) { - ADMIN; + ADMIN_GUARD; 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) { - ADMIN; + ADMIN_GUARD; if (_txIndex < 0) throw jsonrpc::JsonRpcException("Negative index"); auto h = blockHash(_blockNumberOrHash);