Browse Source

Move block_time to be per block_info

Luke Dashjr 11 years ago
parent
commit
88ba5ad183
3 changed files with 9 additions and 10 deletions
  1. 4 3
      api.c
  2. 3 3
      miner.c
  3. 2 4
      miner.h

+ 4 - 3
api.c

@@ -3078,9 +3078,10 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may
 	cg_rlock(&ch_lock);
 	cg_rlock(&ch_lock);
 	struct mining_goal_info * const goal = &global_mining_goal;
 	struct mining_goal_info * const goal = &global_mining_goal;
 	struct blockchain_info * const blkchain = goal->blkchain;
 	struct blockchain_info * const blkchain = goal->blkchain;
-	root = api_add_time(root, "Current Block Time", &blkchain->block_time, true);
-	char fullhash[(sizeof(blkchain->currentblk->prevblkhash) * 2) + 1];
-	blkhashstr(fullhash, blkchain->currentblk->prevblkhash);
+	struct block_info * const blkinfo = blkchain->currentblk;
+	root = api_add_time(root, "Current Block Time", &blkinfo->first_seen_time, true);
+	char fullhash[(sizeof(blkinfo->prevblkhash) * 2) + 1];
+	blkhashstr(fullhash, blkinfo->prevblkhash);
 	root = api_add_string(root, "Current Block Hash", fullhash, true);
 	root = api_add_string(root, "Current Block Hash", fullhash, true);
 	cg_runlock(&ch_lock);
 	cg_runlock(&ch_lock);
 
 

+ 3 - 3
miner.c

@@ -4317,7 +4317,7 @@ one_workable_pool: ;
 	}
 	}
 	wclrtoeol(statuswin);
 	wclrtoeol(statuswin);
 	cg_mvwprintw(statuswin, 3, 0, " Block: %s  Diff:%s (%s)  Started: %s",
 	cg_mvwprintw(statuswin, 3, 0, " Block: %s  Diff:%s (%s)  Started: %s",
-		  goal->current_goal_detail, goal->current_diff_str, goal->net_hashrate, blkchain->block_time_str);
+		  goal->current_goal_detail, goal->current_diff_str, goal->net_hashrate, blkchain->currentblk_first_seen_time_str);
 	
 	
 	char bwstr[(ALLOC_H2B_SHORT*2)+3+1], incomestr[ALLOC_H2B_SHORT+6+1];
 	char bwstr[(ALLOC_H2B_SHORT*2)+3+1], incomestr[ALLOC_H2B_SHORT+6+1];
 	if (blkchain->currentblk->height)
 	if (blkchain->currentblk->height)
@@ -6849,9 +6849,8 @@ void set_curblock(struct block_info * const blkinfo)
 	blkchain->currentblk_subsidy = 5000000000LL >> (blkinfo->height / 210000);
 	blkchain->currentblk_subsidy = 5000000000LL >> (blkinfo->height / 210000);
 
 
 	cg_wlock(&ch_lock);
 	cg_wlock(&ch_lock);
-	blkchain->block_time = time(NULL);
 	__update_block_title();
 	__update_block_title();
-	get_timestamp(blkchain->block_time_str, sizeof(blkchain->block_time_str), blkchain->block_time);
+	get_timestamp(blkchain->currentblk_first_seen_time_str, sizeof(blkchain->currentblk_first_seen_time_str), blkinfo->first_seen_time);
 	cg_wunlock(&ch_lock);
 	cg_wunlock(&ch_lock);
 
 
 	applog(LOG_INFO, "New block: %s diff %s (%s)", goal->current_goal_detail, goal->current_diff_str, goal->net_hashrate);
 	applog(LOG_INFO, "New block: %s diff %s (%s)", goal->current_goal_detail, goal->current_diff_str, goal->net_hashrate);
@@ -6934,6 +6933,7 @@ static bool test_work_current(struct work *work)
 		memcpy(s->prevblkhash, prevblkhash, sizeof(s->prevblkhash));
 		memcpy(s->prevblkhash, prevblkhash, sizeof(s->prevblkhash));
 		s->block_id = block_id;
 		s->block_id = block_id;
 		s->block_seen_order = new_blocks++;
 		s->block_seen_order = new_blocks++;
+		s->first_seen_time = time(NULL);
 		
 		
 		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

+ 2 - 4
miner.h

@@ -1128,6 +1128,7 @@ struct block_info {
 	uint8_t prevblkhash[0x20];
 	uint8_t prevblkhash[0x20];
 	unsigned block_seen_order;  // new_blocks when this block was first seen; was 'block_no'
 	unsigned block_seen_order;  // new_blocks when this block was first seen; was 'block_no'
 	uint32_t height;
 	uint32_t height;
+	time_t first_seen_time;
 	
 	
 	UT_hash_handle hh;
 	UT_hash_handle hh;
 };
 };
@@ -1136,10 +1137,7 @@ struct blockchain_info {
 	struct block_info *blocks;
 	struct block_info *blocks;
 	struct block_info *currentblk;
 	struct block_info *currentblk;
 	uint64_t currentblk_subsidy;  // only valid when height is known! (and assumes Bitcoin)
 	uint64_t currentblk_subsidy;  // only valid when height is known! (and assumes Bitcoin)
-	
-	/* Protected by ch_lock */
-	char block_time_str[0x20];  // was global blocktime
-	time_t block_time;
+	char currentblk_first_seen_time_str[0x20];  // was global blocktime
 };
 };
 
 
 struct mining_goal_info {
 struct mining_goal_info {