Skip to content

Commit

Permalink
test: loading assumeutxo snapshot with current chaintip
Browse files Browse the repository at this point in the history
at snapshot base height
  • Loading branch information
BrandonOdiwuor committed Mar 20, 2024
1 parent a945f09 commit 8704536
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/functional/feature_assumeutxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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)

Expand All @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit 8704536

Please sign in to comment.