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. 11
      src/stratifier.c

21
src/generator.c

@ -24,7 +24,7 @@
struct notify_instance {
/* Hash table data */
UT_hash_handle hh;
int id;
int64_t id;
char prevhash[68];
char *jobid;
@ -121,7 +121,7 @@ struct proxy_instance {
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
@ -731,7 +731,7 @@ static bool parse_notify(proxy_instance_t *proxi, json_t *val)
mutex_lock(&proxi->notify_lock);
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;
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++)
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 */
JSON_CPACK(json_msg, "{sisssssssosssssssb}",
JSON_CPACK(json_msg, "{sIsssssssosssssssb}",
"jobid", ni->id, "prevhash", ni->prevhash,
"coinbase1", ni->coinbase1, "coinbase2", ni->coinbase2,
"merklehash", merkle_arr, "bbversion", ni->bbversion,
@ -1189,7 +1189,7 @@ static void *proxy_send(void *arg)
char *jobid = NULL;
bool ret = true;
json_t *val;
uint32_t id;
int64_t id;
mutex_lock(&proxi->psend_lock);
if (!proxi->psends)
@ -1202,10 +1202,10 @@ static void *proxy_send(void *arg)
if (unlikely(!msg))
continue;
json_uintcpy(&id, msg->json_msg, "jobid");
json_int64cpy(&id, msg->json_msg, "jobid");
mutex_lock(&proxi->notify_lock);
HASH_FIND_INT(proxi->notify_instances, &id, ni);
HASH_FIND_I64(proxi->notify_instances, &id, ni);
if (ni)
jobid = strdup(ni->jobid);
mutex_unlock(&proxi->notify_lock);
@ -1221,7 +1221,7 @@ static void *proxy_send(void *arg)
ret = send_json_msg(cs, val);
json_decref(val);
} 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);
free(msg);
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);
ret = proxy_loop(pi);

11
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;
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);
wb->id = workbase_id++;
if (!ckp->proxy)
wb->id = workbase_id++;
else
workbase_id = wb->id;
if (strncmp(wb->prevhash, lasthash, 64)) {
char bin[32], swap[32];
@ -2820,7 +2826,8 @@ int stratifier(proc_instance_t *pi)
/* Set the initial id to time as high bits so as to not send the same
* id on restarts */
blockchange_id = workbase_id = ((int64_t)time(NULL)) << 32;
if (!ckp->proxy)
blockchange_id = workbase_id = ((int64_t)time(NULL)) << 32;
dealloc(buf);

Loading…
Cancel
Save