Use a nonce2 offset variable for both gbt and stratum to consolidate requirements on work generation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
diff --git a/cgminer.c b/cgminer.c
index fc259c6..1a83282 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 500ecb9..2ba39d6 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 81008f3..1f7fbe6 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]);