rpc: reject AssumeUTXO rollback without tip data #36503

Closed
l0rinc wants to merge 3 commits from l0rinc/rpc-dumptxoutset-missing-undo into master AGit
l0rinc commented 2026-10-11 22:50:54 +00:00 (Migrated from github.com)

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.

**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.
DrahtBot commented 2026-10-11 22:51:04 +00:00 (Migrated from github.com)

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

External sites

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 <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #36778 (AssumeUTXO: replace loadtxoutset RPC with a startup arg by l0rinc)
  • #36702 (validation: don't treat snapshot block as linked on startup by shuv-amp)
  • #36598 ([Demo] validation: remove AssumeUTXO by l0rinc)
  • #36266 (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.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36503 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36503.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36503#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept ACK | [musaHaruna](https://github.com/bitcoin/bitcoin/pull/36503#pullrequestreview-5492606225), [danielabrozzoni](https://github.com/bitcoin/bitcoin/pull/36503#pullrequestreview-6039733757) | | Stale ACK | [cyb3ralbert](https://github.com/bitcoin/bitcoin/pull/36503#pullrequestreview-5870781677) | 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](https://github.com/bitcoin/bitcoin/pull/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](https://github.com/bitcoin/bitcoin/pull/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) * [#36598](https://github.com/bitcoin/bitcoin/pull/36598) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36598.svg"></sub> ([Demo] validation: remove AssumeUTXO by l0rinc) * [#36266](https://github.com/bitcoin/bitcoin/pull/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-->
First-time contributor

🔵 Suggestion · The boundary relaxation in 4b3849d is bundled with snapshot guarding

Although the final guard is correct, 4b3849d couples a rollback-boundary relaxation affecting ordinary pruned nodes with unpruned-snapshot guarding and test rewrites that can be reviewed independently.

Location: src/rpc/blockchain.cpp:3179 (commit).

Review coverage was incomplete.


Reviewed: 4b3849d53b17 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:3f89681de11a6729a084d29fd96adfa42e3f319bf8f5c8ad91552cdeb231adb4:1ed10c4979af6fc548d6b8d4534d505e02e84ac4b0aa4f8633555b2ba75119e8 --> <!-- ralph-base:d55f55eda79a98ddaad7f7bec9faca8beb097b99 --> <!-- ralph-head:4b3849d53b17f20ade22ce3feaa5b5dc9c8d21b0 --> <!-- ralph-case:34df88dcae0c17bd09a6382aa65125626112aedcb5673ddc1f13297e6704a7b8 --> **🔵 Suggestion · The boundary relaxation in `4b3849d` is bundled with snapshot guarding** Although the final guard is correct, `4b3849d` couples a rollback-boundary relaxation affecting ordinary pruned nodes with unpruned-snapshot guarding and test rewrites that can be reviewed independently. Location: src/rpc/blockchain.cpp:3179 (commit). Review coverage was incomplete. <!-- Review tier: sensitive --> --- Reviewed: [`4b3849d53b17`](<https://git.fish.foo/bitcoin/bitcoin/commit/4b3849d53b17f20ade22ce3feaa5b5dc9c8d21b0>) · [Review report](<https://review.fish.foo/report/36503-4b3849d53b17f20ade22ce3feaa5b5dc9c8d21b0-2823-5.html>) · [Previous reports](<https://review.fish.foo/traces/36503/>) [permalink](<https://review.fish.foo/report/36503-4b3849d53b17f20ade22ce3feaa5b5dc9c8d21b0-2823-5.html>)
musaHaruna (Migrated from github.com) reviewed 2026-10-12 15:07:23 +00:00
musaHaruna (Migrated from github.com) left a comment

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.

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.
cyb3ralbert (Migrated from github.com) reviewed 2026-11-12 07:37:21 +00:00
cyb3ralbert (Migrated from github.com) left a comment

Tested ACK 3cb70c28f5

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
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 ```
danielabrozzoni (Migrated from github.com) reviewed 2026-11-25 14:13:25 +00:00
danielabrozzoni (Migrated from github.com) left a comment

Reviewed 4b3849d53b

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

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 :)
danielabrozzoni (Migrated from github.com) commented 2026-11-24 13:20:05 +00:00

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
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 ```
danielabrozzoni (Migrated from github.com) commented 2026-11-25 14:12:08 +00:00

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.

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.
danielabrozzoni (Migrated from github.com) commented 2026-11-24 13:21:21 +00:00

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

I think this is fine to leave, it proves that n1 has the block data for snapshot_block, it's only missing undo data
l0rinc commented 2026-12-02 20:19:13 +00:00 (Migrated from github.com)

Thanks for the comments, based on the latest comments I'm proposing complete removal instead, see #36598

Thanks for the comments, based on the latest comments I'm proposing complete removal instead, see #36598
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36503
No description provided.