From 0aebd0256ffd2ef918ff3a1287977edec89cc12b Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Tue, 27 Dec 2016 10:45:03 +1100 Subject: [PATCH] Submit blocks and retrieve responses directly between stratifier and generator. --- src/generator.c | 25 +++++++++++++++++++++++++ src/generator.h | 1 + src/stratifier.c | 27 ++++++++++++++++++--------- src/stratifier.h | 2 ++ 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/generator.c b/src/generator.c index 4eb12bbe..82e33d4b 100644 --- a/src/generator.c +++ b/src/generator.c @@ -18,6 +18,7 @@ #include "ckpool.h" #include "libckpool.h" #include "generator.h" +#include "stratifier.h" #include "bitcoin.h" #include "uthash.h" #include "utlist.h" @@ -311,6 +312,30 @@ static void clear_unix_msg(unix_msg_t **umsg) } } +void generator_submitblock(ckpool_t *ckp, char *buf) +{ + gdata_t *gdata = ckp->gdata; + server_instance_t *si; + bool warn = false; + connsock_t *cs; + bool ret; + + while (unlikely(!(si = gdata->current_si))) { + if (!warn) + LOGWARNING("No live current server in generator_blocksubmit! Resubmitting indefinitely!"); + warn = true; + cksleep_ms(10); + } + cs = &si->cs; + LOGNOTICE("Submitting block data!"); + ret = submit_block(cs, buf + 64 + 1); + memset(buf + 64, 0, 1); + if (ret) + stratifier_block_solve(ckp, buf); + else + stratifier_block_reject(ckp, buf); +} + 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 c9811c02..498fab98 100644 --- a/src/generator.h +++ b/src/generator.h @@ -20,6 +20,7 @@ void generator_add_send(ckpool_t *ckp, json_t *val); json_t *generator_genbase(ckpool_t *ckp); int generator_getbest(ckpool_t *ckp, char *hash); bool generator_checkaddr(ckpool_t *ckp, const char *addr); +void generator_submitblock(ckpool_t *ckp, char *buf); void *generator(void *arg); #endif /* GENERATOR_H */ diff --git a/src/stratifier.c b/src/stratifier.c index 869f19fc..6e23b792 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1765,9 +1765,9 @@ process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const i flip_32(swap32, hash); __bin2hex(blockhash, swap32, 32); - /* Message format: "submitblock:hash,data" */ - sprintf(gbt_block, "submitblock:%s,", blockhash); - __bin2hex(gbt_block + 12 + 64 + 1, data, 80); + /* Message format: "hash,data" */ + sprintf(gbt_block, "%s,", blockhash); + __bin2hex(gbt_block + 64 + 1, data, 80); if (txns < 0xfd) { uint8_t val8 = txns; @@ -1788,7 +1788,7 @@ process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const i strcat(gbt_block, hexcoinbase); if (wb->txns) realloc_strcat(&gbt_block, wb->txn_data); - send_proc(ckp->generator, gbt_block); + generator_submitblock(ckp, gbt_block); free(gbt_block); } @@ -3429,6 +3429,11 @@ static void block_solve(ckpool_t *ckp, const char *blockhash) reset_bestshares(sdata); } +void stratifier_block_solve(ckpool_t *ckp, const char *blockhash) +{ + block_solve(ckp, blockhash); +} + static void block_reject(sdata_t *sdata, const char *blockhash) { ckmsg_t *block, *tmp, *found = NULL; @@ -3468,6 +3473,11 @@ static void block_reject(sdata_t *sdata, const char *blockhash) LOGWARNING("Submitted, but had block %d rejected", height); } +void stratifier_block_reject(ckpool_t *ckp, const char *blockhash) +{ + block_reject(ckp->sdata, blockhash); +} + /* Some upstream pools (like p2pool) don't update stratum often enough and * miners disconnect if they don't receive regular communication so send them * a ping at regular intervals */ @@ -6638,17 +6648,16 @@ static void parse_remote_workers(sdata_t *sdata, json_t *val, const char *buf) * we no longer do it. */ static void parse_remote_blocksubmit(ckpool_t *ckp, json_t *val, const char *buf) { - json_t *submitblock_val; - const char *gbt_block; + char *gbt_block; - submitblock_val = json_object_get(val, "submitblock"); - gbt_block = json_string_value(submitblock_val); + json_strdup(&gbt_block, val, "submitblock"); if (unlikely(!gbt_block)) { LOGWARNING("Failed to get submitblock data from remote message %s", buf); return; } LOGWARNING("Submitting possible downstream block!"); - send_proc(ckp->generator, gbt_block); + generator_submitblock(ckp, gbt_block + 12); + free(gbt_block); } static void parse_remote_block(ckpool_t *ckp, sdata_t *sdata, json_t *val, const char *buf) diff --git a/src/stratifier.h b/src/stratifier.h index 6d4a5774..a7dca212 100644 --- a/src/stratifier.h +++ b/src/stratifier.h @@ -15,6 +15,8 @@ void parse_remote_txns(ckpool_t *ckp, const json_t *val); void parse_upstream_auth(ckpool_t *ckp, json_t *val); char *stratifier_stats(ckpool_t *ckp, void *data); void stratifier_add_recv(ckpool_t *ckp, json_t *val); +void stratifier_block_solve(ckpool_t *ckp, const char *blockhash); +void stratifier_block_reject(ckpool_t *ckp, const char *blockhash); void *stratifier(void *arg); #endif /* STRATIFIER_H */