Make longpoll do a mandatory flushing of all work even if the block hasn't changed, thus supporting longpoll initiated work change of any sort and merged mining.
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
diff --git a/main.c b/main.c
index 8e0df82..34701d6 100644
--- a/main.c
+++ b/main.c
@@ -267,6 +267,7 @@ static int total_accepted, total_rejected;
static int total_getworks, total_stale, total_discarded;
static int total_queued;
static unsigned int new_blocks;
+static unsigned int work_block;
static unsigned int found_blocks;
static unsigned int local_work;
@@ -2614,7 +2615,6 @@ static bool stale_work(struct work *work, bool share)
{
struct timeval now;
bool ret = false;
- char *hexstr;
gettimeofday(&now, NULL);
if (share) {
@@ -2627,16 +2627,8 @@ static bool stale_work(struct work *work, bool share)
if (donor(work->pool))
return ret;
- hexstr = bin2hex(work->data, 18);
- if (unlikely(!hexstr)) {
- applog(LOG_ERR, "submit_work_thread OOM");
- return ret;
- }
-
- if (strcmp(hexstr, current_block))
+ if (work->work_block != work_block)
ret = true;
-
- free(hexstr);
return ret;
}
@@ -2916,9 +2908,11 @@ static void test_work_current(struct work *work, bool longpoll)
HASH_ADD_STR(blocks, hash, s);
wr_unlock(&blk_lock);
set_curblock(hexstr, work->data);
- if (++new_blocks == 1)
+ if (unlikely(++new_blocks == 1))
goto out_free;
+ work_block++;
+
if (longpoll)
applog(LOG_NOTICE, "LONGPOLL detected new block on network, waiting on fresh work");
else if (have_longpoll)
@@ -2926,6 +2920,10 @@ static void test_work_current(struct work *work, bool longpoll)
else
applog(LOG_NOTICE, "New block detected on network, waiting on fresh work");
restart_threads();
+ } else if (longpoll) {
+ applog(LOG_NOTICE, "LONGPOLL requested work restart, waiting on fresh work");
+ work_block++;
+ restart_threads();
}
out_free:
free(hexstr);
@@ -2972,6 +2970,7 @@ static void *stage_thread(void *userdata)
ok = false;
break;
}
+ work->work_block = work_block;
test_work_current(work, false);
diff --git a/miner.h b/miner.h
index b981a99..e301a68 100644
--- a/miner.h
+++ b/miner.h
@@ -478,6 +478,7 @@ struct work {
bool cloned;
bool rolltime;
+ unsigned int work_block;
int id;
UT_hash_handle hh;
};