From 0465fef5535e55c5284404e59192659b16bcadb0 Mon Sep 17 00:00:00 2001 From: Con Kolivas Date: Mon, 5 Nov 2012 23:22:36 +1100 Subject: [PATCH] Discard record of stratum shares sent and report lost shares on disconnection since they will never be reported back. --- cgminer.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/cgminer.c b/cgminer.c index 0ac54da5..9139412a 100644 --- a/cgminer.c +++ b/cgminer.c @@ -4305,6 +4305,25 @@ out: static void pool_resus(struct pool *pool); +static void clear_stratum_shares(struct pool *pool) +{ + struct stratum_share *sshare, *tmpshare; + int cleared = 0; + + mutex_lock(&sshare_lock); + HASH_ITER(hh, stratum_shares, sshare, tmpshare) { + if (sshare->work.pool == pool) { + HASH_DEL(stratum_shares, sshare); + free(sshare); + cleared++; + } + } + mutex_unlock(&sshare_lock); + + if (cleared) + applog(LOG_WARNING, "Lost %d shares due to stratum disconnect on pool %d", cleared, pool->pool_no); +} + /* One stratum thread per pool that has stratum waits on the socket checking * for new messages and for the integrity of the socket connection. We reset * the connection based on the integrity of the receive side only as the send @@ -4341,6 +4360,11 @@ static void *stratum_thread(void *userdata) pool->getfail_occasions++; total_go++; + /* If the socket to our stratum pool disconnects, all + * tracked submitted shares are lost and we will leak + * the memory if we don't discard their records. */ + clear_stratum_shares(pool); + if (initiate_stratum(pool) && auth_stratum(pool)) continue;