Create a work item from a "clean" request from stratum allowing the new block to be detected and the appropriate block change message to be given.
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
diff --git a/cgminer.c b/cgminer.c
index cb0ef19..af8c63a 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -3043,17 +3043,18 @@ static int block_sort(struct block *blocka, struct block *blockb)
return blocka->block_no - blockb->block_no;
}
-static void test_work_current(struct work *work)
+static bool test_work_current(struct work *work)
{
+ bool ret = true;
char *hexstr;
if (work->mandatory)
- return;
+ return ret;
hexstr = bin2hex(work->data, 18);
if (unlikely(!hexstr)) {
applog(LOG_ERR, "stage_thread OOM");
- return;
+ return ret;
}
/* Search to see if this block exists yet and if not, consider it a
@@ -3061,6 +3062,7 @@ static void test_work_current(struct work *work)
if (!block_exists(hexstr)) {
struct block *s = calloc(sizeof(struct block), 1);
int deleted_block = 0;
+ ret = false;
if (unlikely(!s))
quit (1, "test_work_current OOM");
@@ -3098,8 +3100,8 @@ static void test_work_current(struct work *work)
applog(LOG_NOTICE, "New block detected on network before longpoll");
else
applog(LOG_NOTICE, "New block detected on network");
- restart_threads();
}
+ restart_threads();
} else if (work->longpoll) {
work->longpoll = false;
if (work->pool == current_pool()) {
@@ -3111,6 +3113,7 @@ static void test_work_current(struct work *work)
}
out_free:
free(hexstr);
+ return ret;
}
static int tv_sort(struct work *worka, struct work *workb)
@@ -4145,10 +4148,20 @@ static void *stratum_thread(void *userdata)
if (!parse_method(pool, s) && !parse_stratum_response(s))
applog(LOG_INFO, "Unknown stratum msg: %s", s);
free(s);
- if (unlikely(pool->swork.clean)) {
+ if (pool->swork.clean) {
+ struct work work;
+
+ /* Generate a single work item to update the current
+ * block database */
pool->swork.clean = false;
- applog(LOG_NOTICE, "Stratum requested work restart for block change");
- restart_threads();
+ gen_stratum_work(pool, &work);
+ if (test_work_current(&work)) {
+ if (pool == current_pool()) {
+ restart_threads();
+ applog(LOG_NOTICE, "Stratum requested work restart for block change");
+ }
+ } else
+ applog(LOG_NOTICE, "Stratum from pool %d detected new block", pool->pool_no);
}
if (unlikely(pool->removed)) {