test: Add wallet reorg test during assumeutxo background sync #34535

pull b-l-u-e wants to merge 1 commits into bitcoin:master from b-l-u-e:test-wallet-reorg-assumeutxo changing 1 files +78 −2
  1. b-l-u-e commented at 9:23 PM on February 8, 2026: contributor

    This PR adds a test that verifies wallet balance consistency when a chain reorg occurs while assumeutxo background validation is in progress

    motivation currently test file tests wallet functionality with snapshots but there is no test covering what happens when reorg occurs during background validation phase.

    so what it tests

    • wallet state remains consistent through reorg
    • balance updates when coins are orphaned
  2. DrahtBot added the label Tests on Feb 8, 2026
  3. DrahtBot commented at 9:24 PM on February 8, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK yuvicc, aditrajj
    Stale ACK Bortlesboat

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. b-l-u-e marked this as ready for review on Feb 9, 2026
  5. in test/functional/wallet_assumeutxo.py:156 in 3a8f776299
     151 | +        # Build an alternative chain on n0 that excludes the post snapshot wallet payment
     152 | +        fork_point = SNAPSHOT_BASE_HEIGHT
     153 | +        orig_height = n0.getblockcount()
     154 | +        orig_chainwork = int(n0.getblockchaininfo()['chainwork'], 16)
     155 | +        self.disconnect_nodes(n3.index, n0.index)
     156 | +        n0.invalidateblock(n0.getblockhash(fork_point + 1))
    


    yuvicc commented at 5:04 AM on February 16, 2026:

    Instead of using invalidateblock directly, we could leverage fork-based reorg testing here so that it matches the real re-org scenario. For more see mempool_updatefromblock.py test.


    b-l-u-e commented at 7:55 PM on February 16, 2026:

    i made changes to use fork-based reorg , thanks for the tip

  6. yuvicc commented at 5:05 AM on February 16, 2026: contributor

    Concept ACK

  7. b-l-u-e force-pushed on Feb 16, 2026
  8. b-l-u-e force-pushed on Feb 16, 2026
  9. DrahtBot added the label CI failed on Feb 16, 2026
  10. DrahtBot removed the label CI failed on Feb 16, 2026
  11. in test/functional/wallet_assumeutxo.py:145 in 75368100aa outdated
     140 | +        payment_addr = w_reorg.getnewaddress()
     141 | +        pay_amount = 5
     142 | +        funding_wallet = n0.get_wallet_rpc("w")
     143 | +        txid = funding_wallet.sendtoaddress(payment_addr, pay_amount)
     144 | +        self.generate(n0, nblocks=2, sync_fun=self.no_op)
     145 | +        # Ensure the assumeutxo node receives the blocks with the payment
    


    Bortlesboat commented at 10:12 PM on March 15, 2026:

    nit: 180s timeout seems overly generous here. At this point the blocks have already been synced via sync_blocks and the payment has confirmations, so gettransaction should return quickly. Would 30-60s be sufficient? Long timeouts can mask real issues by making flaky tests take a long time to fail rather than failing fast.


    b-l-u-e commented at 8:28 PM on April 27, 2026:

    thanks i will update to 60s

  12. Bortlesboat commented at 10:13 PM on March 15, 2026: none

    ACK 75368100aa36ce136039b734c317354a04ef783b. Ran wallet_assumeutxo.py locally on Ubuntu 24.04, all tests pass including the new reorg-during-background-sync test.

  13. DrahtBot requested review from yuvicc on Mar 15, 2026
  14. aditrajj commented at 7:25 AM on March 20, 2026: none

    Concept ACK

  15. in test/functional/wallet_assumeutxo.py:120 in 75368100aa
     115 | +
     116 | +        # Restart pruned node fresh to ensure snapshot has more work than active chainstate
     117 | +        self.stop_node(n3.index)
     118 | +        rmtree(n3.chain_path)
     119 | +        self.start_node(n3.index, extra_args=self.extra_args[n3.index])
     120 | +        n3.setmocktime(n0.getblockheader(n0.getbestblockhash())['time'])
    


    maflcko commented at 7:54 AM on March 20, 2026:

    I think according to #34439, rmtree should be avoided, if possible.

    I think this is also trivial to avoid with a hacky hack:

    • Start the node with -reindex -mocktime=123 (This will reject blocks and headers, and delete them?)
    • The n3.setmocktime call here will then recover the mocktime, and the test should continue normall

    However, I haven't tried if this hack actually works and if the test passes


    b-l-u-e commented at 9:55 PM on April 27, 2026:

    Tried the approach and it works thanks for the hack. I updated the test and passes locally

    <details> <summary>test output</summary>

    2026-04-27T21:47:05.297236Z TestFramework (INFO): PRNG seed is: 8502276312754656986
    2026-04-27T21:47:05.347981Z TestFramework (INFO): Initializing test directory /tmp/bitcoin_func_test_jjdqbo8r
    2026-04-27T21:47:06.603434Z TestFramework (INFO): -- Testing assumeutxo
    2026-04-27T21:47:06.605792Z TestFramework (INFO): Creating a UTXO snapshot at height 299
    2026-04-27T21:47:07.147304Z TestFramework (INFO): Loading snapshot into second node from /tmp/bitcoin_func_test_jjdqbo8r/node0/regtest/utxos.dat
    2026-04-27T21:47:07.185135Z TestFramework (INFO): Backup from the snapshot height can be loaded during background sync
    2026-04-27T21:47:07.190968Z TestFramework (INFO): Backup from before the snapshot height can't be loaded during background sync
    2026-04-27T21:47:07.194877Z TestFramework (INFO): Backup from the snapshot height can be loaded during background sync (pruned node)
    2026-04-27T21:47:07.230742Z TestFramework (INFO): Backup from before the snapshot height can't be loaded during background sync (pruned node)
    2026-04-27T21:47:07.240374Z TestFramework (INFO): Test loading descriptors during background sync
    2026-04-27T21:47:07.257714Z TestFramework (INFO): Test that rescanning blocks from before the snapshot fails when blocks are not available from the background sync yet
    2026-04-27T21:47:07.258696Z TestFramework (INFO): Unload wallets and sync node up to height 359
    2026-04-27T21:47:07.487422Z TestFramework (INFO): Verify node state during background sync
    2026-04-27T21:47:07.626065Z TestFramework (INFO): Ensuring wallet can be restored from a backup that was created before the snapshot height
    2026-04-27T21:47:07.651290Z TestFramework (INFO): Check balance of a wallet that is active during snapshot completion
    2026-04-27T21:47:08.939432Z TestFramework (INFO): Ensuring descriptors can be loaded after background sync
    2026-04-27T21:47:08.954958Z TestFramework (INFO): Ensuring wallet can't be restored from a backup that was created before the pruneheight (pruned node)
    2026-04-27T21:47:09.210299Z TestFramework (INFO): Ensuring wallet can be restored from a backup that was created at the pruneheight (pruned node)
    2026-04-27T21:47:09.223229Z TestFramework (INFO): Ensure wallet balances stay consistent across a reorg during assumeutxo background sync
    2026-04-27T21:47:11.899506Z TestFramework (INFO): Stopping nodes
    2026-04-27T21:47:12.057854Z TestFramework (INFO): Cleaning up /tmp/bitcoin_func_test_jjdqbo8r on exit
    2026-04-27T21:47:12.057971Z TestFramework (INFO): Tests successful
    
  16. sedited commented at 2:35 PM on April 27, 2026: contributor

    @b-l-u-e There are a bunch of unresolved review comments here. Can you respond to them?

  17. b-l-u-e commented at 7:31 PM on April 27, 2026: contributor

    @b-l-u-e There are a bunch of unresolved review comments here. Can you respond to them?

    thanks for the reminder

  18. b-l-u-e force-pushed on Apr 27, 2026
  19. b-l-u-e requested review from Bortlesboat on Apr 27, 2026
  20. b-l-u-e requested review from maflcko on Apr 27, 2026
  21. Bortlesboat commented at 6:24 AM on April 28, 2026: none

    ACK ad99afd3da255703547e00f1fe8e4bd60a403c75. Re-reviewed the changes since my previous ACK 75368100aa36ce136039b734c317354a04ef783b, including the switch from removing the pruned node chain directory to the -reindex/-mocktime path and the shorter transaction confirmation timeout. Built current tip on WSL2 Ubuntu 24.04 with wallet support enabled and ran test/functional/wallet_assumeutxo.py; the test passed.

  22. test: Add wallet reorg test during assumeutxo background sync
    Signed-off-by: b-l-u-e <8102260+blue@users.noreply.github.com>
    e42bff60df
  23. in test/functional/wallet_assumeutxo.py:163 in ad99afd3da
     158 | +        tip_time = n0.getblockheader(n0.getbestblockhash())['time']
     159 | +        fork_blocks = []
     160 | +        for i in range((orig_height - fork_point) + 2):
     161 | +            block = create_block(
     162 | +                hashprev=fork_block_hash,
     163 | +                coinbase=create_coinbase(height=fork_point + 1 + i),
    


    maflcko commented at 6:51 AM on April 28, 2026:
                    height=fork_point + 1 + i,
    

    nit, I think this should work as well on current master, but I haven't tried

  24. b-l-u-e force-pushed on Apr 28, 2026
  25. sedited requested review from maflcko on May 2, 2026

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-11 18:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me