Commit a70629a7012600bc55b0a4b3c1e4e253ee6a3733

Con Kolivas 2011-11-01T15:19:26

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.

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;
 };