Skip to content

Commit ef174e9

Browse files
ryanofskymzumsande
andcommitted
test: assumeutxo snapshot block CheckBlockIndex crash test
Add a test for a CheckBlockIndex crash that would happen before previous "assumeutxo: Get rid of faked nTx and nChainTx values" commit. The crash was an assert failure in the (pindex->nChainTx == pindex->nTx + prev_chain_tx) check that would previously happen if the snapshot block was submitted after loading the snapshot and downloading a few blocks after the snapshot. In that case ReceivedBlockTransactions() previously would overwrite the nChainTx value of the submitted snapshot block with a fake value based on the previous block, so the (pindex->nChainTx == pindex->nTx + prev_chain_tx) check would later fail on the first block after the snapshot. This test was originally posted by Martin Zumsande <mzumsande@gmail.com> in bitcoin/bitcoin#29370 (comment) Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
1 parent 0391458 commit ef174e9

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/functional/feature_assumeutxo.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,16 @@ def check_tx_counts(final: bool) -> None:
324324

325325
self.log.info("Restarted node before snapshot validation completed, reloading...")
326326
self.restart_node(1, extra_args=self.extra_args[1])
327+
328+
# Send snapshot block to n1 out of order. This makes the test less
329+
# realistic because normally the snapshot block is one of the last
330+
# blocks downloaded, but its useful to test because it triggers more
331+
# corner cases in ReceivedBlockTransactions() and CheckBlockIndex()
332+
# setting and testing nChainTx values, and it exposed previous bugs.
333+
snapshot_hash = n0.getblockhash(SNAPSHOT_BASE_HEIGHT)
334+
snapshot_block = n0.getblock(snapshot_hash, 0)
335+
n1.submitblock(snapshot_block)
336+
327337
self.connect_nodes(0, 1)
328338

329339
self.log.info(f"Ensuring snapshot chain syncs to tip. ({FINAL_HEIGHT})")

0 commit comments

Comments
 (0)