From a823cca7f9817475567d5f3dc2b64ba2445d7ba2 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 19 Feb 2016 15:46:52 +0100 Subject: [PATCH] decred: allow custom extranonce sizes the extranonce is already placed after header in job.coinbase --- Algo256/vanilla.cu | 1 + ccminer.cpp | 14 ++++++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Algo256/vanilla.cu b/Algo256/vanilla.cu index 1b9cc20..d35ade4 100644 --- a/Algo256/vanilla.cu +++ b/Algo256/vanilla.cu @@ -393,6 +393,7 @@ extern "C" int scanhash_vanilla(int thr_id, struct work* work, uint32_t max_nonc } rc = 2; } + pdata[21] = work->nonces[1]; #endif pdata[19] = work->nonces[0]; return rc; diff --git a/ccminer.cpp b/ccminer.cpp index 5a8fa0a..35d01a5 100644 --- a/ccminer.cpp +++ b/ccminer.cpp @@ -1345,8 +1345,8 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work) switch (opt_algo) { case ALGO_DECRED: // getwork over stratum, getwork merkle + header passed in coinb1 - headersize = (int)sctx->job.coinbase_size - 32; memcpy(merkle_root, sctx->job.coinbase, 32); + headersize = min((int)sctx->job.coinbase_size - 32, sizeof(extraheader)); memcpy(extraheader, &sctx->job.coinbase[32], headersize); break; case ALGO_HEAVY: @@ -1385,18 +1385,16 @@ static bool stratum_gen_work(struct stratum_ctx *sctx, struct work *work) work->data[9 + i] = be32dec((uint32_t *)merkle_root + i); if (opt_algo == ALGO_DECRED) { - uint32_t* extradata = (uint32_t*) sctx->xnonce1; for (i = 0; i < 8; i++) // 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] = le32dec(&extraheader[i]); - for (i = 0; i < sctx->xnonce1_size/4; i++) // extradata - work->data[36 + i] = extradata[i]; - work->data[37] = (rand()*4) << 8; - for (int i=39; i < 45; i++) + for (i = 0; i < headersize/4; i++) // header + extradata + work->data[17 + i] = extraheader[i]; + // allow custom extranonce sizes + for (i = 36 + sctx->xnonce1_size/4; i < 45; i++) work->data[i] = 0; + work->data[37] = (rand()*4) << 8; sctx->job.height = work->data[32]; //applog_hex(work->data, 180); } else {