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

Commit cff0dc6

Browse files
AndreaLanfranchichfast
authored andcommittedJun 5, 2018
Minimal amendment to GetWorkClient
Addresses #1213 - Solution submit is immediate upon arrival and is no influenced by --farm-recheck value - Submission of hashrate is conditional - Renamed m_report_stratum_hashrate to m_report_hashrate as it's valid for both modes Now even sligtly higher --farm-recheck values may be applied to mitigate overhead.
1 parent 90c9f61 commit cff0dc6

File tree

3 files changed

+38
-40
lines changed

3 files changed

+38
-40
lines changed
 

‎ethminer/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class MinerCLI
171171
->group(CommonGroup)
172172
->check(CLI::Range(2, 999));
173173

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

@@ -670,10 +670,10 @@ class MinerCLI
670670
PoolClient *client = nullptr;
671671

672672
if (m_mode == OperationMode::Stratum) {
673-
client = new EthStratumClient(m_io_service, m_worktimeout, m_responsetimeout, m_email, m_report_stratum_hashrate);
673+
client = new EthStratumClient(m_io_service, m_worktimeout, m_responsetimeout, m_email, m_report_hashrate);
674674
}
675675
else if (m_mode == OperationMode::Farm) {
676-
client = new EthGetworkClient(m_farmRecheckPeriod);
676+
client = new EthGetworkClient(m_farmRecheckPeriod, m_report_hashrate);
677677
}
678678
else if (m_mode == OperationMode::Simulation) {
679679
client = new SimulateClient(20, m_benchmarkBlock);
@@ -808,7 +808,7 @@ class MinerCLI
808808
unsigned m_http_port = 0;
809809
#endif
810810

811-
bool m_report_stratum_hashrate = false;
811+
bool m_report_hashrate = false;
812812
string m_email;
813813

814814
#if ETH_DBUS

‎libpoolprotocols/getwork/EthGetworkClient.cpp

+29-34
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ using namespace std;
88
using namespace dev;
99
using namespace eth;
1010

11-
EthGetworkClient::EthGetworkClient(unsigned const & farmRecheckPeriod) : PoolClient(), Worker("getwork")
11+
EthGetworkClient::EthGetworkClient(unsigned const & farmRecheckPeriod, bool const & submitHashrate) : PoolClient(), Worker("getwork"), m_submit_hashrate(submitHashrate)
1212
{
1313
m_farmRecheckPeriod = farmRecheckPeriod;
1414
m_authorized = true;
1515
m_connection_changed = true;
16-
m_solutionToSubmit.nonce = 0;
16+
if (m_submit_hashrate)
17+
m_client_id = h256::random();
1718
startWorking();
1819
}
1920

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

35-
// cnote << "connect to " << m_host;
36-
37-
m_client_id = h256::random();
3836
m_connection_changed = false;
3937
m_justConnected = true; // We set a fake flag, that we can check with workhandler if connection works
4038
}
@@ -53,13 +51,35 @@ void EthGetworkClient::disconnect()
5351
void EthGetworkClient::submitHashrate(string const & rate)
5452
{
5553
// Store the rate in temp var. Will be handled in workLoop
54+
// Hashrate submission does not need to be as quick as possible
5655
m_currentHashrateToSubmit = rate;
56+
5757
}
5858

5959
void EthGetworkClient::submitSolution(Solution solution)
6060
{
61-
// Store the solution in temp var. Will be handled in workLoop
62-
m_solutionToSubmit = solution;
61+
// Immediately send found solution without wait for loop
62+
if (m_connected || m_justConnected) {
63+
try
64+
{
65+
bool accepted = p_client->eth_submitWork("0x" + toHex(solution.nonce), "0x" + toString(solution.work.header), "0x" + toString(solution.mixHash));
66+
if (accepted) {
67+
if (m_onSolutionAccepted) {
68+
m_onSolutionAccepted(false);
69+
}
70+
}
71+
else {
72+
if (m_onSolutionRejected) {
73+
m_onSolutionRejected(false);
74+
}
75+
}
76+
}
77+
catch (jsonrpc::JsonRpcException const& _e)
78+
{
79+
cwarn << "Failed to submit solution.";
80+
cwarn << boost::diagnostic_information(_e);
81+
}
82+
}
6383
}
6484

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

72-
// Submit solution
73-
if (m_solutionToSubmit.nonce) {
74-
try
75-
{
76-
bool accepted = p_client->eth_submitWork("0x" + toHex(m_solutionToSubmit.nonce), "0x" + toString(m_solutionToSubmit.work.header), "0x" + toString(m_solutionToSubmit.mixHash));
77-
if (accepted) {
78-
if (m_onSolutionAccepted) {
79-
m_onSolutionAccepted(false);
80-
}
81-
}
82-
else {
83-
if (m_onSolutionRejected) {
84-
m_onSolutionRejected(false);
85-
}
86-
}
87-
88-
m_solutionToSubmit.nonce = 0;
89-
}
90-
catch (jsonrpc::JsonRpcException const& _e)
91-
{
92-
cwarn << "Failed to submit solution.";
93-
cwarn << boost::diagnostic_information(_e);
94-
}
95-
}
96-
9792
// Get Work
9893
try
9994
{
@@ -129,7 +124,7 @@ void EthGetworkClient::workLoop()
129124
}
130125

131126
// Submit current hashrate if needed
132-
if (!m_currentHashrateToSubmit.empty()) {
127+
if (m_submit_hashrate && !m_currentHashrateToSubmit.empty()) {
133128
try
134129
{
135130
p_client->eth_submitHashrate(m_currentHashrateToSubmit, "0x" + m_client_id.hex());
@@ -139,7 +134,7 @@ void EthGetworkClient::workLoop()
139134
//cwarn << "Failed to submit hashrate.";
140135
//cwarn << boost::diagnostic_information(_e);
141136
}
142-
m_currentHashrateToSubmit = "";
137+
m_currentHashrateToSubmit.clear();
143138
}
144139
}
145140

‎libpoolprotocols/getwork/EthGetworkClient.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using namespace eth;
1313
class EthGetworkClient : public PoolClient, Worker
1414
{
1515
public:
16-
EthGetworkClient(unsigned const & farmRecheckPeriod);
16+
EthGetworkClient(unsigned const & farmRecheckPeriod, bool const & submitHashrate);
1717
~EthGetworkClient();
1818

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

3434
string m_currentHashrateToSubmit = "";
35-
Solution m_solutionToSubmit;
35+
3636
bool m_justConnected = false;
3737
h256 m_client_id;
3838
JsonrpcGetwork *p_client;
3939
WorkPackage m_prevWorkPackage;
40+
41+
// Hashrate submission is optional
42+
bool m_submit_hashrate;
4043
};

0 commit comments

Comments
 (0)
This repository has been archived.