Browse Source

Make sure jobids align between generator and stratifier in proxy mode

master
Con Kolivas 10 years ago
parent
commit
b36e4cec3c
  1. 21
      src/generator.c
  2. 7
      src/stratifier.c

21
src/generator.c

@ -24,7 +24,7 @@
struct notify_instance { struct notify_instance {
/* Hash table data */ /* Hash table data */
UT_hash_handle hh; UT_hash_handle hh;
int id; int64_t id;
char prevhash[68]; char prevhash[68];
char *jobid; char *jobid;
@ -121,7 +121,7 @@ struct proxy_instance {
typedef struct proxy_instance proxy_instance_t; typedef struct proxy_instance proxy_instance_t;
static int proxy_notify_id; // Globally increasing notify id static int64_t proxy_notify_id; // Globally increasing notify id
static ckmsgq_t *srvchk; // Server check message queue static ckmsgq_t *srvchk; // Server check message queue
@ -731,7 +731,7 @@ static bool parse_notify(proxy_instance_t *proxi, json_t *val)
mutex_lock(&proxi->notify_lock); mutex_lock(&proxi->notify_lock);
ni->id = proxy_notify_id++; ni->id = proxy_notify_id++;
HASH_ADD_INT(proxi->notify_instances, id, ni); HASH_ADD_I64(proxi->notify_instances, id, ni);
proxi->current_notify = ni; proxi->current_notify = ni;
mutex_unlock(&proxi->notify_lock); mutex_unlock(&proxi->notify_lock);
@ -991,7 +991,7 @@ static void send_notify(proxy_instance_t *proxi, int sockd)
for (i = 0; i < ni->merkles; i++) for (i = 0; i < ni->merkles; i++)
json_array_append_new(merkle_arr, json_string(&ni->merklehash[i][0])); json_array_append_new(merkle_arr, json_string(&ni->merklehash[i][0]));
/* Use our own jobid instead of the server's one for easy lookup */ /* Use our own jobid instead of the server's one for easy lookup */
JSON_CPACK(json_msg, "{sisssssssosssssssb}", JSON_CPACK(json_msg, "{sIsssssssosssssssb}",
"jobid", ni->id, "prevhash", ni->prevhash, "jobid", ni->id, "prevhash", ni->prevhash,
"coinbase1", ni->coinbase1, "coinbase2", ni->coinbase2, "coinbase1", ni->coinbase1, "coinbase2", ni->coinbase2,
"merklehash", merkle_arr, "bbversion", ni->bbversion, "merklehash", merkle_arr, "bbversion", ni->bbversion,
@ -1189,7 +1189,7 @@ static void *proxy_send(void *arg)
char *jobid = NULL; char *jobid = NULL;
bool ret = true; bool ret = true;
json_t *val; json_t *val;
uint32_t id; int64_t id;
mutex_lock(&proxi->psend_lock); mutex_lock(&proxi->psend_lock);
if (!proxi->psends) if (!proxi->psends)
@ -1202,10 +1202,10 @@ static void *proxy_send(void *arg)
if (unlikely(!msg)) if (unlikely(!msg))
continue; continue;
json_uintcpy(&id, msg->json_msg, "jobid"); json_int64cpy(&id, msg->json_msg, "jobid");
mutex_lock(&proxi->notify_lock); mutex_lock(&proxi->notify_lock);
HASH_FIND_INT(proxi->notify_instances, &id, ni); HASH_FIND_I64(proxi->notify_instances, &id, ni);
if (ni) if (ni)
jobid = strdup(ni->jobid); jobid = strdup(ni->jobid);
mutex_unlock(&proxi->notify_lock); mutex_unlock(&proxi->notify_lock);
@ -1221,7 +1221,7 @@ static void *proxy_send(void *arg)
ret = send_json_msg(cs, val); ret = send_json_msg(cs, val);
json_decref(val); json_decref(val);
} else } else
LOGWARNING("Failed to find matching jobid in proxysend"); LOGWARNING("Failed to find matching jobid for %016lx in proxysend", id);
json_decref(msg->json_msg); json_decref(msg->json_msg);
free(msg); free(msg);
if (!ret && cs->fd > 0) { if (!ret && cs->fd > 0) {
@ -1631,6 +1631,11 @@ static int proxy_mode(ckpool_t *ckp, proc_instance_t *pi)
} }
} }
/* Set the initial id to time as high bits so as to not send the same
* id on restarts */
proxy_notify_id = ((int64_t)time(NULL)) << 32;
LOGDEBUG("Setting proxy notify id to %016lx", proxy_notify_id);
LOGWARNING("%s generator ready", ckp->name); LOGWARNING("%s generator ready", ckp->name);
ret = proxy_loop(pi); ret = proxy_loop(pi);

7
src/stratifier.c

@ -557,8 +557,14 @@ static void add_base(ckpool_t *ckp, workbase_t *wb, bool *new_block)
len = strlen(ckp->logdir) + 8 + 1 + 16 + 1; len = strlen(ckp->logdir) + 8 + 1 + 16 + 1;
wb->logdir = ckalloc(len); wb->logdir = ckalloc(len);
/* In proxy mode, the wb->id is received in the notify update and
* we set workbase_id from it. In server mode the stratifier is
* setting the workbase_id */
ck_wlock(&workbase_lock); ck_wlock(&workbase_lock);
if (!ckp->proxy)
wb->id = workbase_id++; wb->id = workbase_id++;
else
workbase_id = wb->id;
if (strncmp(wb->prevhash, lasthash, 64)) { if (strncmp(wb->prevhash, lasthash, 64)) {
char bin[32], swap[32]; char bin[32], swap[32];
@ -2820,6 +2826,7 @@ int stratifier(proc_instance_t *pi)
/* Set the initial id to time as high bits so as to not send the same /* Set the initial id to time as high bits so as to not send the same
* id on restarts */ * id on restarts */
if (!ckp->proxy)
blockchange_id = workbase_id = ((int64_t)time(NULL)) << 32; blockchange_id = workbase_id = ((int64_t)time(NULL)) << 32;
dealloc(buf); dealloc(buf);

Loading…
Cancel
Save