diff --git a/src/ckpool.c b/src/ckpool.c index 2640543a..e3d05e91 100644 --- a/src/ckpool.c +++ b/src/ckpool.c @@ -854,6 +854,21 @@ static void json_get_string(char **store, json_t *val, const char *res) *store = strdup(buf); } +static void json_get_int64(int64_t *store, json_t *val, const char *res) +{ + json_t *entry = json_object_get(val, res); + + if (!entry) { + LOGDEBUG("Json did not find entry %s", res); + return; + } + if (!json_is_integer(entry)) { + LOGWARNING("Json entry %s is not an integer", res); + return; + } + *store = json_integer_value(entry); +} + static void json_get_int(int *store, json_t *val, const char *res) { json_t *entry = json_object_get(val, res); @@ -930,8 +945,8 @@ static void parse_config(ckpool_t *ckp) json_get_int(&ckp->blockpoll, json_conf, "blockpoll"); json_get_int(&ckp->update_interval, json_conf, "update_interval"); json_get_string(&ckp->serverurl, json_conf, "serverurl"); - json_get_int(&ckp->mindiff, json_conf, "mindiff"); - json_get_int(&ckp->startdiff, json_conf, "startdiff"); + json_get_int64(&ckp->mindiff, json_conf, "mindiff"); + json_get_int64(&ckp->startdiff, json_conf, "startdiff"); json_get_string(&ckp->logdir, json_conf, "logdir"); arr_val = json_object_get(json_conf, "proxy"); if (arr_val && json_is_array(arr_val)) { diff --git a/src/ckpool.h b/src/ckpool.h index ad738640..6929fe5b 100644 --- a/src/ckpool.h +++ b/src/ckpool.h @@ -146,8 +146,8 @@ struct ckpool_instance { int blockpoll; // How frequently in ms to poll bitcoind for block updates /* Difficulty settings */ - int mindiff; // Default 1 - int startdiff; // Default 42 + int64_t mindiff; // Default 1 + int64_t startdiff; // Default 42 /* Coinbase data */ char *btcaddress; // Address to mine to diff --git a/src/stratifier.c b/src/stratifier.c index 390dcd3c..fbb4adb8 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1408,7 +1408,7 @@ static double sane_tdiff(tv_t *end, tv_t *start) return tdiff; } -static void add_submit(stratum_instance_t *client, int diff, bool valid) +static void add_submit(ckpool_t *ckp, stratum_instance_t *client, int diff, bool valid) { double tdiff, bdiff, dsps, drr, network_diff, bias; int64_t next_blockid, optimal; @@ -1467,23 +1467,18 @@ static void add_submit(stratum_instance_t *client, int diff, bool valid) return; optimal = round(dsps * 3.33); - if (optimal <= client->ckp->mindiff) { - if (client->diff == client->ckp->mindiff) - return; - optimal = client->ckp->mindiff; - } - - if (optimal > network_diff) { - /* Intentionally round down here */ - optimal = network_diff; - if (client->diff == optimal) - return; - } - /* Don't drop diff to rapidly in case the client simply switched away * and has just returned */ if (optimal < client->diff / 2) optimal = client->diff / 2; + /* Clamp to mindiff ~ network_diff */ + if (optimal < ckp->mindiff) + optimal = ckp->mindiff; + if (optimal > network_diff) + optimal = network_diff; + if (client->diff == optimal) + return; + client->ssdc = 0; LOGINFO("Client %d biased dsps %.2f dsps %.2f drr %.2f adjust diff from %ld to: %ld ", @@ -1812,7 +1807,7 @@ out_unlock: } } else LOGINFO("Rejected client %d invalid share", client->id); - add_submit(client, diff, result); + add_submit(ckp, client, diff, result); /* Now write to the pool's sharelog. */ val = json_object();