Skip to content
This repository has been archived by the owner on Apr 24, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1215 from ethereum-mining/getwork
Browse files Browse the repository at this point in the history
Critical amendment to GetWorkClient
  • Loading branch information
AndreaLanfranchi authored Jun 5, 2018
2 parents 8007673 + f2734e6 commit ceb9813
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Stratum nicehash. Avoid recalculating target with every job [#1156](https://github.com/ethereum-mining/ethminer/pull/1156).
- Drop duplicate stratum jobs (pool bug workaround) [#1161](https://github.com/ethereum-mining/ethminer/pull/1161).
- CLI11 command line parsing support added [#1160](https://github.com/ethereum-mining/ethminer/pull/1160).
- Farm mode (get_work): fixed loss of valid shares and increment in stales [#1215](https://github.com/ethereum-mining/ethminer/pull/1215).
- Build fixes & improvements [#1214](https://github.com/ethereum-mining/ethminer/pull/1214).
### Removed
- Disabled Debug configuration for Visual Studio [#69](https://github.com/ethereum-mining/ethminer/issues/69) [#1131](https://github.com/ethereum-mining/ethminer/pull/1131).
8 changes: 4 additions & 4 deletions ethminer/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class MinerCLI
->group(CommonGroup)
->check(CLI::Range(2, 999));

app.add_flag("-R,--report-hashrate", m_report_stratum_hashrate,
app.add_flag("-R,--report-hashrate", m_report_hashrate,
"Report current hashrate to pool")
->group(CommonGroup);

Expand Down Expand Up @@ -670,10 +670,10 @@ class MinerCLI
PoolClient *client = nullptr;

if (m_mode == OperationMode::Stratum) {
client = new EthStratumClient(m_io_service, m_worktimeout, m_responsetimeout, m_email, m_report_stratum_hashrate);
client = new EthStratumClient(m_io_service, m_worktimeout, m_responsetimeout, m_email, m_report_hashrate);
}
else if (m_mode == OperationMode::Farm) {
client = new EthGetworkClient(m_farmRecheckPeriod);
client = new EthGetworkClient(m_farmRecheckPeriod, m_report_hashrate);
}
else if (m_mode == OperationMode::Simulation) {
client = new SimulateClient(20, m_benchmarkBlock);
Expand Down Expand Up @@ -808,7 +808,7 @@ class MinerCLI
unsigned m_http_port = 0;
#endif

bool m_report_stratum_hashrate = false;
bool m_report_hashrate = false;
string m_email;

#if ETH_DBUS
Expand Down
63 changes: 29 additions & 34 deletions libpoolprotocols/getwork/EthGetworkClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ using namespace std;
using namespace dev;
using namespace eth;

EthGetworkClient::EthGetworkClient(unsigned const & farmRecheckPeriod) : PoolClient(), Worker("getwork")
EthGetworkClient::EthGetworkClient(unsigned farmRecheckPeriod, bool submitHashrate) : PoolClient(), Worker("getwork"), m_submit_hashrate(submitHashrate)
{
m_farmRecheckPeriod = farmRecheckPeriod;
m_authorized = true;
m_connection_changed = true;
m_solutionToSubmit.nonce = 0;
if (m_submit_hashrate)
m_client_id = h256::random();
startWorking();
}

Expand All @@ -32,9 +33,6 @@ void EthGetworkClient::connect()
p_client = new ::JsonrpcGetwork(new jsonrpc::HttpClient(ss.str()));
}

// cnote << "connect to " << m_host;

m_client_id = h256::random();
m_connection_changed = false;
m_justConnected = true; // We set a fake flag, that we can check with workhandler if connection works
}
Expand All @@ -53,13 +51,35 @@ void EthGetworkClient::disconnect()
void EthGetworkClient::submitHashrate(string const & rate)
{
// Store the rate in temp var. Will be handled in workLoop
// Hashrate submission does not need to be as quick as possible
m_currentHashrateToSubmit = rate;

}

void EthGetworkClient::submitSolution(Solution solution)
{
// Store the solution in temp var. Will be handled in workLoop
m_solutionToSubmit = solution;
// Immediately send found solution without wait for loop
if (m_connected || m_justConnected) {
try
{
bool accepted = p_client->eth_submitWork("0x" + toHex(solution.nonce), "0x" + toString(solution.work.header), "0x" + toString(solution.mixHash));
if (accepted) {
if (m_onSolutionAccepted) {
m_onSolutionAccepted(false);
}
}
else {
if (m_onSolutionRejected) {
m_onSolutionRejected(false);
}
}
}
catch (jsonrpc::JsonRpcException const& _e)
{
cwarn << "Failed to submit solution.";
cwarn << boost::diagnostic_information(_e);
}
}
}

// Handles all getwork communication.
Expand All @@ -69,31 +89,6 @@ void EthGetworkClient::workLoop()
{
if (m_connected || m_justConnected) {

// Submit solution
if (m_solutionToSubmit.nonce) {
try
{
bool accepted = p_client->eth_submitWork("0x" + toHex(m_solutionToSubmit.nonce), "0x" + toString(m_solutionToSubmit.work.header), "0x" + toString(m_solutionToSubmit.mixHash));
if (accepted) {
if (m_onSolutionAccepted) {
m_onSolutionAccepted(false);
}
}
else {
if (m_onSolutionRejected) {
m_onSolutionRejected(false);
}
}

m_solutionToSubmit.nonce = 0;
}
catch (jsonrpc::JsonRpcException const& _e)
{
cwarn << "Failed to submit solution.";
cwarn << boost::diagnostic_information(_e);
}
}

// Get Work
try
{
Expand Down Expand Up @@ -129,7 +124,7 @@ void EthGetworkClient::workLoop()
}

// Submit current hashrate if needed
if (!m_currentHashrateToSubmit.empty()) {
if (m_submit_hashrate && !m_currentHashrateToSubmit.empty()) {
try
{
p_client->eth_submitHashrate(m_currentHashrateToSubmit, "0x" + m_client_id.hex());
Expand All @@ -139,7 +134,7 @@ void EthGetworkClient::workLoop()
//cwarn << "Failed to submit hashrate.";
//cwarn << boost::diagnostic_information(_e);
}
m_currentHashrateToSubmit = "";
m_currentHashrateToSubmit.clear();
}
}

Expand Down
7 changes: 5 additions & 2 deletions libpoolprotocols/getwork/EthGetworkClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using namespace eth;
class EthGetworkClient : public PoolClient, Worker
{
public:
EthGetworkClient(unsigned const & farmRecheckPeriod);
EthGetworkClient(unsigned farmRecheckPeriod, bool submitHashrate);
~EthGetworkClient();

void connect() override;
Expand All @@ -32,9 +32,12 @@ class EthGetworkClient : public PoolClient, Worker
unsigned m_farmRecheckPeriod = 500;

string m_currentHashrateToSubmit = "";
Solution m_solutionToSubmit;

bool m_justConnected = false;
h256 m_client_id;
JsonrpcGetwork *p_client;
WorkPackage m_prevWorkPackage;

// Hashrate submission is optional
bool m_submit_hashrate;
};

0 comments on commit ceb9813

Please sign in to comment.