@@ -8,12 +8,13 @@ using namespace std;
8
8
using namespace dev ;
9
9
using namespace eth ;
10
10
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 )
12
12
{
13
13
m_farmRecheckPeriod = farmRecheckPeriod;
14
14
m_authorized = true ;
15
15
m_connection_changed = true ;
16
- m_solutionToSubmit.nonce = 0 ;
16
+ if (m_submit_hashrate)
17
+ m_client_id = h256::random ();
17
18
startWorking ();
18
19
}
19
20
@@ -32,9 +33,6 @@ void EthGetworkClient::connect()
32
33
p_client = new ::JsonrpcGetwork (new jsonrpc::HttpClient (ss.str ()));
33
34
}
34
35
35
- // cnote << "connect to " << m_host;
36
-
37
- m_client_id = h256::random ();
38
36
m_connection_changed = false ;
39
37
m_justConnected = true ; // We set a fake flag, that we can check with workhandler if connection works
40
38
}
@@ -53,13 +51,35 @@ void EthGetworkClient::disconnect()
53
51
void EthGetworkClient::submitHashrate (string const & rate)
54
52
{
55
53
// Store the rate in temp var. Will be handled in workLoop
54
+ // Hashrate submission does not need to be as quick as possible
56
55
m_currentHashrateToSubmit = rate;
56
+
57
57
}
58
58
59
59
void EthGetworkClient::submitSolution (Solution solution)
60
60
{
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
+ }
63
83
}
64
84
65
85
// Handles all getwork communication.
@@ -69,31 +89,6 @@ void EthGetworkClient::workLoop()
69
89
{
70
90
if (m_connected || m_justConnected) {
71
91
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
-
97
92
// Get Work
98
93
try
99
94
{
@@ -129,7 +124,7 @@ void EthGetworkClient::workLoop()
129
124
}
130
125
131
126
// Submit current hashrate if needed
132
- if (!m_currentHashrateToSubmit.empty ()) {
127
+ if (m_submit_hashrate && !m_currentHashrateToSubmit.empty ()) {
133
128
try
134
129
{
135
130
p_client->eth_submitHashrate (m_currentHashrateToSubmit, " 0x" + m_client_id.hex ());
@@ -139,7 +134,7 @@ void EthGetworkClient::workLoop()
139
134
// cwarn << "Failed to submit hashrate.";
140
135
// cwarn << boost::diagnostic_information(_e);
141
136
}
142
- m_currentHashrateToSubmit = " " ;
137
+ m_currentHashrateToSubmit. clear () ;
143
138
}
144
139
}
145
140
0 commit comments