Skip to content
This repository was archived by the owner on Apr 24, 2022. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f05145f

Browse files
committedJan 21, 2018
Fix ethereumstratum when job number is >8 chars
The current code assumes the incoming job number will always be 8 hex characters long; this currently breaks with nicehash, which is sending 16 hex character job numbers like '000000047fa89505'. This commit fixes the issue by storing the incoming job number length in WorkPackage and Solution, then using it to truncate the stored job number back to whatever the original length was. It also fixes a closely issue where the padding, which added 56 `0`s, was padding out to 72 characters; the fix here resizes directly to 64 characters, whatever the input size.
1 parent bf95e58 commit f05145f

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed
 

‎libethash-cl/CLMiner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ void CLMiner::report(uint64_t _nonce, WorkPackage const& _w)
271271
// TODO: Why re-evaluating?
272272
Result r = EthashAux::eval(_w.seed, _w.header, _nonce);
273273
if (r.value < _w.boundary)
274-
farm.submitProof(Solution{_nonce, r.mixHash, _w.header, _w.seed, _w.boundary, _w.job, false});
274+
farm.submitProof(Solution{_nonce, r.mixHash, _w.header, _w.seed, _w.boundary, _w.job, _w.job_len, false});
275275
else {
276276
farm.failedSolution();
277277
cwarn << "FAILURE: GPU gave incorrect result!";

‎libethash-cuda/CUDAMiner.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void CUDAMiner::report(uint64_t _nonce, const WorkPackage& w)
5252
// FIXME: This code is exactly the same as in EthashGPUMiner.
5353
Result r = EthashAux::eval(w.seed, w.header, _nonce);
5454
if (r.value < w.boundary)
55-
farm.submitProof(Solution{_nonce, r.mixHash, w.header, w.seed, w.boundary, w.job, m_abort});
55+
farm.submitProof(Solution{_nonce, r.mixHash, w.header, w.seed, w.boundary, w.job, w.job_len, m_abort});
5656
else
5757
{
5858
farm.failedSolution();

‎libethcore/EthashAux.h

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ struct Solution
4040
h256 seedHash;
4141
h256 boundary;
4242
h256 job;
43+
int job_len;
4344
bool stale;
4445
};
4546

@@ -101,6 +102,7 @@ struct WorkPackage
101102

102103
uint64_t startNonce = 0;
103104
int exSizeBits = -1;
105+
int job_len = 8;
104106
};
105107

106108
}

‎libstratum/EthStratumClient.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,13 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
406406
diffToTarget((uint32_t*)m_current.boundary.data(), m_nextWorkDifficulty);
407407
m_current.startNonce = ethash_swap_u64(*((uint64_t*)m_extraNonce.data()));
408408
m_current.exSizeBits = m_extraNonceHexSize * 4;
409+
m_current.job_len = job.size();
409410
if (m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM)
410-
job = job + string(64 - 8, '0');
411+
job.resize(64, '0');
411412
m_current.job = h256(job);
412413

413414
p_farm->setWork(m_current);
414-
cnote << "Received new job #" + job.substr(0, 8)
415+
cnote << "Received new job #" + job.substr(0, m_current.job_len)
415416
<< " seed: " << "#" + m_current.seed.hex().substr(0, 32)
416417
<< " target: " << "#" + m_current.boundary.hex().substr(0, 24);
417418
}
@@ -441,12 +442,10 @@ void EthStratumClient::processReponse(Json::Value& responseObject)
441442
m_current.header = h256(sHeaderHash);
442443
m_current.seed = h256(sSeedHash);
443444
m_current.boundary = h256(sShareTarget);
444-
if (m_protocol == STRATUM_PROTOCOL_ETHEREUMSTRATUM)
445-
job = job + string(64 - 8, '0');
446445
m_current.job = h256(job);
447446

448447
p_farm->setWork(m_current);
449-
cnote << "Received new job #" + job.substr(0, 8)
448+
cnote << "Received new job #" + job.substr(0, m_current.job_len)
450449
<< " seed: " << "#" + m_current.seed.hex().substr(0, 32)
451450
<< " target: " << "#" + m_current.boundary.hex().substr(0, 24);
452451
}
@@ -521,7 +520,7 @@ bool EthStratumClient::submit(Solution solution) {
521520
break;
522521
case STRATUM_PROTOCOL_ETHEREUMSTRATUM:
523522
json = "{\"id\": 4, \"method\": \"mining.submit\", \"params\": [\"" +
524-
p_active->user + "\",\"" + solution.job.hex().substr(0, 8) + "\",\"" +
523+
p_active->user + "\",\"" + solution.job.hex().substr(0, solution.job_len) + "\",\"" +
525524
nonceHex.substr(m_extraNonceHexSize, 16 - m_extraNonceHexSize) + "\"]}\n";
526525
break;
527526
}

0 commit comments

Comments
 (0)