From 90782542f8ecfd14f1813bd40fb4b913d1f70485 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 21 Aug 2014 10:53:39 +1000 Subject: [PATCH 1/5] Change attempted block submission to 99%+ only --- src/stratifier.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index 2c57f24f..390dcd3c 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1510,8 +1510,8 @@ test_blocksolve(stratum_instance_t *client, workbase_t *wb, const uchar *data, c ckpool_t *ckp; ts_t ts_now; - /* Submit anything over 95% of the diff in case of rounding errors */ - if (diff < current_workbase->network_diff * 0.95) + /* Submit anything over 99% of the diff in case of rounding errors */ + if (diff < current_workbase->network_diff * 0.99) return; LOGWARNING("Possible block solve diff %f !", diff); From a95c259839ec0adcaedef424ee9c5013e1cdf35d Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 21 Aug 2014 11:17:19 +1000 Subject: [PATCH 2/5] Clamp optimal diff after all calculations are made and store min and start diff as long integers --- src/ckpool.c | 19 +++++++++++++++++-- src/ckpool.h | 4 ++-- src/stratifier.c | 25 ++++++++++--------------- 3 files changed, 29 insertions(+), 19 deletions(-) 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(); From 03ba50a3e294a15ca2f53a585b9c8b56db88d7f0 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 21 Aug 2014 12:14:28 +1000 Subject: [PATCH 3/5] Workbase_id should be updated even in proxy mode or diff will only change once --- src/stratifier.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index fbb4adb8..f8574ffc 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -522,8 +522,7 @@ static void add_base(ckpool_t *ckp, workbase_t *wb, bool *new_block) wb->logdir = ckalloc(len); ck_wlock(&workbase_lock); - if (!ckp->proxy) - wb->id = workbase_id++; + wb->id = workbase_id++; if (strncmp(wb->prevhash, lasthash, 64)) { *new_block = true; From 5ef0829c74802f1482d02f664b62c7ce80facc5b Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 21 Aug 2014 12:26:19 +1000 Subject: [PATCH 4/5] Don't bother counting share diff until it matches the client set diff and don't reproduce the diff change job id test already performed when determining diff in parse_submit --- src/stratifier.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index f8574ffc..c6004513 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1450,12 +1450,10 @@ static void add_submit(ckpool_t *ckp, stratum_instance_t *client, int diff, bool if (client->ssdc < 72 && tdiff < 240) return; - if (diff != client->diff) - return; - - /* We have the effect of a change pending */ - if (client->diff_change_job_id >= next_blockid) + if (diff != client->diff) { + client->ssdc = 0; return; + } /* Diff rate ratio */ dsps = client->dsps5 / bias; From 31221dd0b46dc5590d2cdc3d47f9ae255fd2e194 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Thu, 21 Aug 2014 13:27:29 +1000 Subject: [PATCH 5/5] Clamp max diff in proxy mode to the current upstream pool's diff --- src/stratifier.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index c6004513..fc8a0914 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1417,7 +1417,10 @@ static void add_submit(ckpool_t *ckp, stratum_instance_t *client, int diff, bool ck_rlock(&workbase_lock); next_blockid = workbase_id + 1; - network_diff = current_workbase->network_diff; + if (ckp->proxy) + network_diff = current_workbase->diff; + else + network_diff = current_workbase->network_diff; ck_runlock(&workbase_lock); tdiff = sane_tdiff(&now_t, &client->last_share); @@ -1770,7 +1773,7 @@ static json_t *parse_submit(stratum_instance_t *client, json_t *json_msg, goto out_unlock; } invalid = false; - if (wb->proxy && sdiff > wdiff) + if (wb->proxy && sdiff >= wdiff) submit = true; out_unlock: ck_runlock(&workbase_lock);