From 9d8c45930bf7ab4007ee2c5d72e7ef9ad12bf053 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sat, 21 Jan 2017 13:12:12 +1100 Subject: [PATCH] Check inconclusive block submits against their height hash to see if they were already submitted via other means. --- src/generator.c | 14 ++++++++++++++ src/generator.h | 1 + src/stratifier.c | 21 ++++++++++++++++++--- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/generator.c b/src/generator.c index 884e8595..fccc5f0d 100644 --- a/src/generator.c +++ b/src/generator.c @@ -330,6 +330,20 @@ bool generator_submitblock(ckpool_t *ckp, char *buf) return submit_block(cs, buf + 64 + 1); } +bool generator_get_blockhash(ckpool_t *ckp, int height, 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 false; + } + cs = &si->cs; + return get_blockhash(cs, height, hash); +} + static void gen_loop(proc_instance_t *pi) { server_instance_t *si = NULL, *old_si; diff --git a/src/generator.h b/src/generator.h index 47b802cd..775fc397 100644 --- a/src/generator.h +++ b/src/generator.h @@ -22,6 +22,7 @@ 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_get_blockhash(ckpool_t *ckp, int height, char *hash); void *generator(void *arg); #endif /* GENERATOR_H */ diff --git a/src/stratifier.c b/src/stratifier.c index 83f59f69..3777dfcc 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -2047,7 +2047,7 @@ static void send_node_block(sdata_t *sdata, const char *enonce1, const char *non * workbase readcount */ static bool process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const int cblen, - const uchar *data, const uchar *hash, uchar *swap32, char *blockhash) + const uchar *data, const uchar *hash, uchar *flip32, char *blockhash) { char *gbt_block, varint[12]; int txns = wb->txns + 1; @@ -2055,8 +2055,8 @@ process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const i bool ret; gbt_block = ckalloc(1024); - flip_32(swap32, hash); - __bin2hex(blockhash, swap32, 32); + flip_32(flip32, hash); + __bin2hex(blockhash, flip32, 32); /* Message format: "hash,data" */ sprintf(gbt_block, "%s,", blockhash); @@ -2084,6 +2084,21 @@ process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const i ret = generator_submitblock(ckp, gbt_block); free(gbt_block); + + /* Check failures that may be inconclusive but were submitted via other + * means. */ + if (!ret) { + char heighthash[68] = {}, rhash[68] = {}; + uchar swap256[32]; + + swap_256(swap256, flip32); + __bin2hex(rhash, swap256, 32); + if (generator_get_blockhash(ckp, wb->height, heighthash)) { + ret = !strncmp(rhash, heighthash, 64); + LOGWARNING("Hash for block height %d confirms block was %s", + wb->height, ret ? "ACCEPTED" : "REJECTED"); + } + } return ret; }