Browse Source

Downstream possible block solves to trusted nodes in binary form as well

master
Con Kolivas 9 years ago
parent
commit
a0d86556a0
  1. 17
      src/connector.c
  2. 21
      src/stratifier.c

17
src/connector.c

@ -1152,15 +1152,22 @@ out:
static void parse_remote_submitblock(ckpool_t *ckp, const json_t *val, const char *buf) 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")); json_t *hash_val, *data_val;
const char *hash, *data;
if (unlikely(!gbt_block)) { char *gbt_block;
LOGWARNING("Failed to find submitblock data from upstream submitblock method %s",
buf); 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; return;
} }
ASPRINTF(&gbt_block, "submitblock:%s,%s", hash, data);
LOGWARNING("Submitting possible upstream block!"); LOGWARNING("Submitting possible upstream block!");
send_proc(ckp->generator, gbt_block); send_proc(ckp->generator, gbt_block);
free(gbt_block);
} }
static void ping_upstream(cdata_t *cdata) static void ping_upstream(cdata_t *cdata)

21
src/stratifier.c

@ -1408,7 +1408,8 @@ static void upstream_blocksubmit(ckpool_t *ckp, const char *hash, const char *da
free(buf); 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; stratum_instance_t *client;
sdata_t *sdata = ckp->data; 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); ck_rlock(&sdata->instance_lock);
if (sdata->remote_instances) { if (sdata->remote_instances) {
json_t *val = json_object(); 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) { DL_FOREACH(sdata->remote_instances, client) {
ckmsg_t *client_msg; ckmsg_t *client_msg;
smsg_t *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 = ckzalloc(sizeof(smsg_t));
msg->json_msg = json_msg; msg->json_msg = json_msg;
msg->client_id = client->id; msg->client_id = client->id;
msg->bkey = ckalloc(bkeylen);
memcpy(msg->bkey, bkey, bkeylen);
msg->bkeylen = bkeylen;
client_msg->data = msg; client_msg->data = msg;
DL_APPEND(bulk_send, client_msg); DL_APPEND(bulk_send, client_msg);
messages++; messages++;
} }
json_decref(val); json_decref(val);
free(bkey);
} }
ck_runlock(&sdata->instance_lock); 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) if (ckp->remote)
upstream_blocksubmit(ckp, blockhash, gbt_block + 12 + 64 + 1); upstream_blocksubmit(ckp, blockhash, gbt_block + 12 + 64 + 1);
else else
downstream_blocksubmits(ckp, gbt_block, NULL); downstream_blocksubmits(ckp, blockhash, gbt_block + 12 + 64 + 1, NULL);
free(gbt_block); 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); ASPRINTF(&gbt_block, "submitblock:%s,%s", hash, data);
LOGWARNING("Submitting possible downstream block!"); LOGWARNING("Submitting possible downstream block!");
send_generator(ckp, gbt_block, GEN_PRIORITY); send_generator(ckp, gbt_block, GEN_PRIORITY);
downstream_blocksubmits(ckp, gbt_block, client); downstream_blocksubmits(ckp, hash, data, client);
free(gbt_block); free(gbt_block);
} }

Loading…
Cancel
Save