Browse Source

Cache the binary generation of coinbase1 and 2 on stratum, avoiding a hex2bin of coinbase1 and 2 on each work generation.

nfactor-troky
Con Kolivas 11 years ago
parent
commit
fef649dfef
  1. 4
      cgminer.c
  2. 2
      miner.h
  3. 11
      util.c

4
cgminer.c

@ -5611,10 +5611,10 @@ static void gen_stratum_work(struct pool *pool, struct work *work) @@ -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);

2
miner.h

@ -1066,6 +1066,8 @@ struct stratum_work { @@ -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;

11
util.c

@ -1277,6 +1277,17 @@ static bool parse_notify(struct pool *pool, json_t *val) @@ -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) {

Loading…
Cancel
Save