Browse Source

Call precious block on all submitted blocks.

master
Con Kolivas 8 years ago
parent
commit
8a66c4811b
  1. 19
      src/bitcoin.c
  2. 3
      src/bitcoin.h
  3. 16
      src/generator.c
  4. 3
      src/generator.h
  5. 13
      src/stratifier.c

19
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;

3
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);

16
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;

3
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);

13
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",

Loading…
Cancel
Save