From e441e65c538ae4c2a44a4a097b876fcbf022eb57 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Fri, 26 Sep 2014 21:20:35 +1000 Subject: [PATCH] Ping miners regularly in proxy mode to ensure they don't disconnect when diff is too high for them and they receive no update --- src/stratifier.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/stratifier.c b/src/stratifier.c index ddc1ac45..98e73d4e 100644 --- a/src/stratifier.c +++ b/src/stratifier.c @@ -1144,6 +1144,21 @@ static void block_solve(ckpool_t *ckp) } +/* Some upstream pools (like p2pool) don't update stratum often enough and + * miners disconnect if they don't receive regular communication so send them + * a ping at regular intervals */ +static void broadcast_ping(void) +{ + json_t *json_msg; + + JSON_CPACK(json_msg, "{s:[],s:o,s:s}", + "params", + "id", json_null(), + "method", "mining.ping"); + + stratum_broadcast(json_msg); +} + static int stratum_loop(ckpool_t *ckp, proc_instance_t *pi) { int sockd, ret = 0, selret = 0; @@ -1153,19 +1168,23 @@ static int stratum_loop(ckpool_t *ckp, proc_instance_t *pi) retry: do { - if (!ckp->proxy) { - double tdiff; - tv_t end_tv; - - tv_time(&end_tv); - tdiff = tvdiff(&end_tv, &start_tv); - if (tdiff > ckp->update_interval) { - copy_tv(&start_tv, &end_tv); + double tdiff; + tv_t end_tv; + + tv_time(&end_tv); + tdiff = tvdiff(&end_tv, &start_tv); + if (tdiff > ckp->update_interval) { + copy_tv(&start_tv, &end_tv); + if (!ckp->proxy) { LOGDEBUG("%ds elapsed in strat_loop, updating gbt base", ckp->update_interval); update_base(ckp, GEN_NORMAL); - continue; + } else { + LOGDEBUG("%ds elapsed in strat_loop, pinging miners", + ckp->update_interval); + broadcast_ping(); } + continue; } selret = wait_read_select(us->sockd, 5); if (!selret && !ping_main(ckp)) {