diff --git a/src/bitcoin.c b/src/bitcoin.c index 288dade3..c8444261 100644 --- a/src/bitcoin.c +++ b/src/bitcoin.c @@ -307,7 +307,7 @@ out: return ret; } -bool submit_block(connsock_t *cs, char *params) +bool submit_block(connsock_t *cs, const char *params) { json_t *val, *res_val; int len, retries = 0; @@ -355,6 +355,23 @@ out: return ret; } +void precious_block(connsock_t *cs, const char *params) +{ + char *rpc_req; + int len; + + if (unlikely(!cs->alive)) { + LOGDEBUG("Failed to submit_txn due to connsock dead"); + return; + } + + len = strlen(params) + 64; + rpc_req = ckalloc(len); + sprintf(rpc_req, "{\"method\": \"preciousblock\", \"params\": [\"%s\"]}\n", params); + json_rpc_msg(cs, rpc_req); + dealloc(rpc_req); +} + void submit_txn(connsock_t *cs, const char *params) { char *rpc_req; diff --git a/src/bitcoin.h b/src/bitcoin.h index e1672d59..a27c91f3 100644 --- a/src/bitcoin.h +++ b/src/bitcoin.h @@ -38,7 +38,8 @@ void clear_gbtbase(gbtbase_t *gbt); int get_blockcount(connsock_t *cs); bool get_blockhash(connsock_t *cs, int height, char *hash); bool get_bestblockhash(connsock_t *cs, char *hash); -bool submit_block(connsock_t *cs, char *params); +bool submit_block(connsock_t *cs, const char *params); +void precious_block(connsock_t *cs, const char *params); void submit_txn(connsock_t *cs, const char *params); char *get_txn(connsock_t *cs, const char *hash); diff --git a/src/generator.c b/src/generator.c index e5730e5f..5c3eaa52 100644 --- a/src/generator.c +++ b/src/generator.c @@ -312,7 +312,7 @@ static void clear_unix_msg(unix_msg_t **umsg) } } -bool generator_submitblock(ckpool_t *ckp, char *buf) +bool generator_submitblock(ckpool_t *ckp, const char *buf) { gdata_t *gdata = ckp->gdata; server_instance_t *si; @@ -330,6 +330,20 @@ bool generator_submitblock(ckpool_t *ckp, char *buf) return submit_block(cs, buf); } +void generator_preciousblock(ckpool_t *ckp, const char *hash) +{ + gdata_t *gdata = ckp->gdata; + server_instance_t *si; + connsock_t *cs; + + if (unlikely(!(si = gdata->current_si))) { + LOGWARNING("No live current server in generator_get_blockhash"); + return; + } + cs = &si->cs; + precious_block(cs, hash); +} + bool generator_get_blockhash(ckpool_t *ckp, int height, char *hash) { gdata_t *gdata = ckp->gdata; diff --git a/src/generator.h b/src/generator.h index 775fc397..6e91c5b7 100644 --- a/src/generator.h +++ b/src/generator.h @@ -21,7 +21,8 @@ json_t *generator_genbase(ckpool_t *ckp); int generator_getbest(ckpool_t *ckp, char *hash); bool generator_checkaddr(ckpool_t *ckp, const char *addr); char *generator_get_txn(ckpool_t *ckp, const char *hash); -bool generator_submitblock(ckpool_t *ckp, char *buf); +bool generator_submitblock(ckpool_t *ckp, const char *buf); +void generator_preciousblock(ckpool_t *ckp, const char *hash); bool generator_get_blockhash(ckpool_t *ckp, int height, char *hash); void *generator(void *arg); diff --git a/src/stratifier.c b/src/stratifier.c index 04359ab0..4b3fbf24 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2126,16 +2126,17 @@ process_block(const workbase_t *wb, const char *coinbase, const int cblen, static bool local_block_submit(ckpool_t *ckp, char *gbt_block, const uchar *flip32, int height) { bool ret = generator_submitblock(ckp, gbt_block); + char heighthash[68] = {}, rhash[68] = {}; + uchar swap256[32]; free(gbt_block); + swap_256(swap256, flip32); + __bin2hex(rhash, swap256, 32); + generator_preciousblock(ckp, rhash); + /* Check failures that may be inconclusive but were submitted via other - * means. */ + * means or accepted due to precious block call. */ if (!ret) { - char heighthash[68] = {}, rhash[68] = {}; - uchar swap256[32]; - - swap_256(swap256, flip32); - __bin2hex(rhash, swap256, 32); if (generator_get_blockhash(ckp, height, heighthash)) { ret = !strncmp(rhash, heighthash, 64); LOGWARNING("Hash for block height %d confirms block was %s",