From cac1ea356755116b1ccaae51fa52855d594368bc Mon Sep 17 00:00:00 2001 From: Genoil Date: Wed, 23 Mar 2016 10:22:55 +0100 Subject: [PATCH] failover farm URL (getwork only) --- ethminer/MinerAux.h | 56 +++++++++++++++++++++++++++++++++++----- libethcore/EthashAux.cpp | 2 +- 2 files changed, 50 insertions(+), 8 deletions(-) diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index 4558980ca..47c3c09fb 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -118,6 +118,12 @@ public: { mode = OperationMode::Farm; m_farmURL = argv[++i]; + m_activeFarmURL = m_farmURL; + } + else if ((arg == "-FF" || arg == "--farm-failover") && i + 1 < argc) + { + mode = OperationMode::Farm; + m_farmFailOverURL = argv[++i]; } else if (arg == "--farm-recheck" && i + 1 < argc) try { @@ -128,6 +134,15 @@ public: cerr << "Bad " << arg << " option: " << argv[i] << endl; BOOST_THROW_EXCEPTION(BadArgument()); } + else if (arg == "--farm-retries" && i + 1 < argc) + try { + m_maxFarmRetries = stol(argv[++i]); + } + catch (...) + { + cerr << "Bad " << arg << " option: " << argv[i] << endl; + BOOST_THROW_EXCEPTION(BadArgument()); + } #if ETH_STRATUM || !ETH_TRUE else if ((arg == "-S" || arg == "--stratum") && i + 1 < argc) { @@ -515,7 +530,7 @@ public: else if (mode == OperationMode::Benchmark) doBenchmark(m_minerType, m_phoneHome, m_benchmarkWarmup, m_benchmarkTrial, m_benchmarkTrials); else if (mode == OperationMode::Farm) - doFarm(m_minerType, m_farmURL, m_farmRecheckPeriod); + doFarm(m_minerType, m_activeFarmURL, m_farmRecheckPeriod); else if (mode == OperationMode::Simulation) doSimulation(m_minerType); #if ETH_STRATUM || !ETH_TRUE @@ -530,6 +545,8 @@ public: #if ETH_JSONRPC || !ETH_TRUE << "Work farming mode:" << endl << " -F,--farm Put into mining farm mode with the work server at URL (default: http://127.0.0.1:8545)" << endl + << " -FF,--farm-failover Failover farm URL (default: disabled)" << endl + << " --farm-retries Number of retries until switch to failover (default: 3)" << endl #endif #if ETH_STRATUM || !ETH_TRUE << " -S, --stratum Put into stratum mode with the stratum server at host:port" << endl @@ -780,7 +797,8 @@ private: } } - void doFarm(MinerType _m, string const& _remote, unsigned _recheckPeriod) + + void doFarm(MinerType _m, string & _remote, unsigned _recheckPeriod) { map::SealerDescriptor> sealers; sealers["cpu"] = GenericFarm::SealerDescriptor{&EthashCPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCPUMiner(ci); }}; @@ -794,10 +812,14 @@ private: (void)_remote; (void)_recheckPeriod; #if ETH_JSONRPC || !ETH_TRUE - jsonrpc::HttpClient client(_remote); + jsonrpc::HttpClient client(m_farmURL); + :: FarmClient rpc(client); + jsonrpc::HttpClient failoverClient(m_farmFailOverURL); + ::FarmClient rpcFailover(failoverClient); + + FarmClient * prpc = &rpc; h256 id = h256::random(); - ::FarmClient rpc(client); GenericFarm f; f.setSealers(sealers); if (_m == MinerType::CPU) @@ -831,7 +853,7 @@ private: try { - rpc.eth_submitHashrate(toJS((u256)rate), "0x" + id.hex()); + prpc->eth_submitHashrate(toJS((u256)rate), "0x" + id.hex()); } catch (jsonrpc::JsonRpcException const& _e) { @@ -839,7 +861,7 @@ private: cwarn << boost::diagnostic_information(_e); } - Json::Value v = rpc.eth_getWork(); + Json::Value v = prpc->eth_getWork(); h256 hh(v[0].asString()); h256 newSeedHash(v[1].asString()); if (current.seedHash != newSeedHash) @@ -870,7 +892,7 @@ private: cnote << " Ethash: " << h256(EthashAux::eval(current.seedHash, current.headerHash, solution.nonce).value).hex(); if (EthashAux::eval(current.seedHash, current.headerHash, solution.nonce).value < current.boundary) { - bool ok = rpc.eth_submitWork("0x" + toString(solution.nonce), "0x" + toString(current.headerHash), "0x" + toString(solution.mixHash)); + bool ok = prpc->eth_submitWork("0x" + toString(solution.nonce), "0x" + toString(current.headerHash), "0x" + toString(solution.mixHash)); if (ok) cnote << "B-) Submitted and accepted."; else @@ -885,6 +907,22 @@ private: 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 << endl; + if (m_farmFailOverURL != "") + { + m_farmRetries++; + if (m_farmRetries == m_maxFarmRetries) + { + if (_remote == m_farmURL) { + _remote = m_farmFailOverURL; + prpc = &rpcFailover; + } + else { + _remote = m_farmURL; + prpc = &rpc; + } + m_farmRetries = 0; + } + } } #endif exit(0); @@ -971,6 +1009,10 @@ private: unsigned m_benchmarkBlock = 0; /// Farm params string m_farmURL = "http://127.0.0.1:8545"; + string m_farmFailOverURL = ""; + string m_activeFarmURL = m_farmURL; + unsigned m_farmRetries = 0; + unsigned m_maxFarmRetries = 3; unsigned m_farmRecheckPeriod = 500; bool m_precompute = true; diff --git a/libethcore/EthashAux.cpp b/libethcore/EthashAux.cpp index 3f57cfef2..8147103c1 100644 --- a/libethcore/EthashAux.cpp +++ b/libethcore/EthashAux.cpp @@ -282,7 +282,7 @@ unsigned EthashAux::computeFull(h256 const& _seedHash, bool _createIfMissing) get()->m_fullGenerator = unique_ptr(new thread([=](){ cnote << "Loading full DAG of seedhash: " << _seedHash; get()->full(_seedHash, true, [](unsigned p){ get()->m_fullProgress = p; return 0; }); - eraseDAGs(); // delete any old DAG files + eraseDAGs(); cnote << "Full DAG loaded"; get()->m_fullProgress = 0; get()->m_generatingFullNumber = NotGenerating;