Browse Source

Implement basics of vmask support for ckproxy.

master
Con Kolivas 7 years ago
parent
commit
23102d1417
  1. 2
      src/ckpool.h
  2. 13
      src/generator.c
  3. 52
      src/stratifier.c

2
src/ckpool.h

@ -302,6 +302,7 @@ enum stratum_msgtype {
SM_WORKERSTATS, SM_WORKERSTATS,
SM_REQTXNS, SM_REQTXNS,
SM_CONFIGURE, SM_CONFIGURE,
SM_VERSIONMASK,
SM_NONE SM_NONE
}; };
@ -329,6 +330,7 @@ static const char __maybe_unused *stratum_msgs[] = {
"workerstats", "workerstats",
"reqtxns", "reqtxns",
"mining.configure", "mining.configure",
"vmask",
"" ""
}; };

13
src/generator.c

@ -1892,7 +1892,7 @@ static void *proxy_send(void *arg)
int64_t client_id = 0, id; int64_t client_id = 0, id;
notify_instance_t *ni; notify_instance_t *ni;
json_t *jobid = NULL; json_t *jobid = NULL;
json_t *val; json_t *val, *vmask;
if (unlikely(msg)) { if (unlikely(msg)) {
json_decref(msg->json_msg); json_decref(msg->json_msg);
@ -1961,12 +1961,23 @@ static void *proxy_send(void *arg)
continue; continue;
} }
vmask = json_object_get(msg->json_msg, "vmask");
if (vmask) {
JSON_CPACK(val, "{s[sooooo]soss}", "params", subproxy->auth, jobid,
json_object_dup(msg->json_msg, "nonce2"),
json_object_dup(msg->json_msg, "ntime"),
json_object_dup(msg->json_msg, "nonce"),
json_copy(vmask),
"id", json_object_dup(msg->json_msg, "id"),
"method", "mining.submit");
} else {
JSON_CPACK(val, "{s[soooo]soss}", "params", subproxy->auth, jobid, JSON_CPACK(val, "{s[soooo]soss}", "params", subproxy->auth, jobid,
json_object_dup(msg->json_msg, "nonce2"), json_object_dup(msg->json_msg, "nonce2"),
json_object_dup(msg->json_msg, "ntime"), json_object_dup(msg->json_msg, "ntime"),
json_object_dup(msg->json_msg, "nonce"), json_object_dup(msg->json_msg, "nonce"),
"id", json_object_dup(msg->json_msg, "id"), "id", json_object_dup(msg->json_msg, "id"),
"method", "mining.submit"); "method", "mining.submit");
}
add_json_msgq(&csmsgq, subproxy, &val); add_json_msgq(&csmsgq, subproxy, &val);
send_json_msgq(gdata, &csmsgq); send_json_msgq(gdata, &csmsgq);
} }

52
src/stratifier.c

@ -236,6 +236,9 @@ struct stratum_instance {
* or other problem and should be dropped lazily if * or other problem and should be dropped lazily if
* this is set to 2 */ * this is set to 2 */
bool vmask; /* Requested vmask */
uint32_t version_mask; /* Mask to use for this client */
int latency; /* Latency when on a mining node */ int latency; /* Latency when on a mining node */
bool reconnect; /* This client really needs to reconnect */ bool reconnect; /* This client really needs to reconnect */
@ -3055,7 +3058,7 @@ void stratum_set_proxy_vmask(ckpool_t *ckp, int id, int subid, uint32_t version_
proxy = existing_subproxy(ckp->sdata, id, subid); proxy = existing_subproxy(ckp->sdata, id, subid);
proxy->version_mask = version_mask; proxy->version_mask = version_mask;
LOGWARNING("Stratum Proxy %d:%d had version mask set to %x", id, subid, version_mask); LOGWARNING("Stratum Proxy %d:%d had version mask set to %08x", id, subid, version_mask);
} }
static void stratum_send_diff(sdata_t *sdata, const stratum_instance_t *client); static void stratum_send_diff(sdata_t *sdata, const stratum_instance_t *client);
@ -5719,20 +5722,6 @@ static void stratum_send_diff(sdata_t *sdata, const stratum_instance_t *client)
stratum_add_send(sdata, json_msg, client->id, SM_DIFF); stratum_add_send(sdata, json_msg, client->id, SM_DIFF);
} }
#if 0
/* Needs to be entered with client holding a ref count. */
static void stratum_send_version_mask(sdata_t *sdata, const stratum_instance_t *client)
{
char version_str[12];
json_t *json_msg;
sprintf(version_str, "%08x", client->ckp->version_mask);
JSON_CPACK(json_msg, "{s[s]soss}", "params", version_str, "id", json_null(),
"method", "mining.set_version_mask");
stratum_add_send(sdata, json_msg, client->id, SM_VERSIONMASK);
}
#endif
/* Needs to be entered with client holding a ref count. */ /* Needs to be entered with client holding a ref count. */
static void stratum_send_message(sdata_t *sdata, const stratum_instance_t *client, const char *msg) static void stratum_send_message(sdata_t *sdata, const stratum_instance_t *client, const char *msg)
{ {
@ -6027,7 +6016,7 @@ static void update_client(const stratum_instance_t *client, const int64_t client
/* Submit a share in proxy mode to the parent pool. workbase_lock is held. /* Submit a share in proxy mode to the parent pool. workbase_lock is held.
* Needs to be entered with client holding a ref count. */ * Needs to be entered with client holding a ref count. */
static void submit_share(stratum_instance_t *client, const int64_t jobid, const char *nonce2, static void submit_share(stratum_instance_t *client, const int64_t jobid, const char *nonce2,
const char *ntime, const char *nonce) const char *ntime, const char *nonce, const char *version_mask)
{ {
ckpool_t *ckp = client->ckp; ckpool_t *ckp = client->ckp;
json_t *json_msg; json_t *json_msg;
@ -6037,6 +6026,8 @@ static void submit_share(stratum_instance_t *client, const int64_t jobid, const
JSON_CPACK(json_msg, "{sIsssssssIsIsi}", "jobid", jobid, "nonce2", enonce2, JSON_CPACK(json_msg, "{sIsssssssIsIsi}", "jobid", jobid, "nonce2", enonce2,
"ntime", ntime, "nonce", nonce, "client_id", client->id, "ntime", ntime, "nonce", nonce, "client_id", client->id,
"proxy", client->proxyid, "subproxy", client->subproxyid); "proxy", client->proxyid, "subproxy", client->subproxyid);
if (version_mask)
json_set_string(json_msg, "vmask", version_mask);
generator_add_send(ckp, json_msg); generator_add_send(ckp, json_msg);
} }
@ -6135,7 +6126,7 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg,
if (version_mask && strlen(version_mask) && validhex(version_mask)) { if (version_mask && strlen(version_mask) && validhex(version_mask)) {
sscanf(version_mask, "%x", &version_mask32); sscanf(version_mask, "%x", &version_mask32);
// check version mask // check version mask
if (version_mask32 && ((~ckp->version_mask) & version_mask32) != 0) { if (version_mask32 && ((~client->version_mask) & version_mask32) != 0) {
// means client changed some bits which server doesn't allow to change // means client changed some bits which server doesn't allow to change
err = SE_INVALID_VERSION_MASK; err = SE_INVALID_VERSION_MASK;
*err_val = JSON_ERR(err); *err_val = JSON_ERR(err);
@ -6262,7 +6253,7 @@ out_nowb:
* stale shares and filter out the rest. */ * stale shares and filter out the rest. */
if (wb && wb->proxy && submit) { if (wb && wb->proxy && submit) {
LOGINFO("Submitting share upstream: %s", hexhash); LOGINFO("Submitting share upstream: %s", hexhash);
submit_share(client, id, nonce2, ntime, nonce); submit_share(client, id, nonce2, ntime, nonce, version_mask);
} }
add_submit(ckp, client, diff, result, submit); add_submit(ckp, client, diff, result, submit);
@ -6486,11 +6477,30 @@ static void suggest_diff(ckpool_t *ckp, stratum_instance_t *client, const char *
stratum_send_diff(ckp->sdata, client); stratum_send_diff(ckp->sdata, client);
} }
/* Needs to be entered with client holding a ref count */
static void stratum_send_version_mask(sdata_t *sdata, stratum_instance_t *client)
{
char version_str[12];
json_t *json_msg;
if (unlikely(!client->proxy)) {
LOGERR("stratum_send_version_mask called on a non proxied client");
return;
}
client->version_mask = client->proxy->version_mask;
sprintf(version_str, "%08x", client->version_mask);
JSON_CPACK(json_msg, "{s[s]soss}", "params", version_str, "id", json_null(),
"method", "mining.set_version_mask");
stratum_add_send(sdata, json_msg, client->id, SM_VERSIONMASK);
}
/* Send diff first when sending the first stratum template after subscribing */ /* Send diff first when sending the first stratum template after subscribing */
static void init_client(const stratum_instance_t *client, const int64_t client_id) static void init_client(stratum_instance_t *client, const int64_t client_id)
{ {
sdata_t *sdata = client->sdata; sdata_t *sdata = client->sdata;
if (client->vmask)
stratum_send_version_mask(client->sdata, client);
stratum_send_diff(sdata, client); stratum_send_diff(sdata, client);
stratum_send_update(sdata, client_id, true); stratum_send_update(sdata, client_id, true);
} }
@ -6699,7 +6709,11 @@ static void parse_method(ckpool_t *ckp, sdata_t *sdata, stratum_instance_t *clie
LOGINFO("Mining configure requested from %s %s", client->identity, LOGINFO("Mining configure requested from %s %s", client->identity,
client->address); client->address);
client->vmask = true;
/* Send a temporary vmask in proxy mode till we know what the
* real vmask will be for the upstream pool. */
sprintf(version_str, "%08x", ckp->version_mask); sprintf(version_str, "%08x", ckp->version_mask);
client->version_mask = ckp->version_mask;
val = json_object(); val = json_object();
JSON_CPACK(result_val, "{sbss}", "version-rolling", json_true(), JSON_CPACK(result_val, "{sbss}", "version-rolling", json_true(),
"version-rolling.mask", version_str); "version-rolling.mask", version_str);

Loading…
Cancel
Save