Browse Source

Use a nonce2 offset variable for both gbt and stratum to consolidate requirements on work generation.

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

15
cgminer.c

@ -1698,7 +1698,7 @@ static void gen_gbt_work(struct pool *pool, struct work *work)
update_gbt(pool); update_gbt(pool);
cg_wlock(&pool->gbt_lock); 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++; pool->nonce2++;
cg_dwlock(&pool->gbt_lock); cg_dwlock(&pool->gbt_lock);
merkleroot = __gbt_merkleroot(pool); merkleroot = __gbt_merkleroot(pool);
@ -1758,7 +1758,7 @@ static bool gbt_decode(struct pool *pool, json_t *res_val)
bool submitold; bool submitold;
const char *bits; const char *bits;
const char *workid; const char *workid;
int cbt_len; int cbt_len, orig_len;
uint8_t *extra_len; uint8_t *extra_len;
size_t cal_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"); quit(1, "Failed to calloc pool gbt_coinbase in gbt_decode");
hex2bin(pool->gbt_coinbase, pool->coinbasetxn, 42); hex2bin(pool->gbt_coinbase, pool->coinbasetxn, 42);
extra_len = (uint8_t *)(pool->gbt_coinbase + 41); extra_len = (uint8_t *)(pool->gbt_coinbase + 41);
pool->orig_len = *extra_len; orig_len = *extra_len;
hex2bin(pool->gbt_coinbase + 42, pool->coinbasetxn + 84, pool->orig_len); hex2bin(pool->gbt_coinbase + 42, pool->coinbasetxn + 84, orig_len);
*extra_len += 4; *extra_len += 4;
hex2bin(pool->gbt_coinbase + 42 + *extra_len, pool->coinbasetxn + 84 + (pool->orig_len * 2), hex2bin(pool->gbt_coinbase + 42 + *extra_len, pool->coinbasetxn + 84 + (orig_len * 2),
cbt_len - pool->orig_len - 42); cbt_len - orig_len - 42);
pool->nonce2_offset = orig_len + 42;
free(pool->longpollid); free(pool->longpollid);
pool->longpollid = strdup(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"); quit(1, "Failed to calloc coinbase in gen_stratum_work");
memcpy(coinbase, pool->swork.cb1, pool->swork.cb1_len); memcpy(coinbase, pool->swork.cb1, pool->swork.cb1_len);
memcpy(coinbase + pool->swork.cb1_len, pool->nonce1bin, pool->n1_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); memcpy(coinbase + pool->swork.cb1_len + pool->n1_len + pool->n2size, pool->swork.cb2, pool->swork.cb2_len);
/* Generate merkle root */ /* Generate merkle root */

4
miner.h

@ -1182,6 +1182,7 @@ struct pool {
char *sockbuf; char *sockbuf;
size_t sockbuf_size; size_t sockbuf_size;
char *sockaddr_url; /* stripped url used for sockaddr */ char *sockaddr_url; /* stripped url used for sockaddr */
char *stratum_coinbase;
char *nonce1; char *nonce1;
unsigned char *nonce1bin; unsigned char *nonce1bin;
size_t n1_len; size_t n1_len;
@ -1215,8 +1216,9 @@ struct pool {
unsigned char *txn_hashes; unsigned char *txn_hashes;
int gbt_txns; int gbt_txns;
int coinbase_len; int coinbase_len;
int orig_len;
/* Shared by both stratum & GBT */
int nonce2_offset;
struct timeval tv_lastwork; struct timeval tv_lastwork;
}; };

1
util.c

@ -1257,6 +1257,7 @@ static bool parse_notify(struct pool *pool, json_t *val)
pool->swork.ntime = ntime; pool->swork.ntime = ntime;
pool->swork.clean = clean; pool->swork.clean = clean;
pool->swork.cb_len = pool->swork.cb1_len + pool->n1_len + pool->n2size + pool->swork.cb2_len; 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++) for (i = 0; i < pool->swork.merkles; i++)
free(pool->swork.merkle[i]); free(pool->swork.merkle[i]);

Loading…
Cancel
Save