Skip to content

Commit

Permalink
test: loadtxoutset in divergent chain with less work
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsoromanz committed May 13, 2024
1 parent b940619 commit a7501f7
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions test/functional/feature_assumeutxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
Interesting starting states could be loading a snapshot when the current chain tip is:
- 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 @@ -161,6 +160,22 @@ def test_invalid_file_path(self):
path = node.datadir_path / node.chain / "invalid" / "path"
assert_raises_rpc_error(-8, "Couldn't open file {} for reading.".format(path), node.loadtxoutset, path)

def test_snapshot_in_a_divergent_chain(self, dump_output_path):
# First rollback node2's chain to the pregenerated one, up to height 199
node = self.nodes[2]
block_hash = node.getblockhash(START_HEIGHT + 1)
node.invalidateblock(block_hash)
assert_equal(node.getblockcount(), START_HEIGHT)

self.log.info(f"Check importing a snapshot where current chain-tip is not an ancestor of the snapshot block but has less work")
# Generate a divergent chain in node2 but with less work compared to the snapshot
self.generate(node, nblocks=SNAPSHOT_BASE_HEIGHT-START_HEIGHT-1, sync_fun=self.no_op)
assert node.getblockcount() < SNAPSHOT_BASE_HEIGHT
# Try importing the snapshot and assert its success
loaded = node.loadtxoutset(dump_output_path)
assert_equal(loaded['coins_loaded'], SNAPSHOT_BASE_HEIGHT)
assert_equal(loaded['base_height'], SNAPSHOT_BASE_HEIGHT)

def run_test(self):
"""
Bring up two (disconnected) nodes, mine some new blocks on the first,
Expand Down Expand Up @@ -375,10 +390,10 @@ def check_tx_counts(final: bool) -> None:
self.wait_until(lambda: n.getindexinfo() == completed_idx_state)


# Node 2: all indexes + reindex
# -----------------------------
# Node 2: all indexes + reindex + divergent chain
# -----------------------------------------------

self.log.info("-- Testing all indexes + reindex")
self.log.info("-- Testing all indexes + reindex + divergent chain")
assert_equal(n2.getblockcount(), START_HEIGHT)

self.log.info(f"Loading snapshot into third node from {dump_output['path']}")
Expand Down Expand Up @@ -448,6 +463,8 @@ def check_tx_counts(final: bool) -> None:
self.connect_nodes(0, 2)
self.wait_until(lambda: n2.getblockcount() == FINAL_HEIGHT)

self.test_snapshot_in_a_divergent_chain(dump_output['path'])

@dataclass
class Block:
hash: str
Expand Down

0 comments on commit a7501f7

Please sign in to comment.