Browse Source

Send block submission data remotely before attempting local submit to not delay propagation with the local verification time.

master
Con Kolivas 8 years ago
parent
commit
eb3f0b2a06
  1. 45
      src/stratifier.c

45
src/stratifier.c

@ -2045,14 +2045,13 @@ static void send_node_block(sdata_t *sdata, const char *enonce1, const char *non
/* Process a block into a message for the generator to submit. Must hold /* Process a block into a message for the generator to submit. Must hold
* workbase readcount */ * workbase readcount */
static bool static char *
process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const int cblen, process_block(const workbase_t *wb, const char *coinbase, const int cblen,
const uchar *data, const uchar *hash, uchar *flip32, char *blockhash) const uchar *data, const uchar *hash, uchar *flip32, char *blockhash)
{ {
char *gbt_block, varint[12]; char *gbt_block, varint[12];
int txns = wb->txns + 1; int txns = wb->txns + 1;
char hexcoinbase[1024]; char hexcoinbase[1024];
bool ret;
flip_32(flip32, hash); flip_32(flip32, hash);
__bin2hex(blockhash, flip32, 32); __bin2hex(blockhash, flip32, 32);
@ -2080,10 +2079,15 @@ process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const i
strcat(gbt_block, hexcoinbase); strcat(gbt_block, hexcoinbase);
if (wb->txns) if (wb->txns)
realloc_strcat(&gbt_block, wb->txn_data); realloc_strcat(&gbt_block, wb->txn_data);
return gbt_block;
}
ret = generator_submitblock(ckp, gbt_block); /* Submit block data locally, absorbing and freeing gbt_block */
free(gbt_block); static bool local_block_submit(ckpool_t *ckp, char *gbt_block, const uchar *flip32, int height)
{
bool ret = generator_submitblock(ckp, gbt_block);
free(gbt_block);
/* Check failures that may be inconclusive but were submitted via other /* Check failures that may be inconclusive but were submitted via other
* means. */ * means. */
if (!ret) { if (!ret) {
@ -2092,10 +2096,10 @@ process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const i
swap_256(swap256, flip32); swap_256(swap256, flip32);
__bin2hex(rhash, swap256, 32); __bin2hex(rhash, swap256, 32);
if (generator_get_blockhash(ckp, wb->height, heighthash)) { if (generator_get_blockhash(ckp, height, heighthash)) {
ret = !strncmp(rhash, heighthash, 64); ret = !strncmp(rhash, heighthash, 64);
LOGWARNING("Hash for block height %d confirms block was %s", LOGWARNING("Hash for block height %d confirms block was %s",
wb->height, ret ? "ACCEPTED" : "REJECTED"); height, ret ? "ACCEPTED" : "REJECTED");
} }
} }
return ret; return ret;
@ -2145,8 +2149,8 @@ static void block_reject(json_t *val);
static void submit_node_block(ckpool_t *ckp, sdata_t *sdata, json_t *val) static void submit_node_block(ckpool_t *ckp, sdata_t *sdata, json_t *val)
{ {
char *coinbase = NULL, *enonce1 = NULL, *nonce = NULL, *nonce2 = NULL; char *coinbase = NULL, *enonce1 = NULL, *nonce = NULL, *nonce2 = NULL, *gbt_block;
uchar *enonce1bin = NULL, hash[32], swap[80], swap32[32]; uchar *enonce1bin = NULL, hash[32], swap[80], flip32[32];
char blockhash[68], cdfield[64]; char blockhash[68], cdfield[64];
json_t *bval, *bval_copy; json_t *bval, *bval_copy;
int enonce1len, cblen; int enonce1len, cblen;
@ -2200,7 +2204,8 @@ static void submit_node_block(ckpool_t *ckp, sdata_t *sdata, json_t *val)
/* Fill in the hashes */ /* Fill in the hashes */
share_diff(coinbase, enonce1bin, wb, nonce2, ntime32, nonce, hash, swap, &cblen); share_diff(coinbase, enonce1bin, wb, nonce2, ntime32, nonce, hash, swap, &cblen);
ret = process_block(ckp, wb, coinbase, cblen, swap, hash, swap32, blockhash); gbt_block = process_block(wb, coinbase, cblen, swap, hash, flip32, blockhash);
ret = local_block_submit(ckp, gbt_block, flip32, wb->height);
JSON_CPACK(bval, "{si,ss,ss,sI,ss,ss,ss,sI,sf,ss,ss,ss,ss}", JSON_CPACK(bval, "{si,ss,ss,sI,ss,ss,ss,sI,sf,ss,ss,ss,ss}",
"height", wb->height, "height", wb->height,
@ -5813,11 +5818,11 @@ test_blocksolve(const stratum_instance_t *client, const workbase_t *wb, const uc
const uchar *hash, const double diff, const char *coinbase, int cblen, const uchar *hash, const double diff, const char *coinbase, int cblen,
const char *nonce2, const char *nonce, const uint32_t ntime32, const bool stale) const char *nonce2, const char *nonce, const uint32_t ntime32, const bool stale)
{ {
char blockhash[68], cdfield[64]; char blockhash[68], cdfield[64], *gbt_block;
sdata_t *sdata = client->sdata; sdata_t *sdata = client->sdata;
json_t *val = NULL, *val_copy; json_t *val = NULL, *val_copy;
ckpool_t *ckp = wb->ckp; ckpool_t *ckp = wb->ckp;
uchar swap32[32]; uchar flip32[32];
ts_t ts_now; ts_t ts_now;
bool ret; bool ret;
@ -5833,7 +5838,7 @@ test_blocksolve(const stratum_instance_t *client, const workbase_t *wb, const uc
ts_realtime(&ts_now); ts_realtime(&ts_now);
sprintf(cdfield, "%lu,%lu", ts_now.tv_sec, ts_now.tv_nsec); sprintf(cdfield, "%lu,%lu", ts_now.tv_sec, ts_now.tv_nsec);
ret = process_block(ckp, wb, coinbase, cblen, data, hash, swap32, blockhash); gbt_block = process_block(wb, coinbase, cblen, data, hash, flip32, blockhash);
send_node_block(sdata, client->enonce1, nonce, nonce2, ntime32, wb->id, send_node_block(sdata, client->enonce1, nonce, nonce2, ntime32, wb->id,
diff, client->id); diff, client->id);
@ -5864,6 +5869,9 @@ test_blocksolve(const stratum_instance_t *client, const workbase_t *wb, const uc
ckdbq_add(ckp, ID_BLOCK, val); ckdbq_add(ckp, ID_BLOCK, val);
} }
/* Submit block locally after sending it to remote locations avoiding
* the delay of local verification */
ret = local_block_submit(ckp, gbt_block, flip32, wb->height);
if (ret) if (ret)
block_solve(ckp, val_copy); block_solve(ckp, val_copy);
else else
@ -6979,8 +6987,8 @@ static void parse_remote_block(ckpool_t *ckp, sdata_t *sdata, json_t *val, const
if (unlikely(!wb)) if (unlikely(!wb))
LOGWARNING("Inadequate data locally to attempt submit of remote block"); LOGWARNING("Inadequate data locally to attempt submit of remote block");
else { else {
uchar swap[80], hash[32], hash1[32], swap32[32]; uchar swap[80], hash[32], hash1[32], flip32[32];
char *coinbase = alloca(cblen); char *coinbase = alloca(cblen), *gbt_block;
char blockhash[68]; char blockhash[68];
LOGWARNING("Possible remote block solve diff %lf !", diff); LOGWARNING("Possible remote block solve diff %lf !", diff);
@ -6988,9 +6996,10 @@ static void parse_remote_block(ckpool_t *ckp, sdata_t *sdata, json_t *val, const
hex2bin(swap, swaphex, 80); hex2bin(swap, swaphex, 80);
sha256(swap, 80, hash1); sha256(swap, 80, hash1);
sha256(hash1, 32, hash); sha256(hash1, 32, hash);
/* Ignore the retrun value of process_block here as we rely on gbt_block = process_block(wb, coinbase, cblen, swap, hash, flip32, blockhash);
* the remote server to give us the ID_BLOCK responses */ /* Ignore the return value of local_block_submit here as we rely
process_block(ckp, wb, coinbase, cblen, swap, hash, swap32, blockhash); * on the remote server to give us the ID_BLOCK responses */
local_block_submit(ckp, gbt_block, flip32, wb->height);
put_remote_workbase(sdata, wb); put_remote_workbase(sdata, wb);
} }

Loading…
Cancel
Save