Only internally test for block changes when the work matches the current pool to prevent interleaved block change timing on multipools.
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 88 89 90 91 92 93 94 95 96 97 98
diff --git a/main.c b/main.c
index 099f0cf..ae68559 100644
--- a/main.c
+++ b/main.c
@@ -1095,6 +1095,11 @@ static bool stale_work(struct work *work)
bool ret = false;
char *hexstr;
+ /* Only use the primary pool for determination as the work may
+ * interleave at times of new blocks */
+ if (work->pool != current_pool())
+ return ret;
+
if (!strncmp(blank, current_block, 36))
return ret;
@@ -1304,6 +1309,40 @@ static void set_curblock(char *hexstr)
tm.tm_sec);
}
+static void test_work_current(struct work *work)
+{
+ char *hexstr;
+
+ /* Only use the primary pool for determination */
+ if (work->pool != current_pool())
+ return;
+
+ hexstr = bin2hex(work->data, 36);
+ if (unlikely(!hexstr)) {
+ applog(LOG_ERR, "stage_thread OOM");
+ return;
+ }
+
+ /* current_block is blanked out on successful longpoll */
+ if (likely(strncmp(current_block, blank, 36))) {
+ if (unlikely(strncmp(hexstr, current_block, 36))) {
+ new_blocks++;
+ if (have_longpoll)
+ applog(LOG_WARNING, "New block detected on network before longpoll, waiting on fresh work");
+ else
+ applog(LOG_WARNING, "New block detected on network, waiting on fresh work");
+ /* As we can't flush the work from here, signal the
+ * wakeup thread to restart all the threads */
+ work_restart[watchdog_thr_id].restart = 1;
+ set_curblock(hexstr);
+ }
+ } else {
+ set_curblock(hexstr);
+ memcpy(longpoll_block, hexstr, 36);
+ }
+ free(hexstr);
+}
+
static void *stage_thread(void *userdata)
{
struct thr_info *mythr = userdata;
@@ -1313,7 +1352,6 @@ static void *stage_thread(void *userdata)
while (ok) {
struct work *work = NULL;
- char *hexstr;
work = tq_pop(mythr->q, NULL);
if (unlikely(!work)) {
@@ -1322,31 +1360,7 @@ static void *stage_thread(void *userdata)
break;
}
- hexstr = bin2hex(work->data, 36);
- if (unlikely(!hexstr)) {
- applog(LOG_ERR, "stage_thread OOM");
- break;
- }
-
- /* current_block is blanked out on successful longpoll */
- if (likely(strncmp(current_block, blank, 36))) {
- if (unlikely(strncmp(hexstr, current_block, 36))) {
- new_blocks++;
- if (have_longpoll)
- applog(LOG_WARNING, "New block detected on network before longpoll, waiting on fresh work");
- else
- applog(LOG_WARNING, "New block detected on network, waiting on fresh work");
- /* As we can't flush the work from here, signal
- * the wakeup thread to restart all the
- * threads */
- work_restart[watchdog_thr_id].restart = 1;
- set_curblock(hexstr);
- }
- } else {
- set_curblock(hexstr);
- memcpy(longpoll_block, hexstr, 36);
- }
- free(hexstr);
+ test_work_current(work);
if (unlikely(!tq_push(getq, work))) {
applog(LOG_ERR, "Failed to tq_push work in stage_thread");