mirror of
https://github.com/GOSTSec/sgminer
synced 2025-02-06 12:04:20 +00:00
Cache as much of the gbt coinbase as possible to avoid doing unnecessary hex2bin conversion on every work generation with gbt.
This commit is contained in:
parent
a1052188fd
commit
fb94dfa098
50
cgminer.c
50
cgminer.c
@ -1565,33 +1565,6 @@ void free_work(struct work *work)
|
|||||||
free(work);
|
free(work);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Generate a GBT coinbase from the existing GBT variables stored. Must be
|
|
||||||
* entered under gbt_lock */
|
|
||||||
static void __build_gbt_coinbase(struct pool *pool)
|
|
||||||
{
|
|
||||||
unsigned char *coinbase;
|
|
||||||
int cbt_len, orig_len;
|
|
||||||
uint8_t *extra_len;
|
|
||||||
size_t cal_len;
|
|
||||||
|
|
||||||
cbt_len = strlen(pool->coinbasetxn) / 2;
|
|
||||||
pool->coinbase_len = cbt_len + 4;
|
|
||||||
/* We add 4 bytes of extra data corresponding to nonce2 of stratum */
|
|
||||||
cal_len = pool->coinbase_len + 1;
|
|
||||||
align_len(&cal_len);
|
|
||||||
coinbase = calloc(cal_len, 1);
|
|
||||||
hex2bin(coinbase, pool->coinbasetxn, 42);
|
|
||||||
extra_len = (uint8_t *)(coinbase + 41);
|
|
||||||
orig_len = *extra_len;
|
|
||||||
hex2bin(coinbase + 42, pool->coinbasetxn + 84, orig_len);
|
|
||||||
memcpy(coinbase + 42 + orig_len, &pool->nonce2, 4);
|
|
||||||
*extra_len += 4;
|
|
||||||
hex2bin(coinbase + 42 + *extra_len, pool->coinbasetxn + 84 + (orig_len * 2), cbt_len - orig_len - 42);
|
|
||||||
pool->nonce2++;
|
|
||||||
free(pool->gbt_coinbase);
|
|
||||||
pool->gbt_coinbase = coinbase;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void gen_hash(unsigned char *data, unsigned char *hash, int len);
|
static void gen_hash(unsigned char *data, unsigned char *hash, int len);
|
||||||
|
|
||||||
/* Process transactions with GBT by storing the binary value of the first
|
/* Process transactions with GBT by storing the binary value of the first
|
||||||
@ -1725,7 +1698,8 @@ 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);
|
||||||
__build_gbt_coinbase(pool);
|
memcpy(pool->gbt_coinbase + 42 + pool->orig_len, &pool->nonce2, 4);
|
||||||
|
pool->nonce2++;
|
||||||
cg_dwlock(&pool->gbt_lock);
|
cg_dwlock(&pool->gbt_lock);
|
||||||
merkleroot = __gbt_merkleroot(pool);
|
merkleroot = __gbt_merkleroot(pool);
|
||||||
|
|
||||||
@ -1784,6 +1758,9 @@ 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;
|
||||||
|
uint8_t *extra_len;
|
||||||
|
size_t cal_len;
|
||||||
|
|
||||||
previousblockhash = json_string_value(json_object_get(res_val, "previousblockhash"));
|
previousblockhash = json_string_value(json_object_get(res_val, "previousblockhash"));
|
||||||
target = json_string_value(json_object_get(res_val, "target"));
|
target = json_string_value(json_object_get(res_val, "target"));
|
||||||
@ -1817,6 +1794,23 @@ static bool gbt_decode(struct pool *pool, json_t *res_val)
|
|||||||
cg_wlock(&pool->gbt_lock);
|
cg_wlock(&pool->gbt_lock);
|
||||||
free(pool->coinbasetxn);
|
free(pool->coinbasetxn);
|
||||||
pool->coinbasetxn = strdup(coinbasetxn);
|
pool->coinbasetxn = strdup(coinbasetxn);
|
||||||
|
cbt_len = strlen(pool->coinbasetxn) / 2;
|
||||||
|
pool->coinbase_len = cbt_len + 4;
|
||||||
|
/* We add 4 bytes of extra data corresponding to nonce2 of stratum */
|
||||||
|
cal_len = pool->coinbase_len + 1;
|
||||||
|
align_len(&cal_len);
|
||||||
|
free(pool->gbt_coinbase);
|
||||||
|
pool->gbt_coinbase = calloc(cal_len, 1);
|
||||||
|
if (unlikely(!pool->gbt_coinbase))
|
||||||
|
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);
|
||||||
|
*extra_len += 4;
|
||||||
|
hex2bin(pool->gbt_coinbase + 42 + *extra_len, pool->coinbasetxn + 84 + (pool->orig_len * 2),
|
||||||
|
cbt_len - pool->orig_len - 42);
|
||||||
|
|
||||||
free(pool->longpollid);
|
free(pool->longpollid);
|
||||||
pool->longpollid = strdup(longpollid);
|
pool->longpollid = strdup(longpollid);
|
||||||
free(pool->gbt_workid);
|
free(pool->gbt_workid);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user