From fef649dfefb37e2a2481973bb2a49108a20f6cc1 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 11 Aug 2013 13:47:46 +1000 Subject: [PATCH] Cache the binary generation of coinbase1 and 2 on stratum, avoiding a hex2bin of coinbase1 and 2 on each work generation. --- cgminer.c | 4 ++-- miner.h | 2 ++ util.c | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/cgminer.c b/cgminer.c index f22a44bf..c92589b3 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 a05c1e0a..8b1946e5 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 16016d05..3af61257 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) {