Force a mandatory work item on pool switch and determine what to do based on server supporting roll time or not.
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
diff --git a/main.c b/main.c
index 0e145da..3424042 100644
--- a/main.c
+++ b/main.c
@@ -1413,6 +1413,8 @@ static void flush_requests(bool longpoll)
static bool get_work(struct work *work, bool queued)
{
+ struct timespec abstime = {};
+ struct timeval now;
struct work *work_heap;
struct pool *pool;
bool ret = false;
@@ -1425,7 +1427,7 @@ retry:
goto out;
}
- if (!requests_staged() && !stale_work(work)) {
+ if (!requests_staged() && !stale_work(work) && work->pool->has_rolltime) {
uint32_t *work_ntime;
uint32_t ntime;
@@ -1443,15 +1445,16 @@ retry:
if (total_pools > 1) {
/* Attempt to switch pools if this one has been unresponsive for >half
* a block's duration */
- if (diff.tv_sec > 300) {
+ if (diff.tv_sec > 30) {
switch_pools();
+ inc_staged(pool, 1, true);
goto retry;
}
} else if (diff.tv_sec > 600) {
/* A new block appears on average every 10 mins */
applog(LOG_WARNING, "Prolonged outage. Going idle till network recovers.");
/* Force every thread to wait for new work */
- inc_staged(pool, mining_threads, true);
+ inc_staged(pool, 1, true);
goto retry;
}
}
@@ -1465,11 +1468,22 @@ retry:
goto out;
}
+ gettimeofday(&now, NULL);
+ abstime.tv_sec = now.tv_sec + 60;
+
/* wait for 1st response, or get cached response */
- work_heap = tq_pop(getq, NULL);
+ work_heap = tq_pop(getq, &abstime);
if (unlikely(!work_heap)) {
- applog(LOG_WARNING, "Failed to tq_pop in get_work");
- goto out;
+ if (total_pools > 1) {
+ /* Attempt to switch pools if this one has mandatory
+ * work that has timed out or does not support rolltime */
+ switch_pools();
+ inc_staged(pool, 1, true);
+ goto retry;
+ }
+ if (!pool_tset(pool, &pool->localgen))
+ applog(LOG_WARNING, "Timed out waiting for work from server");
+ goto retry;
}
/* If we make it here we have succeeded in getting fresh work */