This repository has been archived by the owner on Apr 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Critical amendment to GetWorkClient #1215
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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(); | ||
} | ||
|
||
|
@@ -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 | ||
} | ||
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Really do not know. I only replicated what i believe is the "connected" condition imposed in workloop. I did not write this class. |
||
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. | ||
|
@@ -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 | ||
{ | ||
|
@@ -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()); | ||
|
@@ -139,7 +134,7 @@ void EthGetworkClient::workLoop() | |
//cwarn << "Failed to submit hashrate."; | ||
//cwarn << boost::diagnostic_information(_e); | ||
} | ||
m_currentHashrateToSubmit = ""; | ||
m_currentHashrateToSubmit.clear(); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the
m_justConnected
flag for?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really do not know. I only replicated what i believe is the "connected" condition imposed in workloop. I did not write this class.