From 87045362b4e66b6b3e2343f4d7ea109b0179fbb6 Mon Sep 17 00:00:00 2001 From: Brandon Odiwuor Date: Wed, 20 Mar 2024 16:25:47 +0300 Subject: [PATCH] test: loading assumeutxo snapshot with current chaintip at snapshot base height --- test/functional/feature_assumeutxo.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/test/functional/feature_assumeutxo.py b/test/functional/feature_assumeutxo.py index 60dd751ff80466..86e1054eb71741 100755 --- a/test/functional/feature_assumeutxo.py +++ b/test/functional/feature_assumeutxo.py @@ -27,7 +27,6 @@ - TODO: An ancestor of snapshot block - TODO: Not an ancestor of the snapshot block but has less work -- TODO: The snapshot block - TODO: A descendant of the snapshot block - TODO: Not an ancestor or a descendant of the snapshot block and has more work @@ -55,18 +54,19 @@ class AssumeutxoTest(BitcoinTestFramework): def set_test_params(self): """Use the pregenerated, deterministic chain up to height 199.""" - self.num_nodes = 3 + self.num_nodes = 4 self.rpc_timeout = 120 self.extra_args = [ [], ["-fastprune", "-prune=1", "-blockfilterindex=1", "-coinstatsindex=1"], ["-persistmempool=0","-txindex=1", "-blockfilterindex=1", "-coinstatsindex=1"], + [], ] def setup_network(self): """Start with the nodes disconnected so that one can generate a snapshot including blocks the other hasn't yet seen.""" - self.add_nodes(3) + self.add_nodes(4) self.start_nodes(extra_args=self.extra_args) def test_invalid_snapshot_scenarios(self, valid_snapshot_path): @@ -148,6 +148,21 @@ def test_invalid_mempool_state(self, dump_output_path): self.restart_node(2, extra_args=self.extra_args[2]) + def test_loading_snapshot_at_snapshot_base_height(self, dump_output_path): + self.log.info("Test loading snapshot with current chain tip at SNAPSHOT_BASE_HEIGHT (h=299)") + + n0 = self.nodes[0] + n3 = self.nodes[3] + + self.connect_nodes(0,3) + self.wait_until(lambda: n3.getchainstates()['chainstates'][-1]['blocks'] == SNAPSHOT_BASE_HEIGHT) + self.sync_blocks(nodes=(n0, n3)) + assert_equal(n3.getblockcount(), SNAPSHOT_BASE_HEIGHT) + + # Attempt to load the snapshot at SNAPSHOT_BASE_HEIGHT (h=299) + with n3.assert_debug_log(expected_msgs=["[snapshot] activation failed - work does not exceed active chainstate"]): + assert_raises_rpc_error(-32603, "Unable to load UTXO snapshot", n3.loadtxoutset, dump_output_path) + def run_test(self): """ Bring up two (disconnected) nodes, mine some new blocks on the first, @@ -159,6 +174,7 @@ def run_test(self): n0 = self.nodes[0] n1 = self.nodes[1] n2 = self.nodes[2] + n3 = self.nodes[3] self.mini_wallet = MiniWallet(n0) @@ -182,6 +198,7 @@ def run_test(self): # make n1 aware of the new header, but don't give it the block. n1.submitheader(newblock) n2.submitheader(newblock) + n3.submitheader(newblock) # Ensure everyone is seeing the same headers. for n in self.nodes: @@ -201,6 +218,9 @@ def run_test(self): assert_equal(dump_output["nchaintx"], 334) assert_equal(n0.getblockchaininfo()["blocks"], SNAPSHOT_BASE_HEIGHT) + self.test_loading_snapshot_at_snapshot_base_height(dump_output['path']) + + # 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)