Discard all staged work from stratum pools as well as the shares upon disconnection since all the work becomes invalid.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
diff --git a/cgminer.c b/cgminer.c
index c7736cf..55dce4b 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4499,6 +4499,23 @@ static void clear_stratum_shares(struct pool *pool)
}
}
+static void clear_pool_work(struct pool *pool)
+{
+ struct work *work, *tmp;
+ int cleared = 0;
+
+ mutex_lock(stgd_lock);
+ HASH_ITER(hh, staged_work, work, tmp) {
+ if (work->pool == pool) {
+ HASH_DEL(staged_work, work);
+ free_work(work);
+ cleared++;
+ }
+ }
+ mutex_unlock(stgd_lock);
+ applog(LOG_ERR, "Discarded %d stratum works", cleared);
+}
+
/* We only need to maintain a secondary pool connection when we need the
* capacity to get work from the backup pools while still on the primary */
static bool cnx_needed(struct pool *pool)
@@ -4554,6 +4571,9 @@ static void *stratum_thread(void *userdata)
* pool */
if (!cnx_needed(pool)) {
suspend_stratum(pool);
+ clear_stratum_shares(pool);
+ clear_pool_work(pool);
+
wait_lpcurrent(pool);
if (!initiate_stratum(pool) || !auth_stratum(pool)) {
pool_died(pool);
@@ -4587,6 +4607,7 @@ static void *stratum_thread(void *userdata)
* tracked submitted shares are lost and we will leak
* the memory if we don't discard their records. */
clear_stratum_shares(pool);
+ clear_pool_work(pool);
if (initiate_stratum(pool) && auth_stratum(pool))
continue;