|
|
@@ -265,6 +265,10 @@ static char best_share[8] = "0";
|
|
|
static char block_diff[8];
|
|
|
uint64_t best_diff = 0;
|
|
|
|
|
|
+static bool known_blkheight_current;
|
|
|
+static uint32_t known_blkheight;
|
|
|
+static uint32_t known_blkheight_blkid;
|
|
|
+
|
|
|
struct block {
|
|
|
char hash[40];
|
|
|
UT_hash_handle hh;
|
|
|
@@ -1680,9 +1684,50 @@ void free_work(struct work *work)
|
|
|
|
|
|
static char *workpadding = "000000800000000000000000000000000000000000000000000000000000000000000000000000000000000080020000";
|
|
|
|
|
|
+// Must only be called with ch_lock held!
|
|
|
+static
|
|
|
+void __update_block_title(const unsigned char *hash_swap)
|
|
|
+{
|
|
|
+ char *tmp;
|
|
|
+ if (hash_swap) {
|
|
|
+ // Only provided when the block has actually changed
|
|
|
+ free(current_hash);
|
|
|
+ current_hash = malloc(3 /* ... */ + 16 /* block hash segment */ + 1);
|
|
|
+ tmp = bin2hex(&hash_swap[24], 8);
|
|
|
+ sprintf(current_hash, "...%s", tmp);
|
|
|
+ free(tmp);
|
|
|
+ known_blkheight_current = false;
|
|
|
+ } else if (likely(known_blkheight_current)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (current_block_id == known_blkheight_blkid) {
|
|
|
+ // FIXME: The block number will overflow this sometime around AD 2025-2027
|
|
|
+ if (known_blkheight < 1000000) {
|
|
|
+ memmove(¤t_hash[3], ¤t_hash[11], 8);
|
|
|
+ sprintf(¤t_hash[11], " #%6u", known_blkheight);
|
|
|
+ }
|
|
|
+ known_blkheight_current = true;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+static
|
|
|
+void have_block_height(uint32_t block_id, uint32_t blkheight)
|
|
|
+{
|
|
|
+ if (known_blkheight == blkheight)
|
|
|
+ return;
|
|
|
+ applog(LOG_DEBUG, "Learned that block id %08" PRIx32 " is height %" PRIu32, be32toh(block_id), blkheight);
|
|
|
+ mutex_lock(&ch_lock);
|
|
|
+ known_blkheight = blkheight;
|
|
|
+ known_blkheight_blkid = block_id;
|
|
|
+ if (block_id == current_block_id)
|
|
|
+ __update_block_title(NULL);
|
|
|
+ mutex_unlock(&ch_lock);
|
|
|
+}
|
|
|
+
|
|
|
static bool work_decode(struct pool *pool, struct work *work, json_t *val)
|
|
|
{
|
|
|
json_t *res_val = json_object_get(val, "result");
|
|
|
+ json_t *tmp_val;
|
|
|
bool ret = false;
|
|
|
|
|
|
if (unlikely(detect_algo == 1)) {
|
|
|
@@ -1808,6 +1853,12 @@ static bool work_decode(struct pool *pool, struct work *work, json_t *val)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ if ( (tmp_val = json_object_get(res_val, "height")) ) {
|
|
|
+ uint32_t blkheight = json_number_value(tmp_val);
|
|
|
+ uint32_t block_id = ((uint32_t*)work->data)[1];
|
|
|
+ have_block_height(block_id, blkheight);
|
|
|
+ }
|
|
|
+
|
|
|
memset(work->hash, 0, sizeof(work->hash));
|
|
|
|
|
|
gettimeofday(&work->tv_staged, NULL);
|
|
|
@@ -2157,7 +2208,7 @@ static void curses_print_status(void)
|
|
|
pool->sockaddr_url, pool->diff, have_longpoll ? "": "out", pool->rpc_user);
|
|
|
}
|
|
|
wclrtoeol(statuswin);
|
|
|
- mvwprintw(statuswin, 5, 0, " Block: %s... Diff:%s Started: %s Best share: %s ",
|
|
|
+ mvwprintw(statuswin, 5, 0, " Block: %s Diff:%s Started: %s Best share: %s ",
|
|
|
current_hash, block_diff, blocktime, best_share);
|
|
|
mvwhline(statuswin, 6, 0, '-', 80);
|
|
|
mvwhline(statuswin, statusy - 1, 0, '-', 80);
|
|
|
@@ -4161,9 +4212,7 @@ static void set_curblock(char *hexstr, unsigned char *hash)
|
|
|
* elsewhere - and update block_timeval inside the same lock */
|
|
|
mutex_lock(&ch_lock);
|
|
|
gettimeofday(&block_timeval, NULL);
|
|
|
- old_hash = current_hash;
|
|
|
- current_hash = bin2hex(hash_swap + 4, 8);
|
|
|
- free(old_hash);
|
|
|
+ __update_block_title(hash_swap);
|
|
|
old_hash = current_fullhash;
|
|
|
current_fullhash = bin2hex(hash_swap, 32);
|
|
|
free(old_hash);
|
|
|
@@ -4171,7 +4220,7 @@ static void set_curblock(char *hexstr, unsigned char *hash)
|
|
|
|
|
|
get_timestamp(blocktime, &block_timeval);
|
|
|
|
|
|
- applog(LOG_INFO, "New block: %s... diff %s", current_hash, block_diff);
|
|
|
+ applog(LOG_INFO, "New block: %s diff %s", current_hash, block_diff);
|
|
|
}
|
|
|
|
|
|
/* Search to see if this string is from a block that has been seen before */
|
|
|
@@ -5742,6 +5791,20 @@ static void *stratum_thread(void *userdata)
|
|
|
* block database */
|
|
|
pool->swork.clean = false;
|
|
|
gen_stratum_work(pool, work);
|
|
|
+
|
|
|
+ /* Try to extract block height from coinbase scriptSig */
|
|
|
+ char *hex_height = &pool->swork.coinbase1[8 /*version*/ + 2 /*txin count*/ + 72 /*prevout*/ + 2 /*scriptSig len*/ + 2 /*push opcode*/];
|
|
|
+ unsigned char cb_height_sz;
|
|
|
+ hex2bin(&cb_height_sz, &hex_height[-2], 1);
|
|
|
+ if (cb_height_sz == 3) {
|
|
|
+ // FIXME: The block number will overflow this by AD 2173
|
|
|
+ uint32_t block_id = ((uint32_t*)work->data)[1];
|
|
|
+ uint32_t height = 0;
|
|
|
+ hex2bin((unsigned char*)&height, hex_height, 3);
|
|
|
+ height = le32toh(height);
|
|
|
+ have_block_height(block_id, height);
|
|
|
+ }
|
|
|
+
|
|
|
++pool->work_restart_id;
|
|
|
if (test_work_current(work)) {
|
|
|
/* Only accept a work restart if this stratum
|