rpc: reject AssumeUTXO rollback without tip data #36503

pull l0rinc wants to merge 3 commits into bitcoin:master from l0rinc:l0rinc/rpc-dumptxoutset-missing-undo changing 2 files +30 −8
  1. l0rinc commented at 10:50 PM on October 11, 2026: contributor

    Problem: Loading a UTXO snapshot on a pruned node can leave the active tip without block or undo data. Attempting a rollback with dumptxoutset then triggers an assertion and terminates the node.

    Fix: Reuse GetPruneHeight to reject rollback with the existing pruning error when the required data is unavailable.

  2. DrahtBot added the label RPC/REST/ZMQ on Oct 11, 2026
  3. DrahtBot commented at 10:51 PM on October 11, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process.

    Type Reviewers
    Concept ACK musaHaruna, danielabrozzoni
    Stale ACK cyb3ralbert

    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.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #36778 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36778.svg"></sub> (AssumeUTXO: replace loadtxoutset RPC with a startup arg by l0rinc)
    • #36702 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36702.svg"></sub> (validation: don't treat snapshot block as linked on startup by shuv-amp)
    • #36266 <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36266.svg"></sub> (rpc: Let dumptxoutset fail early on stale targets and concurrent runs by fjahr)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. musaHaruna commented at 3:07 PM on October 12, 2026: contributor

    Concept ACK. The fix looks straightforward and contained: GetPruneHeight handles missing data at the tip before calling GetFirstBlock, allowing the RPC to return an error instead of hitting the assertion.

    I have a few questions about the surrounding behavior.

    • Should the early availability check also cover non-pruned nodes? They can load a snapshot without having the historical block or undo data. I understand that the code limits the early check to pruning mode, and non-pruned nodes can fail later during rollback. Could checking availability earlier avoid copying the UTXO set before discovering that rollback is impossible? Registering TemporaryPruneLock could still remain conditional on IsPruneMode().

    • Would a more general error message describe these cases better? Specifically, changing: Could not roll back to requested height since necessary block data is already pruned. to: Could not roll back to requested height because required block or undo data is unavailable. After loading a UTXO snapshot, the node may lack historical block or undo data because it has not obtained or generated it yet, not because pruning deleted it. Keeping the existing wording for this focused fix seems reasonable, though.

    • Could the boundary eventually compare the highest missing-data height against the target using > instead of >=? The loop in CreateRolledBackUTXOSnapshot uses: while (block_index->nHeight > target->nHeight) For example, exporting state 299 from tip 301 disconnects blocks 301 and 300, so it does not need undo for block 299. If GetPruneHeight returns 299, the current 299 >= 299 check rejects that request, whereas 299 > 299 would allow it. Am I missing another requirement for the target’s data? In a locally modified version using > and applying the early availability check to both pruned and non-pruned nodes, the added boundary tests passed. Exporting state 299 succeeded and matched the original snapshot’s UTXO hash, while exporting state 298 still failed.

  5. l0rinc renamed this:
    rpc: reject snapshot rollback without tip data
    rpc: reject AssumeUTXO rollback without tip data
    on Oct 15, 2026
  6. cyb3ralbert commented at 7:37 AM on November 12, 2026: contributor

    Tested ACK 3cb70c28f5e97bd42f45b4a917e21fbd1452f4a3

    Tested on Linux aarch64, GCC 14.2.0, Release build:

    • feature_assumeutxo.py and rpc_dumptxoutset.py passed.
    • 874 unit tests passed (one with warnings).

    Cases checked:

    • Missing snapshot tip and missing undo data: both abort in GetFirstBlock() on the base commit and return the expected RPC errors with the fix.
    • Pruned-node export at height 398 (tip 399) matches the full node's UTXO hash.
    • Historical-gap and target-equality checks pass on the base.

    To reproduce the functional tests:

    python3 build/test/functional/test_runner.py feature_assumeutxo.py rpc_dumptxoutset.py
    
  7. DrahtBot requested review from musaHaruna on Nov 12, 2026
  8. l0rinc referenced this in commit 4107215392 on Nov 18, 2026
  9. l0rinc force-pushed on Nov 18, 2026
  10. DrahtBot added the label CI failed on Nov 18, 2026
  11. test: characterize snapshot rollback without tip data
    Record the assertion when the snapshot tip lacks block data or undo, then restart the node to continue the existing checks.
    a2996510e8
  12. rpc: reject snapshot rollback without tip data
    Reuse GetPruneHeight to return the existing pruning error when the snapshot tip lacks block or undo data.
    8c81459873
  13. rpc: check block and undo data above rollback target
    Rollback disconnects only blocks above the requested height. Check those blocks for missing body or undo data before copying the UTXO set on pruned nodes and snapshot chainstates.
    Report unavailable data because snapshot history may not yet have been downloaded.
    
    Suggested in https://github.com/bitcoin/bitcoin/pull/36503#pullrequestreview-5492606225
    4b3849d53b
  14. l0rinc force-pushed on Nov 18, 2026
  15. DrahtBot removed the label CI failed on Nov 18, 2026
  16. in src/rpc/blockchain.cpp:3176 in 4b3849d53b
    3172 | @@ -3173,15 +3173,15 @@ static RPCMethod dumptxoutset()
    3173 |          // Dump the txoutset of the current tip
    3174 |          result = CreateUTXOSnapshot(node, chainstate, std::move(afile), path, temppath);
    3175 |      } else {
    3176 | -        // Check pruning constraints before attempting rollback and prevent
    3177 | -        // pruning of the necessary blocks with a temporary prune lock
    3178 | +        // Check that the blocks to disconnect are available and protect them from pruning
    


    danielabrozzoni commented at 1:20 PM on November 24, 2026:

    nit: I would expand the comment a little bit, it makes sense to explain why we are guarding with m_from_snapshot_blockhash, and also why GetPruneHeight makes sense even on non-pruned nodes:

    // Check that the blocks to disconnect are available and protect them from pruning.
    // They can be missing either because they were pruned, or because this is a snapshot
    // chainstate whose historical blocks have not been downloaded or connected yet.
    // We use GetPruneHeight in either case, as it scans down from the tip and returns the
    // highest block missing body or undo data
    
  17. in test/functional/feature_assumeutxo.py:693 in 4b3849d53b
     695 |  
     696 |          self.log.info("Check snapshot rollback from a tip with block data but no undo")
     697 |          first_snapshot_child = n1.getblockhash(SNAPSHOT_BASE_HEIGHT + 1)
     698 |          n1.invalidateblock(first_snapshot_child)
     699 |          assert_equal(n1.getbestblockhash(), snapshot_hash)
     700 | -        assert_equal(n1.getblock(snapshot_hash, 0), snapshot_block)
    


    danielabrozzoni commented at 1:21 PM on November 24, 2026:

    I think this is fine to leave, it proves that n1 has the block data for snapshot_block, it's only missing undo data

  18. in src/rpc/blockchain.cpp:3181 in 4b3849d53b
    3181 | -        if (node.chainman->m_blockman.IsPruneMode()) {
    3182 | +        if (const bool prune_mode{blockman.IsPruneMode()}; prune_mode || chainstate.m_from_snapshot_blockhash) {
    3183 |              LOCK(node.chainman->GetMutex());
    3184 | -            if (GetPruneHeight(node.chainman->m_blockman, chainstate.m_chain).value_or(0) >= target_index->nHeight) {
    3185 | -                throw JSONRPCError(RPC_MISC_ERROR, "Could not roll back to requested height since necessary block data is already pruned.");
    3186 | +            if (GetPruneHeight(blockman, chainstate.m_chain).value_or(0) > target_index->nHeight) {
    


    danielabrozzoni commented at 2:12 PM on November 25, 2026:

    Came up during review with Opus 5:

    In master we currently allow to call dumptxoutset with rollback=0, and the call will succeed as long as we are non pruned, and will produce an empty snapshot.

    With this PR, we introduce another case where rollback=0 is allowed, although much more exotic: pruned nodes but with all the block+undo data available, which can happen if one sets prune=1 and then doesn't prune anything, or if a pruned node is in early IBD. (In master this doesn't work, because GetFirstBlock excludes the genesis block as it has no undo data, and the rollback would fail with "Could not roll back to requested height since necessary block data is already pruned.", despite not having anything pruned. In this sense, this PR removes a confusing error that the user could get)

    In both cases, the snapshot produced is not wrong, it's simply expensive to create and useless. Not sure if it's worth to fix, but wanted to mention :)

    See: https://github.com/bitcoin/bitcoin/compare/master...danielabrozzoni:bitcoin:assumeutxo_rollback_0 - I pushed one commit to show the current behavior, the tree commits from this PR, and one test change to show the new behavior.

  19. danielabrozzoni commented at 2:13 PM on November 25, 2026: member

    Reviewed 4b3849d53b17f20ade22ce3feaa5b5dc9c8d21b0

    Left a couple of nits, and some thoughts around rollback=0. If we decide it's not worth fixing, or it's better to fix in a separate PR, happy to ACK.

    I took some notes while reviewing, sharing in case it's helpful to someone else: https://github.com/danielabrozzoni/bitcoin-notes/blob/master/reviews/36503.md :)


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-11-25 17:51 UTC

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