mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-21 20:28:59 +02:00
Merge bitcoin/bitcoin#28685: coinstats, assumeutxo: fix hash_serialized2 calculation
4bfaad4ecachainparams, assumeutxo: Fix signet txoutset hash (Fabian Jahr)a503cd0f0bchainparams, assumeutxo: Fix testnet txoutset hash (Fabian Jahr)f6213929c5assumeutxo: Check deserialized coins for out of range values (Fabian Jahr)66865446a7docs: Add release notes for #28685 (Fabian Jahr)cb0336817escripted-diff: Rename hash_serialized_2 to hash_serialized_3 (Fabian Jahr)351370a1d2coinstats: Fix hash_serialized2 calculation (Fabian Jahr) Pull request description: Closes #28675 The last commit demonstrates that theStack's analysis [here](https://github.com/bitcoin/bitcoin/issues/28675#issuecomment-1770389468) seems to be correct. There will be more changes needed for the rest of the test suite but the `feature_assumeutxo.py` with my additional tests pass. ACKs for top commit: achow101: ACK4bfaad4ecatheStack: Code-review ACK4bfaad4ecaryanofsky: Code review ACK4bfaad4ecaTree-SHA512: 2f6abc92b282f7c5da46391803cf0804d13978d191d541f2509b532c538abccd0a081e46cda23d80d47206a05fa2b5d41b7ab246e6a263db7a7461d6292116ef
This commit is contained in:
@@ -94,8 +94,10 @@ class AssumeutxoTest(BitcoinTestFramework):
|
||||
|
||||
self.log.info(" - snapshot file with alternated UTXO data")
|
||||
cases = [
|
||||
[b"\xff" * 32, 0, "29926acf3ac81f908cf4f22515713ca541c08bb0f0ef1b2c3443a007134d69b8"], # wrong outpoint hash
|
||||
[(1).to_bytes(4, "little"), 32, "798266c2e1f9a98fe5ce61f5951cbf47130743f3764cf3cbc254be129142cf9d"], # wrong outpoint index
|
||||
[b"\xff" * 32, 0, "05030e506678f2eca8d624ffed97090ab3beadad1b51ee6e5985ba91c5720e37"], # wrong outpoint hash
|
||||
[(1).to_bytes(4, "little"), 32, "7d29cfe2c1e242bc6f103878bb70cfffa8b4dac20dbd001ff6ce24b7de2d2399"], # wrong outpoint index
|
||||
[b"\x81", 36, "f03939a195531f96d5dff983e294a1af62af86049fa7a19a7627246f237c03f1"], # wrong coin code VARINT((coinbase ? 1 : 0) | (height << 1))
|
||||
[b"\x83", 36, "e4577da84590fb288c0f7967e89575e1b0aa46624669640f6f5dfef028d39930"], # another wrong coin code
|
||||
]
|
||||
|
||||
for content, offset, wrong_hash in cases:
|
||||
@@ -103,7 +105,7 @@ class AssumeutxoTest(BitcoinTestFramework):
|
||||
f.write(valid_snapshot_contents[:(32 + 8 + offset)])
|
||||
f.write(content)
|
||||
f.write(valid_snapshot_contents[(32 + 8 + offset + len(content)):])
|
||||
expected_error(log_msg=f"[snapshot] bad snapshot content hash: expected ef45ccdca5898b6c2145e4581d2b88c56564dd389e4bd75a1aaf6961d3edd3c0, got {wrong_hash}")
|
||||
expected_error(log_msg=f"[snapshot] bad snapshot content hash: expected 61d9c2b29a2571a5fe285fe2d8554f91f93309666fc9b8223ee96338de25ff53, got {wrong_hash}")
|
||||
|
||||
def run_test(self):
|
||||
"""
|
||||
@@ -150,7 +152,7 @@ class AssumeutxoTest(BitcoinTestFramework):
|
||||
|
||||
assert_equal(
|
||||
dump_output['txoutset_hash'],
|
||||
'ef45ccdca5898b6c2145e4581d2b88c56564dd389e4bd75a1aaf6961d3edd3c0')
|
||||
'61d9c2b29a2571a5fe285fe2d8554f91f93309666fc9b8223ee96338de25ff53')
|
||||
assert_equal(dump_output['nchaintx'], 300)
|
||||
assert_equal(n0.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)
|
||||
|
||||
|
||||
@@ -293,11 +293,11 @@ class CoinStatsIndexTest(BitcoinTestFramework):
|
||||
def _test_index_rejects_hash_serialized(self):
|
||||
self.log.info("Test that the rpc raises if the legacy hash is passed with the index")
|
||||
|
||||
msg = "hash_serialized_2 hash type cannot be queried for a specific block"
|
||||
assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_2', hash_or_height=111)
|
||||
msg = "hash_serialized_3 hash type cannot be queried for a specific block"
|
||||
assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_3', hash_or_height=111)
|
||||
|
||||
for use_index in {True, False, None}:
|
||||
assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_2', hash_or_height=111, use_index=use_index)
|
||||
assert_raises_rpc_error(-8, msg, self.nodes[1].gettxoutsetinfo, hash_type='hash_serialized_3', hash_or_height=111, use_index=use_index)
|
||||
|
||||
def _test_init_index_after_reorg(self):
|
||||
self.log.info("Test a reorg while the index is deactivated")
|
||||
|
||||
@@ -85,7 +85,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
|
||||
# Any of these RPC calls could throw due to node crash
|
||||
self.start_node(node_index)
|
||||
self.nodes[node_index].waitforblock(expected_tip)
|
||||
utxo_hash = self.nodes[node_index].gettxoutsetinfo()['hash_serialized_2']
|
||||
utxo_hash = self.nodes[node_index].gettxoutsetinfo()['hash_serialized_3']
|
||||
return utxo_hash
|
||||
except Exception:
|
||||
# An exception here should mean the node is about to crash.
|
||||
@@ -130,7 +130,7 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
|
||||
If any nodes crash while updating, we'll compare utxo hashes to
|
||||
ensure recovery was successful."""
|
||||
|
||||
node3_utxo_hash = self.nodes[3].gettxoutsetinfo()['hash_serialized_2']
|
||||
node3_utxo_hash = self.nodes[3].gettxoutsetinfo()['hash_serialized_3']
|
||||
|
||||
# Retrieve all the blocks from node3
|
||||
blocks = []
|
||||
@@ -172,12 +172,12 @@ class ChainstateWriteCrashTest(BitcoinTestFramework):
|
||||
"""Verify that the utxo hash of each node matches node3.
|
||||
|
||||
Restart any nodes that crash while querying."""
|
||||
node3_utxo_hash = self.nodes[3].gettxoutsetinfo()['hash_serialized_2']
|
||||
node3_utxo_hash = self.nodes[3].gettxoutsetinfo()['hash_serialized_3']
|
||||
self.log.info("Verifying utxo hash matches for all nodes")
|
||||
|
||||
for i in range(3):
|
||||
try:
|
||||
nodei_utxo_hash = self.nodes[i].gettxoutsetinfo()['hash_serialized_2']
|
||||
nodei_utxo_hash = self.nodes[i].gettxoutsetinfo()['hash_serialized_3']
|
||||
except OSError:
|
||||
# probably a crash on db flushing
|
||||
nodei_utxo_hash = self.restart_node(i, self.nodes[3].getbestblockhash())
|
||||
|
||||
@@ -69,7 +69,7 @@ class UTXOSetHashTest(BitcoinTestFramework):
|
||||
assert_equal(finalized[::-1].hex(), node_muhash)
|
||||
|
||||
self.log.info("Test deterministic UTXO set hash results")
|
||||
assert_equal(node.gettxoutsetinfo()['hash_serialized_2'], "f9aa4fb5ffd10489b9a6994e70ccf1de8a8bfa2d5f201d9857332e9954b0855d")
|
||||
assert_equal(node.gettxoutsetinfo()['hash_serialized_3'], "d1c7fec1c0623f6793839878cbe2a531eb968b50b27edd6e2a57077a5aed6094")
|
||||
assert_equal(node.gettxoutsetinfo("muhash")['muhash'], "d1725b2fe3ef43e55aa4907480aea98d406fc9e0bf8f60169e2305f1fbf5961b")
|
||||
|
||||
def run_test(self):
|
||||
|
||||
@@ -340,7 +340,7 @@ class BlockchainTest(BitcoinTestFramework):
|
||||
assert size > 6400
|
||||
assert size < 64000
|
||||
assert_equal(len(res['bestblock']), 64)
|
||||
assert_equal(len(res['hash_serialized_2']), 64)
|
||||
assert_equal(len(res['hash_serialized_3']), 64)
|
||||
|
||||
self.log.info("Test gettxoutsetinfo works for blockchain with just the genesis block")
|
||||
b1hash = node.getblockhash(1)
|
||||
@@ -353,7 +353,7 @@ class BlockchainTest(BitcoinTestFramework):
|
||||
assert_equal(res2['txouts'], 0)
|
||||
assert_equal(res2['bogosize'], 0),
|
||||
assert_equal(res2['bestblock'], node.getblockhash(0))
|
||||
assert_equal(len(res2['hash_serialized_2']), 64)
|
||||
assert_equal(len(res2['hash_serialized_3']), 64)
|
||||
|
||||
self.log.info("Test gettxoutsetinfo returns the same result after invalidate/reconsider block")
|
||||
node.reconsiderblock(b1hash)
|
||||
@@ -365,20 +365,20 @@ class BlockchainTest(BitcoinTestFramework):
|
||||
assert_equal(res, res3)
|
||||
|
||||
self.log.info("Test gettxoutsetinfo hash_type option")
|
||||
# Adding hash_type 'hash_serialized_2', which is the default, should
|
||||
# Adding hash_type 'hash_serialized_3', which is the default, should
|
||||
# not change the result.
|
||||
res4 = node.gettxoutsetinfo(hash_type='hash_serialized_2')
|
||||
res4 = node.gettxoutsetinfo(hash_type='hash_serialized_3')
|
||||
del res4['disk_size']
|
||||
assert_equal(res, res4)
|
||||
|
||||
# hash_type none should not return a UTXO set hash.
|
||||
res5 = node.gettxoutsetinfo(hash_type='none')
|
||||
assert 'hash_serialized_2' not in res5
|
||||
assert 'hash_serialized_3' not in res5
|
||||
|
||||
# hash_type muhash should return a different UTXO set hash.
|
||||
res6 = node.gettxoutsetinfo(hash_type='muhash')
|
||||
assert 'muhash' in res6
|
||||
assert res['hash_serialized_2'] != res6['muhash']
|
||||
assert res['hash_serialized_3'] != res6['muhash']
|
||||
|
||||
# muhash should not be returned unless requested.
|
||||
for r in [res, res2, res3, res4, res5]:
|
||||
|
||||
@@ -46,7 +46,7 @@ class DumptxoutsetTest(BitcoinTestFramework):
|
||||
'b1bacb602eacf5fbc9a7c2ef6eeb0d229c04e98bdf0c2ea5929012cd0eae3830')
|
||||
|
||||
assert_equal(
|
||||
out['txoutset_hash'], '1f7e3befd45dc13ae198dfbb22869a9c5c4196f8e9ef9735831af1288033f890')
|
||||
out['txoutset_hash'], 'a0b7baa3bf5ccbd3279728f230d7ca0c44a76e9923fca8f32dbfd08d65ea496a')
|
||||
assert_equal(out['nchaintx'], 101)
|
||||
|
||||
# Specifying a path to an existing or invalid file will fail.
|
||||
|
||||
Reference in New Issue
Block a user