From e36e5ce0100b41f720b778fa6bafe74a52ddf0b2 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Sun, 18 May 2014 20:15:07 +1000 Subject: [PATCH] Submit the actual shares sent to the proxy upstream --- src/generator.c | 28 +++++++++++++++++++++++++--- src/stratifier.c | 12 +++++++----- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/generator.c b/src/generator.c index 1aa56e0e..c21da46e 100644 --- a/src/generator.c +++ b/src/generator.c @@ -872,12 +872,16 @@ static void *proxy_recv(void *arg) static void *proxy_send(void *arg) { proxy_instance_t *proxi = (proxy_instance_t *)arg; + connsock_t *cs = proxi->cs; rename_proc("proxysend"); while (42) { + notify_instance_t *instance; stratum_msg_t *msg; - char *buf; + char *jobid; + json_t *val; + uint32_t id; mutex_lock(&proxi->psend_lock); if (!proxi->psends) @@ -890,9 +894,27 @@ static void *proxy_send(void *arg) if (unlikely(!msg)) continue; - buf = json_dumps(msg->json_msg, 0); - LOGDEBUG("Proxysend received: %s", buf); + json_uintcpy(&id, msg->json_msg, "jobid"); + + mutex_lock(&proxi->notify_lock); + HASH_FIND_INT(proxi->notify_instances, &id, instance); + if (instance) + jobid = strdup(instance->jobid); + mutex_unlock(&proxi->notify_lock); + if (!instance) { + LOGWARNING("Failed to find matching jobid in proxysend"); + continue; + } + /* FIXME Use unique IDs and parse responses */ + val = json_pack("{s[ssooo]siss}", "params", proxi->auth, jobid, + json_object_get(msg->json_msg, "nonce2"), + json_object_get(msg->json_msg, "ntime"), + json_object_get(msg->json_msg, "nonce"), + "id", 0, "method", "mining.submit"); + free(jobid); + send_json_msg(cs, val); + json_decref(val); json_decref(msg->json_msg); free(msg); } diff --git a/src/stratifier.c b/src/stratifier.c index 961c85e7..8db001f6 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -175,6 +175,7 @@ struct stratum_instance { char enonce1[32]; uchar enonce1bin[16]; + char enonce1var[12]; uint64_t enonce1_64; int diff; /* Current diff */ @@ -863,6 +864,7 @@ static void new_enonce1(stratum_instance_t *client) if (wb->enonce1constlen) memcpy(client->enonce1bin, wb->enonce1constbin, wb->enonce1constlen); memcpy(client->enonce1bin + wb->enonce1constlen, &client->enonce1_64, wb->enonce1varlen); + __bin2hex(client->enonce1var, &client->enonce1_64, wb->enonce1varlen); __bin2hex(client->enonce1, client->enonce1bin, wb->enonce1constlen + wb->enonce1varlen); ck_wunlock(&workbase_lock); } @@ -1205,16 +1207,16 @@ out_unlock: } /* Submit a share in proxy mode to the parent pool. workbase_lock is held */ -static void __submit_share(workbase_t *wb, const char *jobid, const char *nonce2, - const char *ntime, const char *nonce) +static void __submit_share(stratum_instance_t *client, workbase_t *wb, uint64_t jobid, + const char *nonce2, const char *ntime, const char *nonce) { ckpool_t *ckp = wb->ckp; json_t *json_msg; char enonce2[32]; char *msg; - sprintf(enonce2, "%s%s", wb->enonce1const, nonce2); - json_msg = json_pack("{ssssssss}", "jobid", jobid, "nonce2", enonce2, + sprintf(enonce2, "%s%s", client->enonce1var, nonce2); + json_msg = json_pack("{sissssss}", "jobid", jobid, "nonce2", enonce2, "ntime", ntime, "nonce", nonce); msg = json_dumps(json_msg, 0); json_decref(json_msg); @@ -1312,7 +1314,7 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg, } invalid = false; if (wb->proxy && sdiff > wb->diff) - __submit_share(wb, idstring, nonce2, ntime, nonce); + __submit_share(client, wb, id, nonce2, ntime, nonce); out_unlock: ck_runlock(&workbase_lock);