Skip to content

Commit 5b8d627

Browse files
batch rpc requests
1 parent 41391cf commit 5b8d627

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ MinerAcct=0x1234512345123451234512345123451234512345
3030
```
3131
* All other settings in the `[0xBitcoin]` section can be left as is.
3232
* You can also specify the pool mining address on the command line (-N). See below for all command line options.
33-
* If you mining pool supports the **stratum protocol**, change the `RPCPort=8586` line to `StratumPort=9192`. Consult with your mining pool for the actual port #.
33+
* If your mining pool supports the **stratum protocol**, change the `RPCPort=8586` line to `StratumPort=9192`. Consult with your mining pool for the actual port # to use.
3434
* For **Solo Mining**:
3535
* Input an ETH account and associated private key. (Sorry about making you enter it in plain text format. Make sure it is a 'throw away' account with only the bare minimum amount of money.)
3636
* You can specify the address and port of your node in the `.ini` file, or on the command line.

ethminer/FarmClient.h

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,43 @@ class FarmClient : public jsonrpc::Client
6565
}
6666

6767
void getWorkPool(bytes& _challenge, h256& _target, uint64_t& _difficulty, string& _hashingAcct)
68+
{
69+
jsonrpc::BatchCall batchCall = jsonrpc::BatchCall();
70+
71+
Json::Value data;
72+
data.append(m_userAcct);
73+
74+
// the first 2 calls don't need any parameter input, but there seems to be a bug in
75+
// the libjson-rpc-cpp package, such that it produces invalid JSON request if you just
76+
// do something like : batchCall.addCall("getChallengeNumber", Json::Value());
77+
// so I pass in some data which luckily the pool ignores, and sends me the information I want.
78+
79+
int challengeID = batchCall.addCall("getChallengeNumber", data);
80+
int poolAddressID = batchCall.addCall("getPoolEthAddress", data);
81+
int targetID = batchCall.addCall("getMinimumShareTarget", data);
82+
int difficultyID = batchCall.addCall("getMinimumShareDifficulty", data);
83+
84+
jsonrpc::BatchResponse response = CallProcedures(batchCall);
85+
86+
if (response.hasErrors())
87+
{
88+
LogB << "Error in getWorkPool: JSON-RPC call resulted in errors";
89+
}
90+
91+
_challenge = fromHex(response.getResult(challengeID).asString());
92+
m_target = u256(response.getResult(targetID).asString());
93+
m_hashingAcct = response.getResult(poolAddressID).asString();
94+
m_difficulty = atoll(response.getResult(difficultyID).asString().c_str());
95+
96+
_target = m_target;
97+
_difficulty = m_difficulty;
98+
_hashingAcct = m_hashingAcct;
99+
LogF << "Trace: getWorkPool - challenge:" << toHex(_challenge).substr(0, 8)
100+
<< ", target:" << std::hex << std::setw(16) << std::setfill('0') << upper64OfHash(_target)
101+
<< ", difficulty:" << std::dec << _difficulty;
102+
}
103+
104+
void getWorkPool_old(bytes& _challenge, h256& _target, uint64_t& _difficulty, string& _hashingAcct)
68105
{
69106
static Timer s_lastFetch;
70107
Json::Value data;
@@ -74,7 +111,7 @@ class FarmClient : public jsonrpc::Client
74111
data.append(m_userAcct);
75112
result = CallMethod("getMinimumShareTarget", data);
76113
m_target = u256(result.asString());
77-
114+
78115
if (s_lastFetch.elapsedSeconds() > 20 || m_hashingAcct == "")
79116
{
80117
// no reason to retrieve this stuff every time.
@@ -88,8 +125,8 @@ class FarmClient : public jsonrpc::Client
88125
_target = m_target;
89126
_difficulty = m_difficulty;
90127
_hashingAcct = m_hashingAcct;
91-
LogF << "Trace: getWorkPool - challenge:" << toHex(_challenge).substr(0, 8)
92-
<< ", target:" << std::hex << std::setw(16) << std::setfill('0') << upper64OfHash(_target)
128+
LogF << "Trace: getWorkPool - challenge:" << toHex(_challenge).substr(0, 8)
129+
<< ", target:" << std::hex << std::setw(16) << std::setfill('0') << upper64OfHash(_target)
93130
<< ", difficulty:" << std::dec << _difficulty;
94131
}
95132

0 commit comments

Comments
 (0)