Skip to content

Commit a85e5a7

Browse files
committed
Merge bitcoin#29478: test: Test new header sync behavior in loadtxoutset
1ec6684 test: Add test for loadtxoutset when headers are not synced (Fabian Jahr) 2bc1ecf test: Remove unnecessary sync_blocks in assumeutxo tests (Fabian Jahr) Pull request description: It adds a test for the change to `loadtxoutset` made in bitcoin#29345. Before that change the test doesn't fail right away but times out after 10 minutes. Also removes a `sync_blocks` call that didn't seem to do anything valuable. ACKs for top commit: achow101: ACK 1ec6684 pablomartin4btc: tACK 1ec6684 BrandonOdiwuor: ACK 1ec6684 theStack: ACK 1ec6684 Tree-SHA512: 1337decdf91e4a4f7213fcf8ace1d705e5c1422e0ac3872a59b5be9c33e743850cb8f5f7474750a534952eefd5cfe43fe85a54efb9bc0e47515136a2903676e5
2 parents ef6329f + 1ec6684 commit a85e5a7

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

test/functional/feature_assumeutxo.py

+24-15
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

@@ -166,26 +172,12 @@ def run_test(self):
166172
for n in self.nodes:
167173
n.setmocktime(n.getblockheader(n.getbestblockhash())['time'])
168174

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

190182
self.log.info("-- Testing assumeutxo + some indexes + pruning")
191183

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

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+
198207
assert_equal(
199208
dump_output['txoutset_hash'],
200209
"a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27")

test/functional/wallet_assumeutxo.py

-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ def run_test(self):
6262
for n in self.nodes:
6363
n.setmocktime(n.getblockheader(n.getbestblockhash())['time'])
6464

65-
self.sync_blocks()
66-
6765
n0.createwallet('w')
6866
w = n0.get_wallet_rpc("w")
6967

0 commit comments

Comments
 (0)