mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
rpc: reject AssumeUTXO rollback without tip data #36503
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!36503
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/rpc-dumptxoutset-missing-undo"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem: Loading a UTXO snapshot on a pruned node can leave the active tip without block or undo data. Attempting a rollback with
dumptxoutsetthen triggers an assertion and terminates the node.Fix: Reuse
GetPruneHeightto reject rollback with the existing pruning error when the required data is unavailable.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.
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:
loadtxoutsetRPC with a startup arg by l0rinc)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.
🔵 Suggestion · The boundary relaxation in
4b3849dis bundled with snapshot guardingAlthough the final guard is correct,
4b3849dcouples 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 reportspermalink
Concept ACK. The fix looks straightforward and contained:
GetPruneHeighthandles missing data at the tip before callingGetFirstBlock, 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
TemporaryPruneLockcould still remain conditional onIsPruneMode().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 inCreateRolledBackUTXOSnapshotuses: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
GetPruneHeightreturns 299, the current299 >= 299check rejects that request, whereas299 > 299would 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.Tested ACK
3cb70c28f5Tested on Linux aarch64, GCC 14.2.0, Release build:
feature_assumeutxo.pyandrpc_dumptxoutset.pypassed.Cases checked:
GetFirstBlock()on the base commit and return the expected RPC errors with the fix.To reproduce the functional tests:
Reviewed
4b3849d53bLeft 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 :)
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 whyGetPruneHeightmakes sense even on non-pruned nodes:Came up during review with Opus 5:
In master we currently allow to call
dumptxoutsetwithrollback=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=0is allowed, although much more exotic: pruned nodes but with all the block+undo data available, which can happen if one setsprune=1and then doesn't prune anything, or if a pruned node is in early IBD.(In master this doesn't work, because
GetFirstBlockexcludes 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.
I think this is fine to leave, it proves that n1 has the block data for snapshot_block, it's only missing undo data
Thanks for the comments, based on the latest comments I'm proposing complete removal instead, see #36598