Browse Source

Rationalise use of current_hash to a single hex string the length of the previous block and display only the first non zero hex chars of the block in the status window.

Con Kolivas 12 years ago
parent
commit
448b1fae64
3 changed files with 23 additions and 33 deletions
  1. 2 8
      api.c
  2. 20 24
      cgminer.c
  3. 1 1
      miner.h

+ 2 - 8
api.c

@@ -3665,14 +3665,8 @@ static void minecoin(struct io_data *io_data, __maybe_unused SOCKETTYPE c, __may
 		root = api_add_const(root, "Hash Method", SHA256STR, false);
 		root = api_add_const(root, "Hash Method", SHA256STR, false);
 
 
 	cg_rlock(&ch_lock);
 	cg_rlock(&ch_lock);
-	if (current_fullhash && *current_fullhash) {
-		root = api_add_timeval(root, "Current Block Time", &block_timeval, true);
-		root = api_add_string(root, "Current Block Hash", current_fullhash, true);
-	} else {
-		struct timeval t = {0,0};
-		root = api_add_timeval(root, "Current Block Time", &t, true);
-		root = api_add_const(root, "Current Block Hash", BLANK, false);
-	}
+	root = api_add_timeval(root, "Current Block Time", &block_timeval, true);
+	root = api_add_string(root, "Current Block Hash", current_hash, true);
 	cg_runlock(&ch_lock);
 	cg_runlock(&ch_lock);
 
 
 	root = api_add_bool(root, "LP", &have_longpoll, false);
 	root = api_add_bool(root, "LP", &have_longpoll, false);

+ 20 - 24
cgminer.c

@@ -276,11 +276,9 @@ const
 #endif
 #endif
 bool curses_active;
 bool curses_active;
 
 
-static char current_block[40];
-
 /* Protected by ch_lock */
 /* Protected by ch_lock */
-static char *current_hash;
-char *current_fullhash;
+char current_hash[68];
+static char prev_block[12];
 
 
 static char datestamp[40];
 static char datestamp[40];
 static char blocktime[32];
 static char blocktime[32];
@@ -291,7 +289,7 @@ static char block_diff[8];
 uint64_t best_diff = 0;
 uint64_t best_diff = 0;
 
 
 struct block {
 struct block {
-	char hash[40];
+	char hash[68];
 	UT_hash_handle hh;
 	UT_hash_handle hh;
 	int block_no;
 	int block_no;
 };
 };
@@ -2302,7 +2300,7 @@ static void curses_print_status(void)
 	}
 	}
 	wclrtoeol(statuswin);
 	wclrtoeol(statuswin);
 	cg_mvwprintw(statuswin, 5, 0, " Block: %s...  Diff:%s  Started: %s  Best share: %s   ",
 	cg_mvwprintw(statuswin, 5, 0, " Block: %s...  Diff:%s  Started: %s  Best share: %s   ",
-		  current_hash, block_diff, blocktime, best_share);
+		     prev_block, block_diff, blocktime, best_share);
 	mvwhline(statuswin, 6, 0, '-', 80);
 	mvwhline(statuswin, 6, 0, '-', 80);
 	mvwhline(statuswin, statusy - 1, 0, '-', 80);
 	mvwhline(statuswin, statusy - 1, 0, '-', 80);
 	cg_mvwprintw(statuswin, devcursor - 1, 1, "[P]ool management %s[S]ettings [D]isplay options [Q]uit",
 	cg_mvwprintw(statuswin, devcursor - 1, 1, "[P]ool management %s[S]ettings [D]isplay options [Q]uit",
@@ -4017,24 +4015,23 @@ static void signal_work_update(void)
 	rd_unlock(&mining_thr_lock);
 	rd_unlock(&mining_thr_lock);
 }
 }
 
 
-static void set_curblock(char *hexstr, unsigned char *hash)
+static void set_curblock(char *hexstr)
 {
 {
-	unsigned char hash_swap[32];
-	unsigned char block_hash_swap[32];
-
-	strcpy(current_block, hexstr);
-	swap256(hash_swap, hash);
-	swap256(block_hash_swap, hash + 4);
+	int ofs;
 
 
 	cg_wlock(&ch_lock);
 	cg_wlock(&ch_lock);
 	cgtime(&block_timeval);
 	cgtime(&block_timeval);
-	free(current_hash);
-	current_hash = bin2hex(hash_swap + 2, 8);
-	free(current_fullhash);
-	current_fullhash = bin2hex(block_hash_swap, 32);
+	strcpy(current_hash, hexstr);
 	get_timestamp(blocktime, sizeof(blocktime), &block_timeval);
 	get_timestamp(blocktime, sizeof(blocktime), &block_timeval);
 	cg_wunlock(&ch_lock);
 	cg_wunlock(&ch_lock);
 
 
+	for (ofs = 0; ofs <= 56; ofs++) {
+		if (memcmp(&current_hash[ofs], "0", 1))
+			break;
+	}
+	strncpy(prev_block, &current_hash[ofs], 8);
+	prev_block[8] = '\0';
+
 	applog(LOG_INFO, "New block: %s... diff %s", current_hash, block_diff);
 	applog(LOG_INFO, "New block: %s... diff %s", current_hash, block_diff);
 }
 }
 
 
@@ -4086,16 +4083,15 @@ static void set_blockdiff(const struct work *work)
 
 
 static bool test_work_current(struct work *work)
 static bool test_work_current(struct work *work)
 {
 {
+	unsigned char bedata[32];
+	char hexstr[68];
 	bool ret = true;
 	bool ret = true;
-	char hexstr[40];
 
 
 	if (work->mandatory)
 	if (work->mandatory)
 		return ret;
 		return ret;
 
 
-	/* Hack to work around dud work sneaking into test */
-	__bin2hex(hexstr, work->data + 8, 18);
-	if (!strncmp(hexstr, "000000000000000000000000000000000000", 36))
-		return ret;
+	swap256(bedata, work->data + 4);
+	__bin2hex(hexstr, bedata, 32);
 
 
 	/* 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 */
@@ -4128,7 +4124,7 @@ static bool test_work_current(struct work *work)
 
 
 		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);
-		set_curblock(hexstr, work->data);
+		set_curblock(hexstr);
 		if (unlikely(new_blocks == 1))
 		if (unlikely(new_blocks == 1))
 			return ret;
 			return ret;
 
 
@@ -8004,7 +8000,7 @@ int main(int argc, char *argv[])
 	for (i = 0; i < 36; i++)
 	for (i = 0; i < 36; i++)
 		strcat(block->hash, "0");
 		strcat(block->hash, "0");
 	HASH_ADD_STR(blocks, hash, block);
 	HASH_ADD_STR(blocks, hash, block);
-	strcpy(current_block, block->hash);
+	strcpy(current_hash, block->hash);
 
 
 	INIT_LIST_HEAD(&scan_devices);
 	INIT_LIST_HEAD(&scan_devices);
 
 

+ 1 - 1
miner.h

@@ -1187,7 +1187,7 @@ extern unsigned int total_go, total_ro;
 extern const int opt_cutofftemp;
 extern const int opt_cutofftemp;
 extern int opt_log_interval;
 extern int opt_log_interval;
 extern unsigned long long global_hashrate;
 extern unsigned long long global_hashrate;
-extern char *current_fullhash;
+extern char current_hash[68];
 extern double current_diff;
 extern double current_diff;
 extern uint64_t best_diff;
 extern uint64_t best_diff;
 extern struct timeval block_timeval;
 extern struct timeval block_timeval;