Skip to content

Commit 1ec6684

Browse files
committed
test: Add test for loadtxoutset when headers are not synced
1 parent 2bc1ecf commit 1ec6684

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def expected_error(log_msg="", rpc_details=""):
113113
f.write(valid_snapshot_contents[(32 + 8 + offset + len(content)):])
114114
expected_error(log_msg=f"[snapshot] bad snapshot content hash: expected a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27, got {wrong_hash}")
115115

116+
def test_headers_not_synced(self, valid_snapshot_path):
117+
for node in self.nodes[1:]:
118+
assert_raises_rpc_error(-32603, "The base block header (3bb7ce5eba0be48939b7a521ac1ba9316afee2c7bada3a0cca24188e6d7d96c0) must appear in the headers chain. Make sure all headers are syncing, and call this RPC again.",
119+
node.loadtxoutset,
120+
valid_snapshot_path)
121+
116122
def test_invalid_chainstate_scenarios(self):
117123
self.log.info("Test different scenarios of invalid snapshot chainstate in datadir")
118124

@@ -167,23 +173,11 @@ def run_test(self):
167173
n.setmocktime(n.getblockheader(n.getbestblockhash())['time'])
168174

169175
# Generate a series of blocks that `n0` will have in the snapshot,
170-
# but that n1 doesn't yet see. In order for the snapshot to activate,
171-
# though, we have to ferry over the new headers to n1 so that it
172-
# isn't waiting forever to see the header of the snapshot's base block
173-
# while disconnected from n0.
176+
# but that n1 and n2 don't yet see.
174177
for i in range(100):
175178
if i % 3 == 0:
176179
self.mini_wallet.send_self_transfer(from_node=n0)
177180
self.generate(n0, nblocks=1, sync_fun=self.no_op)
178-
newblock = n0.getblock(n0.getbestblockhash(), 0)
179-
180-
# make n1 aware of the new header, but don't give it the block.
181-
n1.submitheader(newblock)
182-
n2.submitheader(newblock)
183-
184-
# Ensure everyone is seeing the same headers.
185-
for n in self.nodes:
186-
assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)
187181

188182
self.log.info("-- Testing assumeutxo + some indexes + pruning")
189183

@@ -193,6 +187,23 @@ def run_test(self):
193187
self.log.info(f"Creating a UTXO snapshot at height {SNAPSHOT_BASE_HEIGHT}")
194188
dump_output = n0.dumptxoutset('utxos.dat')
195189

190+
self.log.info("Test loading snapshot when headers are not synced")
191+
self.test_headers_not_synced(dump_output['path'])
192+
193+
# In order for the snapshot to activate, we have to ferry over the new
194+
# headers to n1 and n2 so that they see the header of the snapshot's
195+
# base block while disconnected from n0.
196+
for i in range(1, 300):
197+
block = n0.getblock(n0.getblockhash(i), 0)
198+
# make n1 and n2 aware of the new header, but don't give them the
199+
# block.
200+
n1.submitheader(block)
201+
n2.submitheader(block)
202+
203+
# Ensure everyone is seeing the same headers.
204+
for n in self.nodes:
205+
assert_equal(n.getblockchaininfo()["headers"], SNAPSHOT_BASE_HEIGHT)
206+
196207
assert_equal(
197208
dump_output['txoutset_hash'],
198209
"a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27")

0 commit comments

Comments
 (0)