Browse Source

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

nfactor-troky
Con Kolivas 12 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) @@ -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) @@ -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) @@ -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) @@ -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 */

4
miner.h

@ -1182,6 +1182,7 @@ struct pool { @@ -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 { @@ -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;
};

1
util.c

@ -1257,6 +1257,7 @@ static bool parse_notify(struct pool *pool, json_t *val) @@ -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]);

Loading…
Cancel
Save