Browse Source

Partial: test_work_current: Cleanup

Luke Dashjr 11 years ago
parent
commit
f22b5cc030
1 changed files with 46 additions and 30 deletions
  1. 46 30
      miner.c

+ 46 - 30
miner.c

@@ -5793,36 +5793,38 @@ static bool test_work_current(struct work *work)
 {
 {
 	bool ret = true;
 	bool ret = true;
 	char hexstr[65];
 	char hexstr[65];
-
+	
 	if (work->mandatory)
 	if (work->mandatory)
 		return ret;
 		return ret;
-
+	
 	uint32_t block_id = ((uint32_t*)(work->data))[1];
 	uint32_t block_id = ((uint32_t*)(work->data))[1];
-
+	
 	/* Hack to work around dud work sneaking into test */
 	/* Hack to work around dud work sneaking into test */
 	bin2hex(hexstr, work->data + 8, 18);
 	bin2hex(hexstr, work->data + 8, 18);
 	if (!strncmp(hexstr, "000000000000000000000000000000000000", 36))
 	if (!strncmp(hexstr, "000000000000000000000000000000000000", 36))
 		goto out_free;
 		goto out_free;
-
+	
 	/* Search to see if this block exists yet and if not, consider it a
 	/* Search to see if this block exists yet and if not, consider it a
 	 * new block and set the current block details to this one */
 	 * new block and set the current block details to this one */
-	if (!block_exists(hexstr)) {
+	if (!block_exists(hexstr))
+	{
 		struct block *s = calloc(sizeof(struct block), 1);
 		struct block *s = calloc(sizeof(struct block), 1);
 		int deleted_block = 0;
 		int deleted_block = 0;
 		ret = false;
 		ret = false;
-
+		
 		if (unlikely(!s))
 		if (unlikely(!s))
 			quit (1, "test_work_current OOM");
 			quit (1, "test_work_current OOM");
 		strcpy(s->hash, hexstr);
 		strcpy(s->hash, hexstr);
 		s->block_no = new_blocks++;
 		s->block_no = new_blocks++;
-
+		
 		wr_lock(&blk_lock);
 		wr_lock(&blk_lock);
 		/* Only keep the last hour's worth of blocks in memory since
 		/* Only keep the last hour's worth of blocks in memory since
 		 * work from blocks before this is virtually impossible and we
 		 * work from blocks before this is virtually impossible and we
 		 * want to prevent memory usage from continually rising */
 		 * want to prevent memory usage from continually rising */
-		if (HASH_COUNT(blocks) > 6) {
+		if (HASH_COUNT(blocks) > 6)
+		{
 			struct block *oldblock;
 			struct block *oldblock;
-
+			
 			HASH_SORT(blocks, block_sort);
 			HASH_SORT(blocks, block_sort);
 			oldblock = blocks;
 			oldblock = blocks;
 			deleted_block = oldblock->block_no;
 			deleted_block = oldblock->block_no;
@@ -5833,7 +5835,7 @@ static bool test_work_current(struct work *work)
 		set_blockdiff(work);
 		set_blockdiff(work);
 		wr_unlock(&blk_lock);
 		wr_unlock(&blk_lock);
 		work->pool->block_id = block_id;
 		work->pool->block_id = block_id;
-
+		
 		if (deleted_block)
 		if (deleted_block)
 			applog(LOG_DEBUG, "Deleted block %d from database", deleted_block);
 			applog(LOG_DEBUG, "Deleted block %d from database", deleted_block);
 #if BLKMAKER_VERSION > 1
 #if BLKMAKER_VERSION > 1
@@ -5842,35 +5844,47 @@ static bool test_work_current(struct work *work)
 		set_curblock(hexstr, &work->data[4]);
 		set_curblock(hexstr, &work->data[4]);
 		if (unlikely(new_blocks == 1))
 		if (unlikely(new_blocks == 1))
 			goto out_free;
 			goto out_free;
-
-		if (!work->stratum) {
-			if (work->longpoll) {
+		
+		if (!work->stratum)
+		{
+			if (work->longpoll)
+			{
 				applog(LOG_NOTICE, "Longpoll from pool %d detected new block",
 				applog(LOG_NOTICE, "Longpoll from pool %d detected new block",
 				       work->pool->pool_no);
 				       work->pool->pool_no);
-			} else if (have_longpoll)
+			}
+			else
+			if (have_longpoll)
 				applog(LOG_NOTICE, "New block detected on network before longpoll");
 				applog(LOG_NOTICE, "New block detected on network before longpoll");
 			else
 			else
 				applog(LOG_NOTICE, "New block detected on network");
 				applog(LOG_NOTICE, "New block detected on network");
 		}
 		}
 		restart_threads();
 		restart_threads();
-	} else {
+	}
+	else
+	{
 		bool restart = false;
 		bool restart = false;
 		struct pool *curpool = NULL;
 		struct pool *curpool = NULL;
-		if (unlikely(work->pool->block_id != block_id)) {
+		if (unlikely(work->pool->block_id != block_id))
+		{
 			bool was_active = work->pool->block_id != 0;
 			bool was_active = work->pool->block_id != 0;
 			work->pool->block_id = block_id;
 			work->pool->block_id = block_id;
 			if (!work->longpoll)
 			if (!work->longpoll)
 				update_last_work(work);
 				update_last_work(work);
-			if (was_active) {  // Pool actively changed block
+			if (was_active)
+			{
+				// Pool actively changed block
 				if (work->pool == (curpool = current_pool()))
 				if (work->pool == (curpool = current_pool()))
 					restart = true;
 					restart = true;
-				if (block_id == current_block_id) {
+				if (block_id == current_block_id)
+				{
 					// Caught up, only announce if this pool is the one in use
 					// Caught up, only announce if this pool is the one in use
 					if (restart)
 					if (restart)
 						applog(LOG_NOTICE, "%s %d caught up to new block",
 						applog(LOG_NOTICE, "%s %d caught up to new block",
 						       work->longpoll ? "Longpoll from pool" : "Pool",
 						       work->longpoll ? "Longpoll from pool" : "Pool",
 						       work->pool->pool_no);
 						       work->pool->pool_no);
-				} else {
+				}
+				else
+				{
 					// Switched to a block we know, but not the latest... why?
 					// Switched to a block we know, but not the latest... why?
 					// This might detect pools trying to double-spend or 51%,
 					// This might detect pools trying to double-spend or 51%,
 					// but let's not make any accusations until it's had time
 					// but let's not make any accusations until it's had time
@@ -5883,17 +5897,19 @@ static bool test_work_current(struct work *work)
 				}
 				}
 			}
 			}
 		}
 		}
-	  if (work->longpoll) {
-		++work->pool->work_restart_id;
-		update_last_work(work);
-		if ((!restart) && work->pool == current_pool()) {
-			applog(
-			       (opt_quiet_work_updates ? LOG_DEBUG : LOG_NOTICE),
-			       "Longpoll from pool %d requested work update",
-				work->pool->pool_no);
-			restart = true;
-		}
-	  }
+		if (work->longpoll)
+		{
+			++work->pool->work_restart_id;
+			update_last_work(work);
+			if ((!restart) && work->pool == current_pool())
+			{
+				applog(
+				       (opt_quiet_work_updates ? LOG_DEBUG : LOG_NOTICE),
+				       "Longpoll from pool %d requested work update",
+					work->pool->pool_no);
+				restart = true;
+			}
+		}
 		if (restart)
 		if (restart)
 			restart_threads();
 			restart_threads();
 	}
 	}