mirror of
https://github.com/GOSTSec/sgminer
synced 2025-01-22 20:44:19 +00:00
Cache the coinbase length to speed up stratum work generation.
This commit is contained in:
parent
0870ab7532
commit
d644fdf1f4
18
cgminer.c
18
cgminer.c
@ -5086,30 +5086,26 @@ static void set_work_target(struct work *work, double diff)
|
|||||||
static void gen_stratum_work(struct pool *pool, struct work *work)
|
static void gen_stratum_work(struct pool *pool, struct work *work)
|
||||||
{
|
{
|
||||||
unsigned char *coinbase, merkle_root[32], merkle_sha[64];
|
unsigned char *coinbase, merkle_root[32], merkle_sha[64];
|
||||||
int len, cb1_len, n1_len, cb2_len, i;
|
|
||||||
char *header, *merkle_hash;
|
char *header, *merkle_hash;
|
||||||
uint32_t *data32, *swap32;
|
uint32_t *data32, *swap32;
|
||||||
size_t alloc_len;
|
size_t alloc_len;
|
||||||
|
int i;
|
||||||
|
|
||||||
mutex_lock(&pool->pool_lock);
|
mutex_lock(&pool->pool_lock);
|
||||||
|
|
||||||
/* Generate coinbase */
|
/* Generate coinbase */
|
||||||
work->nonce2 = bin2hex((const unsigned char *)&pool->nonce2, pool->n2size);
|
work->nonce2 = bin2hex((const unsigned char *)&pool->nonce2, pool->n2size);
|
||||||
pool->nonce2++;
|
pool->nonce2++;
|
||||||
cb1_len = strlen(pool->swork.coinbase1) / 2;
|
alloc_len = pool->swork.cb_len;
|
||||||
n1_len = strlen(pool->nonce1) / 2;
|
|
||||||
cb2_len = strlen(pool->swork.coinbase2) / 2;
|
|
||||||
len = cb1_len + n1_len + pool->n2size + cb2_len;
|
|
||||||
alloc_len = len;
|
|
||||||
align_len(&alloc_len);
|
align_len(&alloc_len);
|
||||||
coinbase = calloc(alloc_len, 1);
|
coinbase = calloc(alloc_len, 1);
|
||||||
hex2bin(coinbase, pool->swork.coinbase1, cb1_len);
|
hex2bin(coinbase, pool->swork.coinbase1, pool->swork.cb1_len);
|
||||||
hex2bin(coinbase + cb1_len, pool->nonce1, n1_len);
|
hex2bin(coinbase + pool->swork.cb1_len, pool->nonce1, pool->n1_len);
|
||||||
hex2bin(coinbase + cb1_len + n1_len, work->nonce2, pool->n2size);
|
hex2bin(coinbase + pool->swork.cb1_len + pool->n1_len, work->nonce2, pool->n2size);
|
||||||
hex2bin(coinbase + cb1_len + n1_len + pool->n2size, pool->swork.coinbase2, cb2_len);
|
hex2bin(coinbase + pool->swork.cb1_len + pool->n1_len + pool->n2size, pool->swork.coinbase2, pool->swork.cb2_len);
|
||||||
|
|
||||||
/* Generate merkle root */
|
/* Generate merkle root */
|
||||||
gen_hash(coinbase, merkle_root, len);
|
gen_hash(coinbase, merkle_root, pool->swork.cb_len);
|
||||||
free(coinbase);
|
free(coinbase);
|
||||||
memcpy(merkle_sha, merkle_root, 32);
|
memcpy(merkle_sha, merkle_root, 32);
|
||||||
for (i = 0; i < pool->swork.merkles; i++) {
|
for (i = 0; i < pool->swork.merkles; i++) {
|
||||||
|
5
miner.h
5
miner.h
@ -855,6 +855,10 @@ struct stratum_work {
|
|||||||
char *ntime;
|
char *ntime;
|
||||||
bool clean;
|
bool clean;
|
||||||
|
|
||||||
|
size_t cb1_len;
|
||||||
|
size_t cb2_len;
|
||||||
|
size_t cb_len;
|
||||||
|
|
||||||
size_t header_len;
|
size_t header_len;
|
||||||
int merkles;
|
int merkles;
|
||||||
double diff;
|
double diff;
|
||||||
@ -934,6 +938,7 @@ struct pool {
|
|||||||
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 *nonce1;
|
char *nonce1;
|
||||||
|
size_t n1_len;
|
||||||
uint32_t nonce2;
|
uint32_t nonce2;
|
||||||
int n2size;
|
int n2size;
|
||||||
bool has_stratum;
|
bool has_stratum;
|
||||||
|
5
util.c
5
util.c
@ -1131,11 +1131,15 @@ static bool parse_notify(struct pool *pool, json_t *val)
|
|||||||
pool->swork.job_id = job_id;
|
pool->swork.job_id = job_id;
|
||||||
pool->swork.prev_hash = prev_hash;
|
pool->swork.prev_hash = prev_hash;
|
||||||
pool->swork.coinbase1 = coinbase1;
|
pool->swork.coinbase1 = coinbase1;
|
||||||
|
pool->swork.cb1_len = strlen(coinbase1) / 2;
|
||||||
pool->swork.coinbase2 = coinbase2;
|
pool->swork.coinbase2 = coinbase2;
|
||||||
|
pool->swork.cb2_len = strlen(coinbase2) / 2;
|
||||||
pool->swork.bbversion = bbversion;
|
pool->swork.bbversion = bbversion;
|
||||||
pool->swork.nbit = nbit;
|
pool->swork.nbit = nbit;
|
||||||
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;
|
||||||
|
|
||||||
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]);
|
||||||
if (merkles) {
|
if (merkles) {
|
||||||
@ -1468,6 +1472,7 @@ bool initiate_stratum(struct pool *pool)
|
|||||||
applog(LOG_INFO, "Failed to get nonce1 in initiate_stratum");
|
applog(LOG_INFO, "Failed to get nonce1 in initiate_stratum");
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
pool->n1_len = strlen(pool->nonce1) / 2;
|
||||||
pool->n2size = json_integer_value(json_array_get(res_val, 2));
|
pool->n2size = json_integer_value(json_array_get(res_val, 2));
|
||||||
if (!pool->n2size) {
|
if (!pool->n2size) {
|
||||||
applog(LOG_INFO, "Failed to get n2size in initiate_stratum");
|
applog(LOG_INFO, "Failed to get n2size in initiate_stratum");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user