From c542e47aa327bb046cf4327aec0b32176d47d796 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 12 Aug 2013 10:49:38 +1000 Subject: [PATCH] Use a nonce2 offset variable for both gbt and stratum to consolidate requirements on work generation. --- cgminer.c | 15 ++++++++------- miner.h | 4 +++- util.c | 1 + 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/cgminer.c b/cgminer.c index fc259c64..1a832829 100644 --- a/cgminer.c +++ b/cgminer.c @@ -1698,7 +1698,7 @@ static void gen_gbt_work(struct pool *pool, struct work *work) update_gbt(pool); cg_wlock(&pool->gbt_lock); - memcpy(pool->gbt_coinbase + 42 + pool->orig_len, &pool->nonce2, 4); + memcpy(pool->gbt_coinbase + pool->nonce2_offset, &pool->nonce2, 4); pool->nonce2++; cg_dwlock(&pool->gbt_lock); merkleroot = __gbt_merkleroot(pool); @@ -1758,7 +1758,7 @@ static bool gbt_decode(struct pool *pool, json_t *res_val) bool submitold; const char *bits; const char *workid; - int cbt_len; + int cbt_len, orig_len; uint8_t *extra_len; size_t cal_len; @@ -1805,11 +1805,12 @@ static bool gbt_decode(struct pool *pool, json_t *res_val) quit(1, "Failed to calloc pool gbt_coinbase in gbt_decode"); hex2bin(pool->gbt_coinbase, pool->coinbasetxn, 42); extra_len = (uint8_t *)(pool->gbt_coinbase + 41); - pool->orig_len = *extra_len; - hex2bin(pool->gbt_coinbase + 42, pool->coinbasetxn + 84, pool->orig_len); + orig_len = *extra_len; + hex2bin(pool->gbt_coinbase + 42, pool->coinbasetxn + 84, orig_len); *extra_len += 4; - hex2bin(pool->gbt_coinbase + 42 + *extra_len, pool->coinbasetxn + 84 + (pool->orig_len * 2), - cbt_len - pool->orig_len - 42); + hex2bin(pool->gbt_coinbase + 42 + *extra_len, pool->coinbasetxn + 84 + (orig_len * 2), + cbt_len - orig_len - 42); + pool->nonce2_offset = orig_len + 42; free(pool->longpollid); pool->longpollid = strdup(longpollid); @@ -5606,7 +5607,7 @@ static void gen_stratum_work(struct pool *pool, struct work *work) quit(1, "Failed to calloc coinbase in gen_stratum_work"); memcpy(coinbase, pool->swork.cb1, pool->swork.cb1_len); memcpy(coinbase + pool->swork.cb1_len, pool->nonce1bin, pool->n1_len); - hex2bin(coinbase + pool->swork.cb1_len + pool->n1_len, work->nonce2, pool->n2size); + hex2bin(coinbase + pool->nonce2_offset, work->nonce2, pool->n2size); memcpy(coinbase + pool->swork.cb1_len + pool->n1_len + pool->n2size, pool->swork.cb2, pool->swork.cb2_len); /* Generate merkle root */ diff --git a/miner.h b/miner.h index 500ecb90..2ba39d61 100644 --- a/miner.h +++ b/miner.h @@ -1182,6 +1182,7 @@ struct pool { char *sockbuf; size_t sockbuf_size; char *sockaddr_url; /* stripped url used for sockaddr */ + char *stratum_coinbase; char *nonce1; unsigned char *nonce1bin; size_t n1_len; @@ -1215,8 +1216,9 @@ struct pool { unsigned char *txn_hashes; int gbt_txns; int coinbase_len; - int orig_len; + /* Shared by both stratum & GBT */ + int nonce2_offset; struct timeval tv_lastwork; }; diff --git a/util.c b/util.c index 81008f38..1f7fbe61 100644 --- a/util.c +++ b/util.c @@ -1257,6 +1257,7 @@ static bool parse_notify(struct pool *pool, json_t *val) pool->swork.ntime = ntime; pool->swork.clean = clean; pool->swork.cb_len = pool->swork.cb1_len + pool->n1_len + pool->n2size + pool->swork.cb2_len; + pool->nonce2_offset = pool->swork.cb1_len + pool->n1_len; for (i = 0; i < pool->swork.merkles; i++) free(pool->swork.merkle[i]);