22
22
assert_approx ,
23
23
assert_equal ,
24
24
assert_raises_rpc_error ,
25
+ sha256sum_file ,
25
26
)
26
27
from test_framework .wallet import (
27
28
getnewdestination ,
@@ -320,12 +321,16 @@ def run_test(self):
320
321
for n in self .nodes :
321
322
assert_equal (n .getblockchaininfo ()["headers" ], SNAPSHOT_BASE_HEIGHT )
322
323
323
- assert_equal (
324
- dump_output ['txoutset_hash' ],
325
- "a4bf3407ccb2cc0145c49ebba8fa91199f8a3903daf0883875941497d2493c27" )
326
- assert_equal (dump_output ["nchaintx" ], blocks [SNAPSHOT_BASE_HEIGHT ].chain_tx )
327
324
assert_equal (n0 .getblockchaininfo ()["blocks" ], SNAPSHOT_BASE_HEIGHT )
328
325
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
+
329
334
# Mine more blocks on top of the snapshot that n1 hasn't yet seen. This
330
335
# will allow us to test n1's sync-to-tip on top of a snapshot.
331
336
self .generate (n0 , nblocks = 100 , sync_fun = self .no_op )
@@ -335,6 +340,39 @@ def run_test(self):
335
340
336
341
assert_equal (n0 .getblockchaininfo ()["blocks" ], FINAL_HEIGHT )
337
342
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
+
338
376
self .test_snapshot_with_less_work (dump_output ['path' ])
339
377
self .test_invalid_mempool_state (dump_output ['path' ])
340
378
self .test_invalid_snapshot_scenarios (dump_output ['path' ])
0 commit comments