Browse Source

Try to extract block height from coinbase scriptSig, when mining stratum

Luke Dashjr 13 years ago
parent
commit
e9025bf001
1 changed files with 14 additions and 0 deletions
  1. 14 0
      miner.c

+ 14 - 0
miner.c

@@ -5784,6 +5784,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