Cache the binary generation of coinbase1 and 2 on stratum, avoiding a hex2bin of coinbase1 and 2 on each 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
diff --git a/cgminer.c b/cgminer.c
index f22a44b..c92589b 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -5611,10 +5611,10 @@ static void gen_stratum_work(struct pool *pool, struct work *work)
coinbase = calloc(alloc_len, 1);
if (unlikely(!coinbase))
quit(1, "Failed to calloc coinbase in gen_stratum_work");
- hex2bin(coinbase, pool->swork.coinbase1, pool->swork.cb1_len);
+ memcpy(coinbase, pool->swork.cb1, pool->swork.cb1_len);
hex2bin(coinbase + pool->swork.cb1_len, pool->nonce1, pool->n1_len);
hex2bin(coinbase + pool->swork.cb1_len + pool->n1_len, work->nonce2, pool->n2size);
- hex2bin(coinbase + pool->swork.cb1_len + pool->n1_len + pool->n2size, pool->swork.coinbase2, pool->swork.cb2_len);
+ memcpy(coinbase + pool->swork.cb1_len + pool->n1_len + pool->n2size, pool->swork.cb2, pool->swork.cb2_len);
/* Generate merkle root */
gen_hash(coinbase, merkle_root, pool->swork.cb_len);
diff --git a/miner.h b/miner.h
index a05c1e0..8b1946e 100644
--- a/miner.h
+++ b/miner.h
@@ -1066,6 +1066,8 @@ struct stratum_work {
char *nbit;
char *ntime;
bool clean;
+ unsigned char *cb1;
+ unsigned char *cb2;
size_t cb1_len;
size_t cb2_len;
diff --git a/util.c b/util.c
index 16016d0..3af6125 100644
--- a/util.c
+++ b/util.c
@@ -1277,6 +1277,17 @@ static bool parse_notify(struct pool *pool, json_t *val)
/* workpadding */ 96;
pool->swork.header_len = pool->swork.header_len * 2 + 1;
align_len(&pool->swork.header_len);
+
+ free(pool->swork.cb1);
+ free(pool->swork.cb2);
+ pool->swork.cb1 = calloc(pool->swork.cb1_len, 1);
+ if (unlikely(!pool->swork.cb1))
+ quit(1, "Failed to calloc swork cb1 in parse_notify");
+ hex2bin(pool->swork.cb1, pool->swork.coinbase1, pool->swork.cb1_len);
+ pool->swork.cb2 = calloc(pool->swork.cb2_len, 1);
+ if (unlikely(!pool->swork.cb2))
+ quit(1, "Failed to calloc swork cb2 in parse_notify");
+ hex2bin(pool->swork.cb2, pool->swork.coinbase2, pool->swork.cb2_len);
cg_wunlock(&pool->data_lock);
if (opt_protocol) {