From 4708a73e19314c260298fdb8533ec6c5bbdeea02 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sun, 19 Apr 2015 22:59:57 +0200 Subject: [PATCH] Remote miner fixes. --- eth/Farm.h | 3 +- eth/farm.json | 2 +- eth/main.cpp | 61 ++++++++++++++------- libdevcore/Worker.cpp | 3 +- libethcore/Ethash.cpp | 5 +- libethereum/CommonNet.h | 12 ++-- libweb3jsonrpc/WebThreeStubServerBase.cpp | 2 +- libweb3jsonrpc/WebThreeStubServerBase.h | 2 +- libweb3jsonrpc/abstractwebthreestubserver.h | 6 +- libweb3jsonrpc/spec.json | 2 +- test/webthreestubclient.h | 3 +- 11 files changed, 63 insertions(+), 38 deletions(-) diff --git a/eth/Farm.h b/eth/Farm.h index c061449e3..ae2ef5a7d 100644 --- a/eth/Farm.h +++ b/eth/Farm.h @@ -22,11 +22,12 @@ class Farm : public jsonrpc::Client else throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); } - bool eth_submitWork(const std::string& param1, const std::string& param2) throw (jsonrpc::JsonRpcException) + bool eth_submitWork(const std::string& param1, const std::string& param2, const std::string& param3) throw (jsonrpc::JsonRpcException) { Json::Value p; p.append(param1); p.append(param2); + p.append(param3); Json::Value result = this->CallMethod("eth_submitWork",p); if (result.isBool()) return result.asBool(); diff --git a/eth/farm.json b/eth/farm.json index 24f0c163e..1f4142d00 100644 --- a/eth/farm.json +++ b/eth/farm.json @@ -1,4 +1,4 @@ [ { "name": "eth_getWork", "params": [], "order": [], "returns": []}, - { "name": "eth_submitWork", "params": ["", ""], "order": [], "returns": true} + { "name": "eth_submitWork", "params": ["", "", ""], "order": [], "returns": true} ] diff --git a/eth/main.cpp b/eth/main.cpp index f47243972..a85e14485 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -339,6 +339,9 @@ void doBenchmark(MinerType _m, bool _phoneHome, unsigned _warmupDuration = 15, u exit(0); } +struct HappyChannel: public LogChannel { static const char* name() { return ":-D"; } static const int verbosity = 1; }; +struct SadChannel: public LogChannel { static const char* name() { return ":-("; } static const int verbosity = 1; }; + void doFarm(MinerType _m, string const& _remote, unsigned _recheckPeriod) { (void)_m; @@ -347,9 +350,7 @@ void doFarm(MinerType _m, string const& _remote, unsigned _recheckPeriod) #if ETH_JSONRPC || !ETH_TRUE jsonrpc::HttpClient client(_remote); Farm rpc(client); - GenericFarm f; - if (_m == MinerType::CPU) f.startCPU(); else if (_m == MinerType::GPU) @@ -357,29 +358,47 @@ void doFarm(MinerType _m, string const& _remote, unsigned _recheckPeriod) ProofOfWork::WorkPackage current; while (true) - { - bool completed = false; - ProofOfWork::Solution solution; - f.onSolutionFound([&](ProofOfWork::Solution sol) - { - solution = sol; - return completed = true; - }); - for (unsigned i = 0; !completed; ++i) + try { - Json::Value v = rpc.eth_getWork(); - h256 hh(v[0].asString()); - if (hh != current.headerHash) + bool completed = false; + ProofOfWork::Solution solution; + f.onSolutionFound([&](ProofOfWork::Solution sol) + { + solution = sol; + return completed = true; + }); + for (unsigned i = 0; !completed; ++i) { - current.headerHash = hh; - current.seedHash = h256(v[1].asString()); - current.boundary = h256(v[2].asString()); - f.setWork(current); + if (current) + cnote << "Mining on PoWhash" << current.headerHash.abridged() << ": " << f.miningProgress(); + else + cnote << "Getting work package..."; + Json::Value v = rpc.eth_getWork(); + h256 hh(v[0].asString()); + if (hh != current.headerHash) + { + current.headerHash = hh; + current.seedHash = h256(v[1].asString()); + current.boundary = h256(v[2].asString()); + cnote << "Got new work package."; + f.setWork(current); + } + this_thread::sleep_for(chrono::milliseconds(_recheckPeriod)); } - this_thread::sleep_for(chrono::milliseconds(_recheckPeriod)); + cnote << "Solution found; submitting [" << solution.nonce << "," << current.headerHash.abridged() << "," << solution.mixHash.abridged() << "] to" << _remote << "..."; + bool ok = rpc.eth_submitWork("0x" + toString(solution.nonce), "0x" + toString(current.headerHash), "0x" + toString(solution.mixHash)); + if (ok) + clog(HappyChannel) << "Submitted and accepted."; + else + clog(SadChannel) << "Not accepted."; + current.reset(); + } + catch (jsonrpc::JsonRpcException&) + { + for (auto i = 10; --i; this_thread::sleep_for(chrono::seconds(1))) + cerr << "JSON-RPC problem. Probably couldn't connect. Retrying in " << i << "... \r"; + cerr << endl; } - rpc.eth_submitWork("0x" + toString(solution.nonce), "0x" + toString(solution.mixHash)); - } #endif exit(0); } diff --git a/libdevcore/Worker.cpp b/libdevcore/Worker.cpp index 19c0d9751..7fe320420 100644 --- a/libdevcore/Worker.cpp +++ b/libdevcore/Worker.cpp @@ -43,8 +43,9 @@ void Worker::startWorking() m_state.compare_exchange_strong(ex, WorkerState::Started); startedWorking(); + cnote << "Entering work loop..."; workLoop(); - cnote << "Finishing up worker thread"; + cnote << "Finishing up worker thread..."; doneWorking(); // ex = WorkerState::Stopping; diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index c61529017..7ff35fd2b 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -314,7 +314,10 @@ void Ethash::GPUMiner::workLoop() uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)w.boundary >> 192); m_miner->search(w.headerHash.data(), upper64OfBoundary, *m_hook); } - catch (...) {} + catch (...) + { + cwarn << "Error GPU mining. GPU memory fragmentation?"; + } } void Ethash::GPUMiner::pause() diff --git a/libethereum/CommonNet.h b/libethereum/CommonNet.h index 2ee260650..2083e9919 100644 --- a/libethereum/CommonNet.h +++ b/libethereum/CommonNet.h @@ -37,13 +37,13 @@ namespace eth { #if ETH_DEBUG -static const unsigned c_maxHashes = 64; ///< Maximum number of hashes BlockHashes will ever send. -static const unsigned c_maxHashesAsk = 64; ///< Maximum number of hashes GetBlockHashes will ever ask for. -static const unsigned c_maxBlocks = 32; ///< Maximum number of blocks Blocks will ever send. -static const unsigned c_maxBlocksAsk = 32; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain). +static const unsigned c_maxHashes = 2048; ///< Maximum number of hashes BlockHashes will ever send. +static const unsigned c_maxHashesAsk = 2048; ///< Maximum number of hashes GetBlockHashes will ever ask for. +static const unsigned c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send. +static const unsigned c_maxBlocksAsk = 128; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain). #else -static const unsigned c_maxHashes = 256; ///< Maximum number of hashes BlockHashes will ever send. -static const unsigned c_maxHashesAsk = 256; ///< Maximum number of hashes GetBlockHashes will ever ask for. +static const unsigned c_maxHashes = 2048; ///< Maximum number of hashes BlockHashes will ever send. +static const unsigned c_maxHashesAsk = 2048; ///< Maximum number of hashes GetBlockHashes will ever ask for. static const unsigned c_maxBlocks = 128; ///< Maximum number of blocks Blocks will ever send. static const unsigned c_maxBlocksAsk = 128; ///< Maximum number of blocks we ask to receive in Blocks (when using GetChain). #endif diff --git a/libweb3jsonrpc/WebThreeStubServerBase.cpp b/libweb3jsonrpc/WebThreeStubServerBase.cpp index 7fc68c27f..212f3728b 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.cpp +++ b/libweb3jsonrpc/WebThreeStubServerBase.cpp @@ -775,7 +775,7 @@ Json::Value WebThreeStubServerBase::eth_getWork() return ret; } -bool WebThreeStubServerBase::eth_submitWork(string const& _nonce, string const& _mixHash) +bool WebThreeStubServerBase::eth_submitWork(string const& _nonce, string const&, string const& _mixHash) { try { diff --git a/libweb3jsonrpc/WebThreeStubServerBase.h b/libweb3jsonrpc/WebThreeStubServerBase.h index 22a31a762..9180c8ef7 100644 --- a/libweb3jsonrpc/WebThreeStubServerBase.h +++ b/libweb3jsonrpc/WebThreeStubServerBase.h @@ -113,7 +113,7 @@ public: virtual Json::Value eth_getFilterLogs(std::string const& _filterId); virtual Json::Value eth_getLogs(Json::Value const& _json); virtual Json::Value eth_getWork(); - virtual bool eth_submitWork(std::string const& _nonce, std::string const& _mixHash); + virtual bool eth_submitWork(std::string const& _nonce, std::string const&, std::string const& _mixHash); virtual std::string eth_register(std::string const& _address); virtual bool eth_unregister(std::string const& _accountId); virtual Json::Value eth_fetchQueuedTransactions(std::string const& _accountId); diff --git a/libweb3jsonrpc/abstractwebthreestubserver.h b/libweb3jsonrpc/abstractwebthreestubserver.h index 0860ecaee..8da47d0fc 100644 --- a/libweb3jsonrpc/abstractwebthreestubserver.h +++ b/libweb3jsonrpc/abstractwebthreestubserver.h @@ -53,7 +53,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerbindAndAddMethod(jsonrpc::Procedure("eth_getFilterLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_getFilterLogsI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getLogs", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_OBJECT, NULL), &AbstractWebThreeStubServer::eth_getLogsI); this->bindAndAddMethod(jsonrpc::Procedure("eth_getWork", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, NULL), &AbstractWebThreeStubServer::eth_getWorkI); - this->bindAndAddMethod(jsonrpc::Procedure("eth_submitWork", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_submitWorkI); + this->bindAndAddMethod(jsonrpc::Procedure("eth_submitWork", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING,"param2",jsonrpc::JSON_STRING,"param3",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_submitWorkI); this->bindAndAddMethod(jsonrpc::Procedure("eth_register", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_STRING, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_registerI); this->bindAndAddMethod(jsonrpc::Procedure("eth_unregister", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_BOOLEAN, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_unregisterI); this->bindAndAddMethod(jsonrpc::Procedure("eth_fetchQueuedTransactions", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_ARRAY, "param1",jsonrpc::JSON_STRING, NULL), &AbstractWebThreeStubServer::eth_fetchQueuedTransactionsI); @@ -250,7 +250,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServereth_submitWork(request[0u].asString(), request[1u].asString()); + response = this->eth_submitWork(request[0u].asString(), request[1u].asString(), request[2u].asString()); } inline virtual void eth_registerI(const Json::Value &request, Json::Value &response) { @@ -350,7 +350,7 @@ class AbstractWebThreeStubServer : public jsonrpc::AbstractServerCallMethod("eth_submitWork",p); if (result.isBool()) return result.asBool();