2222 assert_approx ,
2323 assert_equal ,
2424 assert_raises_rpc_error ,
25+ sha256sum_file ,
2526)
2627from test_framework .wallet import (
2728 getnewdestination ,
@@ -320,12 +321,16 @@ def run_test(self):
320321 for n in self .nodes :
321322 assert_equal (n .getblockchaininfo ()["headers" ], SNAPSHOT_BASE_HEIGHT )
322323
323- assert_equal (
324- dump_output ['txoutset_hash' ],
325- "a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27" )
326- assert_equal (dump_output ["nchaintx" ], blocks [SNAPSHOT_BASE_HEIGHT ].chain_tx )
327324 assert_equal (n0 .getblockchaininfo ()["blocks" ], SNAPSHOT_BASE_HEIGHT )
328325
326+ def check_dump_output (output ):
327+ assert_equal (
328+ output ['txoutset_hash' ],
329+ "a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27" )
330+ assert_equal (output ["nchaintx" ], blocks [SNAPSHOT_BASE_HEIGHT ].chain_tx )
331+
332+ check_dump_output (dump_output )
333+
329334 # Mine more blocks on top of the snapshot that n1 hasn't yet seen. This
330335 # will allow us to test n1's sync-to-tip on top of a snapshot.
331336 self .generate (n0 , nblocks = 100 , sync_fun = self .no_op )
@@ -335,6 +340,39 @@ def run_test(self):
335340
336341 assert_equal (n0 .getblockchaininfo ()["blocks" ], FINAL_HEIGHT )
337342
343+ self .log .info (f"Check that dumptxoutset works for past block heights" )
344+ # rollback defaults to the snapshot base height
345+ dump_output2 = n0 .dumptxoutset ('utxos2.dat' , "rollback" )
346+ check_dump_output (dump_output2 )
347+ assert_equal (sha256sum_file (dump_output ['path' ]), sha256sum_file (dump_output2 ['path' ]))
348+
349+ # Rollback with specific height
350+ dump_output3 = n0 .dumptxoutset ('utxos3.dat' , rollback = SNAPSHOT_BASE_HEIGHT )
351+ check_dump_output (dump_output3 )
352+ assert_equal (sha256sum_file (dump_output ['path' ]), sha256sum_file (dump_output3 ['path' ]))
353+
354+ # Specified height that is not a snapshot height
355+ prev_snap_height = SNAPSHOT_BASE_HEIGHT - 1
356+ dump_output4 = n0 .dumptxoutset (path = 'utxos4.dat' , rollback = prev_snap_height )
357+ assert_equal (
358+ dump_output4 ['txoutset_hash' ],
359+ "8a1db0d6e958ce0d7c963bc6fc91ead596c027129bacec68acc40351037b09d7" )
360+ assert sha256sum_file (dump_output ['path' ]) != sha256sum_file (dump_output4 ['path' ])
361+
362+ # Use a hash instead of a height
363+ prev_snap_hash = n0 .getblockhash (prev_snap_height )
364+ dump_output5 = n0 .dumptxoutset ('utxos5.dat' , rollback = prev_snap_hash )
365+ assert_equal (sha256sum_file (dump_output4 ['path' ]), sha256sum_file (dump_output5 ['path' ]))
366+
367+ # TODO: This is a hack to set m_best_header to the correct value after
368+ # dumptxoutset/reconsiderblock. Otherwise the wrong error messages are
369+ # returned in following tests. It can be removed once this bug is
370+ # fixed. See also https://github.com/bitcoin/bitcoin/issues/26245
371+ self .restart_node (0 , ["-reindex" ])
372+
373+ # Ensure n0 is back at the tip
374+ assert_equal (n0 .getblockchaininfo ()["blocks" ], FINAL_HEIGHT )
375+
338376 self .test_snapshot_with_less_work (dump_output ['path' ])
339377 self .test_invalid_mempool_state (dump_output ['path' ])
340378 self .test_invalid_snapshot_scenarios (dump_output ['path' ])
0 commit comments