From 81638e5a0628b2a7b651c9a2048498131af3c35c Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Wed, 2 Mar 2016 08:05:23 +1100 Subject: [PATCH] Correctly reset worker diff when it's set to zero via ckdb --- src/stratifier.c | 90 ++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 66bc831f..9cfe10fd 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -4772,7 +4772,51 @@ static user_instance_t *generate_user(ckpool_t *ckp, stratum_instance_t *client, return user; } -static void set_worker_mindiff(ckpool_t *ckp, const char *workername, int mindiff); +static void set_worker_mindiff(ckpool_t *ckp, const char *workername, int mindiff) +{ + stratum_instance_t *client; + sdata_t *sdata = ckp->sdata; + worker_instance_t *worker; + user_instance_t *user; + + /* Find the user first */ + user = user_by_workername(sdata, workername); + + /* Then find the matching worker user */ + worker = get_worker(sdata, user, workername); + + if (mindiff < 1) { + if (likely(!mindiff)) { + worker->mindiff = 0; + return; + } + LOGINFO("Worker %s requested invalid diff %d", worker->workername, mindiff); + return; + } + if (mindiff < ckp->mindiff) + mindiff = ckp->mindiff; + if (mindiff == worker->mindiff) + return; + worker->mindiff = mindiff; + + /* Iterate over all the workers from this user to find any with the + * matching worker that are currently live and send them a new diff + * if we can. Otherwise it will only act as a clamp on next share + * submission. */ + ck_rlock(&sdata->instance_lock); + DL_FOREACH(user->clients, client) { + if (client->worker_instance != worker) + continue; + /* Per connection suggest diff overrides worker mindiff ugh */ + if (mindiff < client->suggest_diff) + continue; + if (mindiff == client->diff) + continue; + client->diff = mindiff; + stratum_send_diff(sdata, client); + } + ck_runlock(&sdata->instance_lock); +} static void parse_worker_diffs(ckpool_t *ckp, json_t *worker_array) { @@ -5748,50 +5792,6 @@ static json_params_t return jp; } -static void set_worker_mindiff(ckpool_t *ckp, const char *workername, int mindiff) -{ - stratum_instance_t *client; - sdata_t *sdata = ckp->sdata; - worker_instance_t *worker; - user_instance_t *user; - - /* Find the user first */ - user = user_by_workername(sdata, workername); - - /* Then find the matching worker user */ - worker = get_worker(sdata, user, workername); - - if (mindiff < 0) { - LOGINFO("Worker %s requested invalid diff %d", worker->workername, mindiff); - return; - } - if (!mindiff) - mindiff = ckp->startdiff; - if (mindiff < ckp->mindiff) - mindiff = ckp->mindiff; - if (mindiff == worker->mindiff) - return; - worker->mindiff = mindiff; - - /* Iterate over all the workers from this user to find any with the - * matching worker that are currently live and send them a new diff - * if we can. Otherwise it will only act as a clamp on next share - * submission. */ - ck_rlock(&sdata->instance_lock); - DL_FOREACH(user->clients, client) { - if (client->worker_instance != worker) - continue; - /* Per connection suggest diff overrides worker mindiff ugh */ - if (mindiff < client->suggest_diff) - continue; - if (mindiff == client->diff) - continue; - client->diff = mindiff; - stratum_send_diff(sdata, client); - } - ck_runlock(&sdata->instance_lock); -} - /* Implement support for the diff in the params as well as the originally * documented form of placing diff within the method. Needs to be entered with * client holding a ref count. */