Browse Source

Calculate current_fullhash only when needed (for RPC 'coins')

Luke Dashjr 11 years ago
parent
commit
7e1f24efea
3 changed files with 13 additions and 21 deletions
  1. 4 8
      api.c
  2. 0 12
      miner.c
  3. 9 1
      miner.h

+ 4 - 8
api.c

@@ -3078,14 +3078,10 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may
 	cg_rlock(&ch_lock);
 	struct mining_goal_info * const goal = &global_mining_goal;
 	struct blockchain_info * const blkchain = goal->blkchain;
-	if (blkchain->current_fullhash && *blkchain->current_fullhash) {
-		root = api_add_time(root, "Current Block Time", &blkchain->block_time, true);
-		root = api_add_string(root, "Current Block Hash", blkchain->current_fullhash, true);
-	} else {
-		time_t t = 0;
-		root = api_add_time(root, "Current Block Time", &t, true);
-		root = api_add_const(root, "Current Block Hash", BLANK, false);
-	}
+	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);
+	root = api_add_string(root, "Current Block Hash", fullhash, true);
 	cg_runlock(&ch_lock);
 
 	root = api_add_bool(root, "LP", &have_longpoll, false);

+ 0 - 12
miner.c

@@ -371,14 +371,6 @@ static char datestamp[40];
 static char best_share[ALLOC_H2B_SHORTV] = "0";
 double best_diff = 0;
 
-struct block_info {
-	uint32_t block_id;
-	uint8_t prevblkhash[0x20];
-	unsigned block_seen_order;  // new_blocks when this block was first seen; was 'block_no'
-	
-	UT_hash_handle hh;
-};
-
 static struct blockchain_info global_blkchain;
 struct mining_goal_info global_mining_goal = {
 	.blkchain = &global_blkchain,
@@ -6824,7 +6816,6 @@ static void restart_threads(void)
 	rd_unlock(&mining_thr_lock);
 }
 
-static
 void blkhashstr(char *rv, const unsigned char *hash)
 {
 	unsigned char hash_swap[32];
@@ -6848,9 +6839,6 @@ void set_curblock(struct block_info * const blkinfo)
 	cg_wlock(&ch_lock);
 	blkchain->block_time = time(NULL);
 	__update_block_title(hash_swap);
-	free(blkchain->current_fullhash);
-	blkchain->current_fullhash = malloc(65);
-	bin2hex(blkchain->current_fullhash, hash_swap, 32);
 	get_timestamp(blkchain->block_time_str, sizeof(blkchain->block_time_str), blkchain->block_time);
 	cg_wunlock(&ch_lock);
 

+ 9 - 1
miner.h

@@ -1061,6 +1061,7 @@ extern void clear_stratum_shares(struct pool *pool);
 extern void hashmeter2(struct thr_info *);
 extern bool stale_work(struct work *, bool share);
 extern bool stale_work_future(struct work *, bool share, unsigned long ustime);
+extern void blkhashstr(char *out, const unsigned char *hash);
 extern void set_target_to_pdiff(void *dest_target, double pdiff);
 #define bdiff_to_pdiff(n) (n * 1.0000152587)
 extern void set_target_to_bdiff(void *dest_target, double bdiff);
@@ -1122,12 +1123,19 @@ extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user
 #define MAX_GPU_INTENSITY MAX_SHA_INTENSITY
 #endif
 
+struct block_info {
+	uint32_t block_id;
+	uint8_t prevblkhash[0x20];
+	unsigned block_seen_order;  // new_blocks when this block was first seen; was 'block_no'
+	
+	UT_hash_handle hh;
+};
+
 struct blockchain_info {
 	struct block_info *blocks;
 	struct block_info *currentblk;
 	
 	/* Protected by ch_lock */
-	char *current_fullhash;
 	char block_time_str[0x20];  // was global blocktime
 	time_t block_time;