From a0d86556a0db616bcdd1d155f4c24b014d147b7b Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 29 Jan 2016 14:45:09 +1100 Subject: [PATCH] Downstream possible block solves to trusted nodes in binary form as well --- src/connector.c | 17 ++++++++++++----- src/stratifier.c | 21 +++++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/connector.c b/src/connector.c index 0b1f9173..55fccb0a 100644 --- a/src/connector.c +++ b/src/connector.c @@ -1152,15 +1152,22 @@ out: static void parse_remote_submitblock(ckpool_t *ckp, const json_t *val, const char *buf) { - const char *gbt_block = json_string_value(json_object_get(val, "submitblock")); - - if (unlikely(!gbt_block)) { - LOGWARNING("Failed to find submitblock data from upstream submitblock method %s", - buf); + json_t *hash_val, *data_val; + const char *hash, *data; + char *gbt_block; + + hash_val = json_object_get(val, "hash"); + hash = json_string_value(hash_val); + data_val = json_object_get(val, "data"); + data = json_string_value(data_val); + if (unlikely(!hash || !data)) { + LOGWARNING("Failed to extract hash and data from remote submitblock msg %s", buf); return; } + ASPRINTF(&gbt_block, "submitblock:%s,%s", hash, data); LOGWARNING("Submitting possible upstream block!"); send_proc(ckp->generator, gbt_block); + free(gbt_block); } static void ping_upstream(cdata_t *cdata) diff --git a/src/stratifier.c b/src/stratifier.c index 386fbaa7..6df7dc05 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1408,7 +1408,8 @@ static void upstream_blocksubmit(ckpool_t *ckp, const char *hash, const char *da free(buf); } -static void downstream_blocksubmits(ckpool_t *ckp, const char *gbt_block, const stratum_instance_t *source) +static void downstream_blocksubmits(ckpool_t *ckp, const char *hash, const char *data, + const stratum_instance_t *source) { stratum_instance_t *client; sdata_t *sdata = ckp->data; @@ -1418,10 +1419,14 @@ static void downstream_blocksubmits(ckpool_t *ckp, const char *gbt_block, const ck_rlock(&sdata->instance_lock); if (sdata->remote_instances) { json_t *val = json_object(); + char *bkey = bkey_object(); + uint32_t bkeylen; + + JSON_CPACK(val, "{ss}", "method", "submitblock"); + bkey_add_hex(bkey, "hash", hash); + bkey_add_hex(bkey, "data", data); + bkeylen = bkey_len(bkey); - JSON_CPACK(val, "{ss,ss}", - "method", "submitblock", - "submitdata", gbt_block); DL_FOREACH(sdata->remote_instances, client) { ckmsg_t *client_msg; smsg_t *msg; @@ -1434,11 +1439,15 @@ static void downstream_blocksubmits(ckpool_t *ckp, const char *gbt_block, const msg = ckzalloc(sizeof(smsg_t)); msg->json_msg = json_msg; msg->client_id = client->id; + msg->bkey = ckalloc(bkeylen); + memcpy(msg->bkey, bkey, bkeylen); + msg->bkeylen = bkeylen; client_msg->data = msg; DL_APPEND(bulk_send, client_msg); messages++; } json_decref(val); + free(bkey); } ck_runlock(&sdata->instance_lock); @@ -1487,7 +1496,7 @@ process_block(ckpool_t *ckp, const workbase_t *wb, const char *coinbase, const i if (ckp->remote) upstream_blocksubmit(ckp, blockhash, gbt_block + 12 + 64 + 1); else - downstream_blocksubmits(ckp, gbt_block, NULL); + downstream_blocksubmits(ckp, blockhash, gbt_block + 12 + 64 + 1, NULL); free(gbt_block); } @@ -6007,7 +6016,7 @@ static void parse_remote_blocksubmit(ckpool_t *ckp, json_t *val, const char *buf ASPRINTF(&gbt_block, "submitblock:%s,%s", hash, data); LOGWARNING("Submitting possible downstream block!"); send_generator(ckp, gbt_block, GEN_PRIORITY); - downstream_blocksubmits(ckp, gbt_block, client); + downstream_blocksubmits(ckp, hash, data, client); free(gbt_block); }