Instead of keeping track of when the last work item was generated to keep stratum connections open, keep them open if any shares have been submitted awaiting a response.
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
diff --git a/cgminer.c b/cgminer.c
index 61267d6..b504b79 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3264,6 +3264,7 @@ static void *submit_work_thread(void *userdata)
applog(LOG_WARNING, "Pool %d communication resumed, submitting work", pool->pool_no);
mutex_lock(&sshare_lock);
HASH_ADD_INT(stratum_shares, id, sshare);
+ pool->sshares++;
mutex_unlock(&sshare_lock);
applog(LOG_DEBUG, "Successfully submitted, adding to stratum_shares db");
submitted = true;
@@ -3749,7 +3750,6 @@ static void stage_work(struct work *work)
{
applog(LOG_DEBUG, "Pushing work from pool %d to hash queue", work->pool->pool_no);
work->work_block = work_block;
- work->pool->last_work_time = time(NULL);
test_work_current(work);
hash_push(work);
}
@@ -4704,8 +4704,10 @@ static bool parse_stratum_response(struct pool *pool, char *s)
id = json_integer_value(id_val);
mutex_lock(&sshare_lock);
HASH_FIND_INT(stratum_shares, &id, sshare);
- if (sshare)
+ if (sshare) {
HASH_DEL(stratum_shares, sshare);
+ pool->sshares--;
+ }
mutex_unlock(&sshare_lock);
if (!sshare) {
if (json_is_true(res_val))
@@ -4738,6 +4740,7 @@ void clear_stratum_shares(struct pool *pool)
HASH_DEL(stratum_shares, sshare);
diff_cleared += sshare->work->work_difficulty;
free_work(sshare->work);
+ pool->sshares--;
free(sshare);
cleared++;
}
@@ -4792,9 +4795,9 @@ static bool cnx_needed(struct pool *pool)
return true;
if (!cp->has_gbt && !cp->has_stratum && (!opt_fail_only || !cp->hdr_path))
return true;
- /* Keep the connection open to allow any stray shares to be submitted
- * on switching pools for 2 minutes. */
- if (time(NULL) < pool->last_work_time + 120)
+ /* If we're waiting for a response from shares submitted, keep the
+ * connection open. */
+ if (pool->sshares)
return true;
return false;
}
@@ -5181,7 +5184,6 @@ static struct work *hash_pop(void)
/* Signal hash_pop again in case there are mutliple hash_pop waiters */
pthread_cond_signal(&getq->cond);
mutex_unlock(stgd_lock);
- work->pool->last_work_time = time(NULL);
return work;
}
diff --git a/miner.h b/miner.h
index 4c34131..544d1fa 100644
--- a/miner.h
+++ b/miner.h
@@ -972,7 +972,6 @@ struct pool {
pthread_cond_t cr_cond;
struct list_head curlring;
- time_t last_work_time;
time_t last_share_time;
double last_share_diff;
uint64_t best_diff;
@@ -1000,6 +999,7 @@ struct pool {
struct stratum_work swork;
pthread_t stratum_thread;
pthread_mutex_t stratum_lock;
+ int sshares; /* stratum shares submitted waiting on response */
/* GBT variables */
bool has_gbt;