Browse Source

Provide hash rate according to interface in #2737.

Closed #2737.
cl-refactor
Gav Wood 10 years ago
parent
commit
ef1be85649
  1. 39
      ethminer/Farm.h
  2. 13
      ethminer/MinerAux.h
  3. 3
      ethminer/farm.json
  4. 5
      libethereum/Client.cpp
  5. 23
      libethereum/ClientBase.cpp
  6. 7
      libethereum/ClientBase.h
  7. 3
      libethereum/Interface.h
  8. 6
      libweb3jsonrpc/WebThreeStubServerBase.cpp
  9. 2
      libweb3jsonrpc/WebThreeStubServerBase.h

39
ethminer/Farm.h

@ -1,39 +0,0 @@
/**
* This file is generated by jsonrpcstub, DO NOT CHANGE IT MANUALLY!
*/
#ifndef JSONRPC_CPP_STUB_FARM_H_
#define JSONRPC_CPP_STUB_FARM_H_
#include <jsonrpccpp/client.h>
class Farm : public jsonrpc::Client
{
public:
Farm(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {}
Json::Value eth_getWork() throw (jsonrpc::JsonRpcException)
{
Json::Value p;
p = Json::nullValue;
Json::Value result = this->CallMethod("eth_getWork",p);
if (result.isArray())
return result;
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
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();
else
throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString());
}
};
#endif //JSONRPC_CPP_STUB_FARM_H_

13
ethminer/MinerAux.h

@ -52,7 +52,7 @@
#include "BuildInfo.h" #include "BuildInfo.h"
#if ETH_JSONRPC || !ETH_TRUE #if ETH_JSONRPC || !ETH_TRUE
#include "PhoneHome.h" #include "PhoneHome.h"
#include "Farm.h" #include "FarmClient.h"
#endif #endif
using namespace std; using namespace std;
using namespace dev; using namespace dev;
@ -482,7 +482,8 @@ private:
#if ETH_JSONRPC || !ETH_TRUE #if ETH_JSONRPC || !ETH_TRUE
jsonrpc::HttpClient client(_remote); jsonrpc::HttpClient client(_remote);
Farm rpc(client); h256 id = h256::random();
::FarmClient rpc(client);
GenericFarm<EthashProofOfWork> f; GenericFarm<EthashProofOfWork> f;
f.setSealers(sealers); f.setSealers(sealers);
if (_m == MinerType::CPU) if (_m == MinerType::CPU)
@ -504,10 +505,16 @@ private:
}); });
for (unsigned i = 0; !completed; ++i) for (unsigned i = 0; !completed; ++i)
{ {
auto mp = f.miningProgress();
f.resetMiningProgress();
if (current) if (current)
minelog << "Mining on PoWhash" << current.headerHash << ": " << f.miningProgress(); minelog << "Mining on PoWhash" << current.headerHash << ": " << mp;
else else
minelog << "Getting work package..."; minelog << "Getting work package...";
auto rate = mp.rate();
rpc.eth_submitHashrate((int)rate, "0x" + id.hex());
Json::Value v = rpc.eth_getWork(); Json::Value v = rpc.eth_getWork();
h256 hh(v[0].asString()); h256 hh(v[0].asString());
h256 newSeedHash(v[1].asString()); h256 newSeedHash(v[1].asString());

3
ethminer/farm.json

@ -1,6 +1,7 @@
[ [
{ "name": "eth_getWork", "params": [], "order": [], "returns": []}, { "name": "eth_getWork", "params": [], "order": [], "returns": []},
{ "name": "eth_submitWork", "params": ["", "", ""], "order": [], "returns": true} { "name": "eth_submitWork", "params": ["", "", ""], "order": [], "returns": true},
{ "name": "eth_submitHashrate", "params": [0, ""], "order": [], "returns": true},
{ "name": "eth_awaitNewWork", "params": [], "order": [], "returns": []}, { "name": "eth_awaitNewWork", "params": [], "order": [], "returns": []},
{ "name": "eth_progress", "params": [], "order": [], "returns": true} { "name": "eth_progress", "params": [], "order": [], "returns": true}
] ]

5
libethereum/Client.cpp

@ -503,9 +503,10 @@ WorkingProgress Client::miningProgress() const
uint64_t Client::hashrate() const uint64_t Client::hashrate() const
{ {
uint64_t r = externalHashrate();
if (Ethash::isWorking(m_sealEngine.get())) if (Ethash::isWorking(m_sealEngine.get()))
return Ethash::workingProgress(m_sealEngine.get()).rate(); r += Ethash::workingProgress(m_sealEngine.get()).rate();
return 0; return r;
} }
std::list<MineInfo> Client::miningHistory() std::list<MineInfo> Client::miningHistory()

23
libethereum/ClientBase.cpp

@ -21,7 +21,7 @@
*/ */
#include "ClientBase.h" #include "ClientBase.h"
#include <algorithm>
#include <libdevcore/StructuredLogger.h> #include <libdevcore/StructuredLogger.h>
#include "BlockChain.h" #include "BlockChain.h"
#include "Executive.h" #include "Executive.h"
@ -492,11 +492,10 @@ int ClientBase::compareBlockHashes(h256 _h1, h256 _h2) const
BlockNumber n1 = numberFromHash(_h1); BlockNumber n1 = numberFromHash(_h1);
BlockNumber n2 = numberFromHash(_h2); BlockNumber n2 = numberFromHash(_h2);
if (n1 > n2) { if (n1 > n2)
return 1; return 1;
} else if (n1 == n2) { else if (n1 == n2)
return 0; return 0;
}
return -1; return -1;
} }
@ -524,3 +523,19 @@ bool ClientBase::isKnownTransaction(h256 const& _blockHash, unsigned _i) const
{ {
return isKnown(_blockHash) && bc().transactions().size() > _i; return isKnown(_blockHash) && bc().transactions().size() > _i;
} }
void ClientBase::submitExternalHashrate(int _rate, h256 const& _id)
{
m_externalRates[_id] = make_pair(_rate, chrono::steady_clock::now());
}
uint64_t ClientBase::externalHashrate() const
{
uint64_t ret = 0;
for (auto i = m_externalRates.begin(); i != m_externalRates.end();)
if (chrono::steady_clock::now() - i->second.second > chrono::seconds(5))
i = m_externalRates.erase(i);
else
ret += i++->second.first;
return ret;
}

7
libethereum/ClientBase.h

@ -166,6 +166,8 @@ public:
virtual uint64_t hashrate() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::hashrate")); } virtual uint64_t hashrate() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::hashrate")); }
virtual WorkingProgress miningProgress() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::miningProgress")); } virtual WorkingProgress miningProgress() const override { BOOST_THROW_EXCEPTION(InterfaceNotSupported("ClientBase::miningProgress")); }
virtual void submitExternalHashrate(int _rate, h256 const& _id) override;
Block asOf(BlockNumber _h) const; Block asOf(BlockNumber _h) const;
protected: protected:
@ -179,6 +181,8 @@ protected:
virtual void prepareForTransaction() = 0; virtual void prepareForTransaction() = 0;
/// } /// }
uint64_t externalHashrate() const;
TransactionQueue m_tq; ///< Maintains a list of incoming transactions not yet in a block on the blockchain. TransactionQueue m_tq; ///< Maintains a list of incoming transactions not yet in a block on the blockchain.
// filters // filters
@ -187,6 +191,9 @@ protected:
std::unordered_map<h256, h256s> m_specialFilters = std::unordered_map<h256, std::vector<h256>>{{PendingChangedFilter, {}}, {ChainChangedFilter, {}}}; std::unordered_map<h256, h256s> m_specialFilters = std::unordered_map<h256, std::vector<h256>>{{PendingChangedFilter, {}}, {ChainChangedFilter, {}}};
///< The dictionary of special filters and their additional data ///< The dictionary of special filters and their additional data
std::map<unsigned, ClientWatch> m_watches; ///< Each and every watch - these reference a filter. std::map<unsigned, ClientWatch> m_watches; ///< Each and every watch - these reference a filter.
// external hashrate
mutable std::unordered_map<h256, std::pair<uint64_t, std::chrono::steady_clock::time_point>> m_externalRates;
}; };
}} }}

3
libethereum/Interface.h

@ -215,7 +215,8 @@ public:
virtual std::tuple<h256, h256, h256> getEthashWork() { BOOST_THROW_EXCEPTION(InterfaceNotSupported("Interface::getEthashWork")); } virtual std::tuple<h256, h256, h256> getEthashWork() { BOOST_THROW_EXCEPTION(InterfaceNotSupported("Interface::getEthashWork")); }
/// Submit the nonce for the proof-of-work. /// Submit the nonce for the proof-of-work.
virtual bool submitEthashWork(h256 const&, h64 const&) { BOOST_THROW_EXCEPTION(InterfaceNotSupported("Interface::submitEthashWork")); } virtual bool submitEthashWork(h256 const&, h64 const&) { BOOST_THROW_EXCEPTION(InterfaceNotSupported("Interface::submitEthashWork")); }
/// Submit the ongoing hashrate of a particular external miner.
virtual void submitExternalHashrate(int, h256 const&) { BOOST_THROW_EXCEPTION(InterfaceNotSupported("Interface::submitExternalHashrate")); }
/// Check the progress of the mining. /// Check the progress of the mining.
virtual WorkingProgress miningProgress() const = 0; virtual WorkingProgress miningProgress() const = 0;

6
libweb3jsonrpc/WebThreeStubServerBase.cpp

@ -784,10 +784,10 @@ bool WebThreeStubServerBase::eth_submitWork(string const& _nonce, string const&,
} }
} }
void WebThreeStubServerBase::eth_submitHashrate(int _hashes, string const& _id) bool WebThreeStubServerBase::eth_submitHashrate(int _hashes, string const& _id)
{ {
(void)_hashes; (void)_id; client()->submitExternalHashrate(_hashes, jsToFixed<32>(_id));
// client()->submitExternalHashrate(_hashes, jsToFixed<32>(_id)); return true;
} }
string WebThreeStubServerBase::eth_register(string const& _address) string WebThreeStubServerBase::eth_register(string const& _address)

2
libweb3jsonrpc/WebThreeStubServerBase.h

@ -139,7 +139,7 @@ public:
virtual Json::Value eth_getLogsEx(Json::Value const& _json); virtual Json::Value eth_getLogsEx(Json::Value const& _json);
virtual Json::Value eth_getWork(); virtual Json::Value eth_getWork();
virtual bool eth_submitWork(std::string const& _nonce, std::string const&, std::string const& _mixHash); virtual bool eth_submitWork(std::string const& _nonce, std::string const&, std::string const& _mixHash);
virtual void eth_submitHashrate(int _hashes, std::string const& _id); virtual bool eth_submitHashrate(int _hashes, std::string const& _id);
virtual std::string eth_register(std::string const& _address); virtual std::string eth_register(std::string const& _address);
virtual bool eth_unregister(std::string const& _accountId); virtual bool eth_unregister(std::string const& _accountId);
virtual Json::Value eth_fetchQueuedTransactions(std::string const& _accountId); virtual Json::Value eth_fetchQueuedTransactions(std::string const& _accountId);

Loading…
Cancel
Save