Skip to content

Commit

Permalink
Fix feature_assumeutxo.py (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil committed Oct 24, 2024
1 parent ba956b6 commit 7910ee4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/kernel/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -634,10 +634,10 @@ class CRegTestParams : public CChainParams
m_assumeutxo_data = {
{
// For use by test/functional/feature_assumeutxo.py
.height = 2199,
.hash_serialized = AssumeutxoHash{uint256S("0xa9e20f6c0c6531e44789f7a29df1939fa1c2e7d5c451b25c5201880628c57940")},
.nChainTx = 2200,
.blockhash = uint256S("0x66832161e18db8b9325ec765201657c4238992f27c36ba37111f1e2d55cc16cb")
.height = 4099,
.hash_serialized = AssumeutxoHash{uint256S("0x73200c9ce4eb500fb90dc57599ed084a1351eb0bf5de133c8a8ed4662e7e8162")},
.nChainTx = 2100,
.blockhash = uint256S("0x05487442d7c76a7c64070cca8a52742fa7be67566802c55cc4499b15ff8acc0b")
},
};

Expand Down
28 changes: 14 additions & 14 deletions test/functional/feature_assumeutxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
)

START_HEIGHT = 2099
SNAPSHOT_BASE_HEIGHT = 2199
FINAL_HEIGHT = 2299
SNAPSHOT_BASE_HEIGHT = 4099
FINAL_HEIGHT = 6099
COMPLETE_IDX = {'synced': True, 'best_block_height': FINAL_HEIGHT}


Expand Down Expand Up @@ -96,22 +96,22 @@ def expected_error(log_msg="", rpc_details=""):
f.write(valid_snapshot_contents[:32])
f.write((valid_num_coins + off).to_bytes(8, "little"))
f.write(valid_snapshot_contents[32 + 8:])
expected_error(log_msg=f"bad snapshot - coins left over after deserializing 2198 coins" if off == -1 else f"bad snapshot format or truncated snapshot after deserializing 2199 coins")
expected_error(log_msg=f"bad snapshot - coins left over after deserializing 4098 coins" if off == -1 else f"bad snapshot format or truncated snapshot after deserializing 4099 coins")

self.log.info(" - snapshot file with alternated UTXO data")
cases = [
[b"\xff" * 32, 0, "7d52155c9a9fdc4525b637ef6170568e5dad6fabd0b1fdbb9432010b8453095b"], # wrong outpoint hash
[(1).to_bytes(4, "little"), 32, "9f4d897031ab8547665b4153317ae2fdbf0130c7840b66427ebc48b881cb80ad"], # wrong outpoint index
[b"\x81", 36, "3da966ba9826fb6d2604260e01607b55ba44e1a5de298606b08704bc62570ea8"], # wrong coin code VARINT((coinbase ? 1 : 0) | (height << 1))
[b"\x80", 36, "091e893b3ccb4334378709578025356c8bcb0a623f37c7c4e493133c988648e5"], # another wrong coin code
[b"\xff" * 32, 0, "b5a0110eb8ffa80d08b0a201313a0e09006d0677210b0941e247710506a13cb5"], # wrong outpoint hash
[(1).to_bytes(4, "little"), 32, "4a2d96ddec10d00f9de83dd5b2b26419d464b4639edd4d3dfd33fdb7948e241e"], # wrong outpoint index
[b"\x81", 36, "c67efb6331ae90c591d449c75fa8bdbef2e9c4d283d6f82586d017fbbcae6b71"], # wrong coin code VARINT((coinbase ? 1 : 0) | (height << 1))
[b"\x80", 36, "42d4c50bb80a6c266605b524314879e6f27e0e01fd5bb8340dc9a188ab056b9f"], # another wrong coin code
]

for content, offset, wrong_hash in cases:
with open(bad_snapshot_path, "wb") as f:
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 a9e20f6c0c6531e44789f7a29df1939fa1c2e7d5c451b25c5201880628c57940, got {wrong_hash}")
expected_error(log_msg=f"[snapshot] bad snapshot content hash: expected 73200c9ce4eb500fb90dc57599ed084a1351eb0bf5de133c8a8ed4662e7e8162, got {wrong_hash}")

def test_invalid_chainstate_scenarios(self):
self.log.info("Test different scenarios of invalid snapshot chainstate in datadir")
Expand Down Expand Up @@ -173,7 +173,7 @@ def run_test(self):
# though, we have to ferry over the new headers to n1 so that it
# isn't waiting forever to see the header of the snapshot's base block
# while disconnected from n0.
for i in range(100):
for i in range(2000):
if i % 3 == 0:
self.mini_wallet.send_self_transfer(from_node=n0)
self.generate(n0, nblocks=1, sync_fun=self.no_op)
Expand All @@ -197,13 +197,13 @@ def run_test(self):

assert_equal(
dump_output['txoutset_hash'],
"a9e20f6c0c6531e44789f7a29df1939fa1c2e7d5c451b25c5201880628c57940")
assert_equal(dump_output["nchaintx"], 2200)
"73200c9ce4eb500fb90dc57599ed084a1351eb0bf5de133c8a8ed4662e7e8162")
assert_equal(dump_output["nchaintx"], 4767)
assert_equal(n0.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT)

# Mine more blocks on top of the snapshot that n1 hasn't yet seen. This
# will allow us to test n1's sync-to-tip on top of a snapshot.
self.generate(n0, nblocks=100, sync_fun=self.no_op)
self.generate(n0, nblocks=2000, sync_fun=self.no_op)

assert_equal(n0.getblockcount(), FINAL_HEIGHT)
assert_equal(n1.getblockcount(), START_HEIGHT)
Expand Down Expand Up @@ -236,7 +236,7 @@ def run_test(self):
prev_tx = n0.getblock(spend_coin_blockhash, 3)['tx'][0]
prevout = {"txid": prev_tx['txid'], "vout": 0, "scriptPubKey": prev_tx['vout'][0]['scriptPubKey']['hex']}
privkey = n0.get_deterministic_priv_key().key
raw_tx = n1.createrawtransaction([prevout], {getnewdestination()[2]: 24.99})
raw_tx = n1.createrawtransaction([prevout], {getnewdestination()[2]: 19999.99})
signed_tx = n1.signrawtransactionwithkey(raw_tx, [privkey], [prevout])['hex']
signed_txid = tx_from_hex(signed_tx).rehash()

Expand All @@ -262,7 +262,7 @@ def run_test(self):
self.log.info("Checking that blocks are segmented on disk")
assert self.has_blockfile(n1, "00000"), "normal blockfile missing"
assert self.has_blockfile(n1, "00001"), "assumed blockfile missing"
assert not self.has_blockfile(n1, "00002"), "too many blockfiles"
assert not self.has_blockfile(n1, "00012"), "too many blockfiles"

self.log.info("Restarted node before snapshot validation completed, reloading...")
self.restart_node(1, extra_args=self.extra_args[1])
Expand Down

0 comments on commit 7910ee4

Please sign in to comment.