From 14a843026575b1b2ec2fe591c8e5e4890d91eba0 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 19 May 2014 00:03:33 +1000 Subject: [PATCH] Propagate the upstream pool's diff to clients as soon as it has dropped if it's below their current setting --- src/stratifier.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/stratifier.c b/src/stratifier.c index 5a9fb04c..9bc2d22b 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -541,10 +541,13 @@ static void update_notify(ckpool_t *ckp) stratum_broadcast_update(new_block | clean); } +static void stratum_send_diff(stratum_instance_t *client); + static void update_diff(ckpool_t *ckp) { + stratum_instance_t *client; + double old_diff, diff; json_t *val; - double diff; char *buf; buf = send_recv_proc(ckp->generator, "getdiff"); @@ -560,8 +563,23 @@ static void update_diff(ckpool_t *ckp) json_decref(val); ck_wlock(&workbase_lock); + old_diff = proxy_base.diff; current_workbase->diff = proxy_base.diff = diff; ck_wunlock(&workbase_lock); + + if (old_diff < diff) + return; + + /* If the diff has dropped, iterated over all the clients and check + * they're at or below the new diff, and update it if not. */ + ck_rlock(&instance_lock); + for (client = stratum_instances; client != NULL; client = client->hh.next) { + if (client->diff > diff) { + client->diff = diff; + stratum_send_diff(client); + } + } + ck_runlock(&instance_lock); } /* Enter with instance_lock held */