diff --git a/src/ckpool.c b/src/ckpool.c index 620cd925..31746936 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -883,9 +883,10 @@ static void json_get_int64(int64_t *store, json_t *val, const char *res) return; } *store = json_integer_value(entry); + LOGDEBUG("Json found entry %s: %ld", res, *store); } -static void json_get_int(int *store, json_t *val, const char *res) +void json_get_int(int *store, json_t *val, const char *res) { json_t *entry = json_object_get(val, res); @@ -898,6 +899,7 @@ static void json_get_int(int *store, json_t *val, const char *res) return; } *store = json_integer_value(entry); + LOGDEBUG("Json found entry %s: %d", res, *store); } static void json_get_bool(bool *store, json_t *val, const char *res) @@ -913,6 +915,7 @@ static void json_get_bool(bool *store, json_t *val, const char *res) return; } *store = json_is_true(entry); + LOGDEBUG("Json found entry %s: %s", res, *store ? "true" : "false"); } static void parse_btcds(ckpool_t *ckp, json_t *arr_val, int arr_size) diff --git a/src/ckpool.h b/src/ckpool.h index f5e6aa2b..b1ce196f 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -200,5 +200,6 @@ json_t *json_rpc_call(connsock_t *cs, const char *rpc_req); int process_exit(ckpool_t *ckp, proc_instance_t *pi, int ret); void json_get_string(char **store, json_t *val, const char *res); +void json_get_int(int *store, json_t *val, const char *res); #endif /* CKPOOL_H */ diff --git a/src/libckpool.h b/src/libckpool.h index a769a0ed..26f6e670 100644 --- a/src/libckpool.h +++ b/src/libckpool.h @@ -79,6 +79,16 @@ #define __maybe_unused __attribute__((unused)) #define uninitialised_var(x) x = x +#define MAX(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a > _b ? _a : _b; }) + +#define MIN(a,b) \ + ({ __typeof__ (a) _a = (a); \ + __typeof__ (b) _b = (b); \ + _a < _b ? _a : _b; }) + typedef unsigned char uchar; typedef struct timeval tv_t; diff --git a/src/stratifier.c b/src/stratifier.c index bb431c57..ec2d5bb5 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -245,7 +245,7 @@ struct worker_instance { double dsps1440; tv_t last_share; - int64_t mindiff; /* User chosen mindiff */ + int mindiff; /* User chosen mindiff */ }; /* Per client stratum instance == workers */ @@ -1588,6 +1588,7 @@ static int send_recv_auth(stratum_instance_t *client) free(json_msg); if (likely(buf)) { + worker_instance_t *worker = client->worker_instance; char *cmd = NULL, *secondaryuserid = NULL; char response[PAGESIZE] = {}; json_error_t err_val; @@ -1603,8 +1604,11 @@ static int send_recv_auth(stratum_instance_t *client) val = json_loads(cmd, 0, &err_val); if (unlikely(!val)) LOGWARNING("AUTH JSON decode failed(%d): %s", err_val.line, err_val.text); - else + else { json_get_string(&secondaryuserid, val, "secondaryuserid"); + json_get_int(&worker->mindiff, val, "difficultydefault"); + client->suggest_diff = worker->mindiff; + } if (!safecmp(response, "ok.auth") && secondaryuserid) { if (!user_instance->secondaryuserid) user_instance->secondaryuserid = secondaryuserid; @@ -2667,8 +2671,8 @@ static void sauth_process(ckpool_t *ckp, json_params_t *jp) { json_t *result_val, *json_msg, *err_val = NULL; stratum_instance_t *client; + int mindiff, errnum = 0; int64_t client_id; - int errnum = 0; client_id = jp->client_id; @@ -2698,6 +2702,18 @@ static void sauth_process(ckpool_t *ckp, json_params_t *jp) json_object_set_new_nocheck(json_msg, "error", err_val ? err_val : json_null()); json_object_set_nocheck(json_msg, "id", jp->id_val); stratum_add_send(json_msg, client_id); + + if (!json_is_string(result_val) || !client->suggest_diff) + goto out; + + /* Update the client now if they have set a valid mindiff different + * from the startdiff */ + mindiff = MAX(ckp->mindiff, client->suggest_diff); + mindiff = MIN(ckp->startdiff, mindiff); + if (mindiff != client->diff) { + client->diff = mindiff; + stratum_send_diff(client); + } out: discard_json_params(&jp);