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 +81 −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
    ACK Bortlesboat
    Concept ACK yuvicc, aditrajj

    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-->

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • Restore wallet created at snapshot height it should be empty before sync -> Restore wallet created at snapshot height; it should be empty before sync [run-on sentence missing punctuation; needs a separator or conjunction to be grammatical]
    • Payment is post snapshot and intended to be orphaned by the reorg ensure seen first -> Payment is post-snapshot and intended to be orphaned by the reorg; ensure it is seen first [missing hyphen in "post-snapshot" and a separator plus subject "it" to make the instruction grammatical]

    <sup>2026-02-16 20:16:22</sup>

  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. test: Add wallet reorg test during assumeutxo background sync
    Signed-off-by: b-l-u-e <winnie.gitau282@gmail.com>
    75368100aa
  9. b-l-u-e force-pushed on Feb 16, 2026
  10. DrahtBot added the label CI failed on Feb 16, 2026
  11. DrahtBot removed the label CI failed on Feb 16, 2026
  12. in test/functional/wallet_assumeutxo.py:145 in 75368100aa
     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.

  13. 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.

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

    Concept ACK

  16. 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


yuvicc

Labels

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-04-21 12:12 UTC

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