Suspend stratum connections to backup pools when there is no requirement to potentially grab work from them.
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/cgminer.c b/cgminer.c
index 2628b59..beb8716 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -4676,6 +4676,28 @@ static void clear_stratum_shares(struct pool *pool)
}
}
+/* 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)
+{
+ struct pool *cp;
+
+ if (pool_strategy == POOL_BALANCE)
+ return true;
+ if (pool_strategy == POOL_LOADBALANCE)
+ return true;
+ if (opt_fail_only)
+ return true;
+ cp = current_pool();
+ if (cp == pool)
+ return true;
+ if (!cp->has_gbt && !cp->has_stratum)
+ return true;
+ return false;
+}
+
+static void wait_lpcurrent(struct pool *pool);
+
/* 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
@@ -4696,6 +4718,22 @@ static void *stratum_thread(void *userdata)
if (unlikely(pool->removed))
break;
+ /* Check to see whether we need to maintain this connection
+ * indefinitely or just bring it up when we switch to this
+ * pool */
+ if (!cnx_needed(pool)) {
+ suspend_stratum(pool);
+ wait_lpcurrent(pool);
+ if (!initiate_stratum(pool) || !auth_stratum(pool)) {
+ pool_died(pool);
+ while (!initiate_stratum(pool) || !auth_stratum(pool)) {
+ if (pool->removed)
+ goto out;
+ sleep(30);
+ }
+ }
+ }
+
FD_ZERO(&rd);
FD_SET(pool->sock, &rd);
timeout.tv_sec = 90;
diff --git a/util.c b/util.c
index c4b065f..770f1ba 100644
--- a/util.c
+++ b/util.c
@@ -1435,6 +1435,14 @@ out:
return ret;
}
+void suspend_stratum(struct pool *pool)
+{
+ applog(LOG_INFO, "Closing socket for stratum pool %d", pool->pool_no);
+ mutex_lock(&pool->stratum_lock);
+ pool->stratum_active = false;
+ mutex_unlock(&pool->stratum_lock);
+ CLOSESOCKET(pool->sock);
+}
void dev_error(struct cgpu_info *dev, enum dev_reason reason)
{
diff --git a/util.h b/util.h
index d0125ac..253b61d 100644
--- a/util.h
+++ b/util.h
@@ -51,6 +51,7 @@ bool parse_method(struct pool *pool, char *s);
bool extract_sockaddr(struct pool *pool, char *url);
bool auth_stratum(struct pool *pool);
bool initiate_stratum(struct pool *pool);
+void suspend_stratum(struct pool *pool);
void dev_error(struct cgpu_info *dev, enum dev_reason reason);
void *realloc_strcat(char *ptr, char *s);
void RenameThread(const char* name);