def update_merkle_root_to_match_coinbase(auxpow_header): coinbase = auxpow_header['parent_coinbase_tx'] revised_coinbase_txid = auxpow.fast_txid(coinbase) revised_merkle_branch = [revised_coinbase_txid] revised_merkle_root = auxpow.calculate_merkle_root( revised_coinbase_txid, revised_merkle_branch, auxpow_header['coinbase_merkle_index']) auxpow_header['parent_header']['merkle_root'] = revised_merkle_root auxpow_header['coinbase_merkle_branch'] = revised_merkle_branch
def test_deserialize_auxpow_header_explicit_coinbase(self): header = self.deserialize_with_auxpow(header_with_mm) header_auxpow = header['powdata']['auxpow'] coinbase_tx = header_auxpow['parent_coinbase_tx'] expected_coinbase_txid = 'e751249a0dfc33c119c2f3375054a8cfe18eacf8291da689cb8f4570afbdb1a3' observed_coinbase_txid = auxpow.fast_txid(coinbase_tx) self.assertEqual(expected_coinbase_txid, observed_coinbase_txid) self.assertEqual(header_auxpow['coinbase_merkle_branch'], [ "5c3158d4f108917fba77f9695650608477456b8f6f06238b1613311aafa74b09", "eebaf1b6b9ab455497e6dd571140f0a3647ce36e1ab3e34a177dacc474a755d9", "b57660b84bf4011d416c6a884c329b092ad0fb0dabce075ed2a830ca14f86cb9", "2f8974fd4f4a648613dbed7544bbfcbbeceaa4c143aaed7812c14cbdb5cd3954", "26fe65cbf0e306f589fe74179b0d8e58ec664971ff8d3d10702803bb0f0a2cbf", "f280de3cf6d62a9b88713435a0319763df2886128a65ddb1af5d9b3ea01d4c07", "52a27c19db70842beba5d65be16d7eb04a9562762859bfb192f9fe65ac5bc8fa", "48ee3a89e348e962228292d9169a650323d0dc16b8c5e3ab84b98d94a2f8a466", "e2d47a5fa5522849202c0d2caa2906c13f8c44e1878420e4d8e8e892ea96097a", "a644bcb70473e2670f047d34da5cb3b6b886949cefee927706c4bf512e1ea73e", "676ac4c906bb6a5da87b20e0d6baf3b3bac55299556ec9e81e81e67bbd719b91", "04b4353b08ffd77e01d57285cbb2f538950d0039995889c685bcdd9c9c181870", ]) coinbase_merkle_index = header_auxpow['coinbase_merkle_index'] self.assertEqual(0, coinbase_merkle_index) self.assertEqual(header_auxpow['chain_merkle_branch'], [ "2cadbb3ce34769fc6f95572012c22605f8c3a69982a9a6854523f6548007d30b", "e5c2407ba454ffeb28cf0c50c5c293a84c9a75788f8a8f35ccb974e606280377", "a5cd51355bea0fd77416d06bf3647e16b4663d2f87e6a3ccb23e713cb8b4de1c", ]) chain_merkle_index = header_auxpow['chain_merkle_index'] self.assertEqual(7, chain_merkle_index) expected_parent_header = blockchain.deserialize_pure_header( bfh('0000ff3f913d01444f14db2c6ab43ffd0f36af5613423815543c22000000000000000000ef6330ff500ba8a2eb0d2e988d3275057fcf81beb55e430e5cdf4a20dee82ad76c83785ba70d2c1728f397b0' ), None) expected_parent_hash = blockchain.hash_header(expected_parent_header) observed_parent_hash = blockchain.hash_header( header_auxpow['parent_header']) self.assertEqual(expected_parent_hash, observed_parent_hash) expected_parent_merkle_root = expected_parent_header['merkle_root'] observed_parent_merkle_root = header_auxpow['parent_header'][ 'merkle_root'] self.assertEqual(expected_parent_merkle_root, observed_parent_merkle_root)
def test_deserialize_auxpow_header_explicit_coinbase(self): header = self.deserialize_with_auxpow(namecoin_header_37174) header_auxpow = header['auxpow'] self.assertEqual(constants.net.AUXPOW_CHAIN_ID, header_auxpow['chain_id']) coinbase_tx = header_auxpow['parent_coinbase_tx'] expected_coinbase_txid = '8a3164be45a621f85318647d425fe9f45837b8e42ec4fdd902d7f64daf61ff4a' observed_coinbase_txid = auxpow.fast_txid(coinbase_tx) self.assertEqual(expected_coinbase_txid, observed_coinbase_txid) self.assertEqual(header_auxpow['coinbase_merkle_branch'], [ "f8f27314022a5165ae122642babb28dd44191dd36f99dad80b4f16b75197dde0", "c8a9dc420e17dee7b04bc0174c7a37ed9e5bc3f0ea0fdfe0b5d24bfc19ecedb0", "0ce9c5b98e212527e4aa7b9298435dc4e8f4dfc4dc63b7c89c06300637c33620", "3b6d0c4122a5b047cb879a440461839f0446f6bd451f01c6f0b14b6624e84136", "458500be38a68b215112df5e52d9c08fdd52034fb2005ce15d2a42be28e436cb", ]) coinbase_merkle_index = header_auxpow['coinbase_merkle_index'] self.assertEqual(0, coinbase_merkle_index) self.assertEqual(header_auxpow['chain_merkle_branch'], [ "000000000000000000000000000000000000000000000000000000000000000a", "65bd8eb2c7e3a3646507977e8659e5396b197f197fbb51e7158927a263798302", "5f961bb13289d705abb28376a01f7097535c95f87b9e719b9ec39d8eb20d72e9", "7cb5fdcc41120d6135a40a6753bddc0c9b675ba2936d2e0cd78cdcb02e6beb50", ]) chain_merkle_index = header_auxpow['chain_merkle_index'] self.assertEqual(11, chain_merkle_index) expected_parent_header = blockchain.deserialize_pure_header( bfh('0100000055a7bc918827dbe7d8027781d803f4b418589b7b9fc03e718a03000000000000625a3d6dc4dfb0ab25f450cd202ff3bdb074f2edde1ddb4af5217e10c9dbafb9639a0a4fd7690d1a25aeaa97' ), None) expected_parent_hash = blockchain.hash_header(expected_parent_header) observed_parent_hash = blockchain.hash_header( header_auxpow['parent_header']) self.assertEqual(expected_parent_hash, observed_parent_hash) expected_parent_merkle_root = expected_parent_header['merkle_root'] observed_parent_merkle_root = header_auxpow['parent_header'][ 'merkle_root'] self.assertEqual(expected_parent_merkle_root, observed_parent_merkle_root)
def update_merkle_root_to_match_coinbase(auxpow_header): """Updates the parent block merkle root This modifies the merkle root in the auxpow's parent block header to match the auxpow coinbase transaction. We need this after modifying the coinbase for tests. Note that this also breaks the PoW. This is fine for tests that fail due to an earlier check already.""" coinbase = auxpow_header['parent_coinbase_tx'] revised_coinbase_txid = auxpow.fast_txid(coinbase) revised_merkle_branch = [revised_coinbase_txid] revised_merkle_root = hash_merkle_root(revised_merkle_branch, revised_coinbase_txid, auxpow_header['coinbase_merkle_index']) auxpow_header['parent_header']['merkle_root'] = revised_merkle_root auxpow_header['coinbase_merkle_branch'] = revised_merkle_branch
def test_deserialize_auxpow_header_explicit_coinbase(self): header_bytes = bfh(namecoin_header_37174) # We can't pass the real height because it's below a checkpoint, and # the deserializer expects ElectrumX to strip checkpointed AuxPoW. header = blockchain.deserialize_header( header_bytes, constants.net.max_checkpoint() + 1) header_auxpow = header['auxpow'] self.assertEqual(auxpow.CHAIN_ID, header_auxpow['chain_id']) coinbase_tx = header_auxpow['parent_coinbase_tx'] expected_coinbase_txid = '8a3164be45a621f85318647d425fe9f45837b8e42ec4fdd902d7f64daf61ff4a' observed_coinbase_txid = auxpow.fast_txid(coinbase_tx) self.assertEqual(expected_coinbase_txid, observed_coinbase_txid) coinbase_merkle_branch = header_auxpow['coinbase_merkle_branch'] self.assertEqual(5, len(coinbase_merkle_branch)) self.assertEqual( 'f8f27314022a5165ae122642babb28dd44191dd36f99dad80b4f16b75197dde0', coinbase_merkle_branch[0]) self.assertEqual( 'c8a9dc420e17dee7b04bc0174c7a37ed9e5bc3f0ea0fdfe0b5d24bfc19ecedb0', coinbase_merkle_branch[1]) self.assertEqual( '0ce9c5b98e212527e4aa7b9298435dc4e8f4dfc4dc63b7c89c06300637c33620', coinbase_merkle_branch[2]) self.assertEqual( '3b6d0c4122a5b047cb879a440461839f0446f6bd451f01c6f0b14b6624e84136', coinbase_merkle_branch[3]) self.assertEqual( '458500be38a68b215112df5e52d9c08fdd52034fb2005ce15d2a42be28e436cb', coinbase_merkle_branch[4]) coinbase_merkle_index = header_auxpow['coinbase_merkle_index'] self.assertEqual(0, coinbase_merkle_index) chain_merkle_branch = header_auxpow['chain_merkle_branch'] self.assertEqual(4, len(chain_merkle_branch)) self.assertEqual( '000000000000000000000000000000000000000000000000000000000000000a', chain_merkle_branch[0]) self.assertEqual( '65bd8eb2c7e3a3646507977e8659e5396b197f197fbb51e7158927a263798302', chain_merkle_branch[1]) self.assertEqual( '5f961bb13289d705abb28376a01f7097535c95f87b9e719b9ec39d8eb20d72e9', chain_merkle_branch[2]) self.assertEqual( '7cb5fdcc41120d6135a40a6753bddc0c9b675ba2936d2e0cd78cdcb02e6beb50', chain_merkle_branch[3]) chain_merkle_index = header_auxpow['chain_merkle_index'] self.assertEqual(11, chain_merkle_index) expected_parent_hash = '00000000000024111173f561b36ad4906df95f52503a79332d7f540c2a57db84' observed_parent_hash = blockchain.hash_header( header_auxpow['parent_header']) self.assertEqual(expected_parent_hash, observed_parent_hash) expected_parent_header = blockchain.deserialize_header( bfh('0100000055a7bc918827dbe7d8027781d803f4b418589b7b9fc03e718a03000000000000625a3d6dc4dfb0ab25f450cd202ff3bdb074f2edde1ddb4af5217e10c9dbafb9639a0a4fd7690d1a25aeaa97' ), 1) expected_parent_merkle_root = expected_parent_header['merkle_root'] observed_parent_merkle_root = header_auxpow['parent_header'][ 'merkle_root'] self.assertEqual(expected_parent_merkle_root, observed_parent_merkle_root)