Browse Source

Parse upstream requests for transactions, returning any found in the remote's transaction table.

master
Con Kolivas 8 years ago
parent
commit
3e954e225f
  1. 2
      src/connector.c
  2. 44
      src/stratifier.c
  3. 1
      src/stratifier.h

2
src/connector.c

@ -1202,6 +1202,8 @@ static void *urecv_process(void *arg)
parse_upstream_workinfo(ckp, val); parse_upstream_workinfo(ckp, val);
else if (!safecmp(method, stratum_msgs[SM_BLOCK])) else if (!safecmp(method, stratum_msgs[SM_BLOCK]))
parse_upstream_block(ckp, val); parse_upstream_block(ckp, val);
else if (!safecmp(method, stratum_msgs[SM_REQTXNS]))
parse_upstream_reqtxns(ckp, val);
else if (!safecmp(method, "pong")) else if (!safecmp(method, "pong"))
LOGDEBUG("Received upstream pong"); LOGDEBUG("Received upstream pong");
else else

44
src/stratifier.c

@ -7046,27 +7046,49 @@ static json_t *get_hash_transactions(sdata_t *sdata, const json_t *hashes)
return txn_array; return txn_array;
} }
static void parse_remote_reqtxns(sdata_t *sdata, json_t *val, const int64_t client_id) static json_t *get_reqtxns(sdata_t *sdata, json_t *val, bool downstream)
{ {
json_t *hashes = json_object_get(val, "hash"); json_t *hashes = json_object_get(val, "hash");
json_t *txns, *ret = NULL;
int requested, found; int requested, found;
json_t *txns;
if (unlikely(!hashes) || !json_is_array(hashes)) if (unlikely(!hashes) || !json_is_array(hashes))
return; goto out;
requested = json_array_size(hashes); requested = json_array_size(hashes);
if (unlikely(!requested)) if (unlikely(!requested))
return; goto out;
txns = get_hash_transactions(sdata, hashes); txns = get_hash_transactions(sdata, hashes);
found = json_array_size(txns); found = json_array_size(txns);
if (!found) if (found) {
return json_decref(txns); JSON_CPACK(ret, "{ssso}", "method", stratum_msgs[SM_TRANSACTIONS], "transaction", txns);
/* Reuse val variable */ LOGINFO("Sending %d found of %d requested txns %s", found, requested,
JSON_CPACK(val, "{ssso}", "method", stratum_msgs[SM_TRANSACTIONS], "transaction", txns); downstream ? "downstream" : "upstream");
stratum_add_send(sdata, val, client_id, SM_TRANSACTIONS); } else
LOGINFO("Sending %d found of %d requested txns to remote client %"PRId64, json_decref(txns);
found, requested, client_id); out:
return ret;
}
static void parse_remote_reqtxns(sdata_t *sdata, json_t *val, const int64_t client_id)
{
json_t *ret = get_reqtxns(sdata, val, true);
if (!ret)
return;
stratum_add_send(sdata, ret, client_id, SM_TRANSACTIONS);
}
void parse_upstream_reqtxns(ckpool_t *ckp, json_t *val)
{
json_t *ret = get_reqtxns(ckp->sdata, val, false);
char *msg;
if (!ret)
return;
msg = json_dumps(ret, JSON_NO_UTF8 | JSON_PRESERVE_ORDER | JSON_COMPACT | JSON_EOL);
json_decref(ret);
connector_upstream_msg(ckp, msg);
} }
static void parse_trusted_msg(ckpool_t *ckp, sdata_t *sdata, json_t *val, stratum_instance_t *client) static void parse_trusted_msg(ckpool_t *ckp, sdata_t *sdata, json_t *val, stratum_instance_t *client)

1
src/stratifier.h

@ -15,6 +15,7 @@ void parse_remote_txns(ckpool_t *ckp, const json_t *val);
void parse_upstream_auth(ckpool_t *ckp, json_t *val); void parse_upstream_auth(ckpool_t *ckp, json_t *val);
void parse_upstream_workinfo(ckpool_t *ckp, json_t *val); void parse_upstream_workinfo(ckpool_t *ckp, json_t *val);
void parse_upstream_block(ckpool_t *ckp, json_t *val); void parse_upstream_block(ckpool_t *ckp, json_t *val);
void parse_upstream_reqtxns(ckpool_t *ckp, json_t *val);
char *stratifier_stats(ckpool_t *ckp, void *data); char *stratifier_stats(ckpool_t *ckp, void *data);
void stratifier_add_recv(ckpool_t *ckp, json_t *val); void stratifier_add_recv(ckpool_t *ckp, json_t *val);
void stratifier_block_solve(ckpool_t *ckp, const char *blockhash); void stratifier_block_solve(ckpool_t *ckp, const char *blockhash);

Loading…
Cancel
Save