Browse Source

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.

Con Kolivas 14 years ago
parent
commit
a70629a701
2 changed files with 11 additions and 11 deletions
  1. 10 11
      main.c
  2. 1 0
      miner.h

+ 10 - 11
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);
 

+ 1 - 0
miner.h

@@ -478,6 +478,7 @@ struct work {
 	bool		cloned;
 	bool		rolltime;
 
+	unsigned int	work_block;
 	int		id;
 	UT_hash_handle hh;
 };