|
|
|
@ -1324,9 +1324,8 @@ err_out:
@@ -1324,9 +1324,8 @@ err_out:
|
|
|
|
|
|
|
|
|
|
static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work) |
|
|
|
|
{ |
|
|
|
|
uint32_t extraheader[32] = { 0 }; |
|
|
|
|
uchar merkle_root[64] = { 0 }; |
|
|
|
|
int i, headersize = 0; |
|
|
|
|
int i; |
|
|
|
|
|
|
|
|
|
if (!sctx->job.job_id) { |
|
|
|
|
// applog(LOG_WARNING, "stratum_gen_work: job not yet retrieved");
|
|
|
|
@ -1349,10 +1348,7 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
@@ -1349,10 +1348,7 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
|
|
|
|
|
/* Generate merkle root */ |
|
|
|
|
switch (opt_algo) { |
|
|
|
|
case ALGO_DECRED: |
|
|
|
|
// getwork over stratum, getwork merkle + header passed in coinb1
|
|
|
|
|
memcpy(merkle_root, sctx->job.coinbase, 32); |
|
|
|
|
headersize = min((int)sctx->job.coinbase_size - 32, sizeof(extraheader)); |
|
|
|
|
memcpy(extraheader, &sctx->job.coinbase[32], headersize); |
|
|
|
|
// getwork over stratum, no merkle to generate
|
|
|
|
|
break; |
|
|
|
|
case ALGO_HEAVY: |
|
|
|
|
case ALGO_MJOLLNIR: |
|
|
|
@ -1374,7 +1370,7 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
@@ -1374,7 +1370,7 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
|
|
|
|
|
memcpy(merkle_root + 32, sctx->job.merkle[i], 32); |
|
|
|
|
if (opt_algo == ALGO_HEAVY || opt_algo == ALGO_MJOLLNIR) |
|
|
|
|
heavycoin_hash(merkle_root, merkle_root, 64); |
|
|
|
|
else if (!headersize) |
|
|
|
|
else |
|
|
|
|
sha256d(merkle_root, merkle_root, 64); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -1386,26 +1382,25 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
@@ -1386,26 +1382,25 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work)
|
|
|
|
|
work->data[0] = le32dec(sctx->job.version); |
|
|
|
|
for (i = 0; i < 8; i++) |
|
|
|
|
work->data[1 + i] = le32dec((uint32_t *)sctx->job.prevhash + i); |
|
|
|
|
for (i = 0; i < 8; i++) |
|
|
|
|
work->data[9 + i] = be32dec((uint32_t *)merkle_root + i); |
|
|
|
|
|
|
|
|
|
if (opt_algo == ALGO_DECRED) { |
|
|
|
|
for (i = 0; i < 8; i++) // prevhash
|
|
|
|
|
for (i = 0; i < 8; i++) // reversed prevhash
|
|
|
|
|
work->data[1 + i] = swab32(work->data[1 + i]); |
|
|
|
|
for (i = 0; i < 8; i++) // merkle
|
|
|
|
|
work->data[9 + i] = swab32(work->data[9 + i]); |
|
|
|
|
for (i = 0; i < headersize/4; i++) // header
|
|
|
|
|
work->data[17 + i] = extraheader[i]; |
|
|
|
|
// decred header (coinb1) [merkle...nonce]
|
|
|
|
|
memcpy(&work->data[9], sctx->job.coinbase, 112); |
|
|
|
|
// extradata
|
|
|
|
|
uint32_t* extradata = (uint32_t*) sctx->xnonce1; |
|
|
|
|
for (i = 0; i < sctx->xnonce1_size/4; i++) |
|
|
|
|
work->data[36 + i] = extradata[i]; |
|
|
|
|
for (i = 36 + sctx->xnonce1_size/4; i < 45; i++) |
|
|
|
|
work->data[i] = 0; |
|
|
|
|
work->data[37] = (rand()*4) << 8; |
|
|
|
|
if (sctx->xnonce1_size > sizeof(work->data)-(36*4)) { |
|
|
|
|
// should never happen...
|
|
|
|
|
applog(LOG_ERR, "extranonce size overflow!"); |
|
|
|
|
sctx->xnonce1_size = sizeof(work->data)-(36*4); |
|
|
|
|
} |
|
|
|
|
memcpy(&work->data[36], sctx->xnonce1, sctx->xnonce1_size); |
|
|
|
|
work->data[37] = (rand()*4) << 8; // random work data
|
|
|
|
|
sctx->job.height = work->data[32]; |
|
|
|
|
//applog_hex(work->data, 180);
|
|
|
|
|
} else { |
|
|
|
|
for (i = 0; i < 8; i++) |
|
|
|
|
work->data[9 + i] = be32dec((uint32_t *)merkle_root + i); |
|
|
|
|
work->data[17] = le32dec(sctx->job.ntime); |
|
|
|
|
work->data[18] = le32dec(sctx->job.nbits); |
|
|
|
|
work->data[20] = 0x80000000; |
|
|
|
|