Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. |
There was a problem hiding this 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
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. IfGetPruneHeightreturns 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.
cyb3ralbert
left a comment
There was a problem hiding this comment.
Tested ACK 3cb70c2
Tested on Linux aarch64, GCC 14.2.0, Release build:
feature_assumeutxo.pyandrpc_dumptxoutset.pypassed.- 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
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 bitcoin#36503 (review)
3cb70c2 to
4107215
Compare
Record the assertion when the snapshot tip lacks block data or undo, then restart the node to continue the existing checks.
Reuse GetPruneHeight to return the existing pruning error when the snapshot tip lacks block or undo data.
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 bitcoin#36503 (review)
4107215 to
4b3849d
Compare
danielabrozzoni
left a comment
There was a problem hiding this comment.
Reviewed 4b3849d
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 :)
| } else { | ||
| // Check pruning constraints before attempting rollback and prevent | ||
| // pruning of the necessary blocks with a temporary prune lock | ||
| // Check that the blocks to disconnect are available and protect them from pruning |
There was a problem hiding this comment.
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
| first_snapshot_child = n1.getblockhash(SNAPSHOT_BASE_HEIGHT + 1) | ||
| n1.invalidateblock(first_snapshot_child) | ||
| assert_equal(n1.getbestblockhash(), snapshot_hash) | ||
| assert_equal(n1.getblock(snapshot_hash, 0), snapshot_block) |
There was a problem hiding this comment.
I think this is fine to leave, it proves that n1 has the block data for snapshot_block, it's only missing undo data
| LOCK(node.chainman->GetMutex()); | ||
| if (GetPruneHeight(node.chainman->m_blockman, chainstate.m_chain).value_or(0) >= target_index->nHeight) { | ||
| throw JSONRPCError(RPC_MISC_ERROR, "Could not roll back to requested height since necessary block data is already pruned."); | ||
| if (GetPruneHeight(blockman, chainstate.m_chain).value_or(0) > target_index->nHeight) { |
There was a problem hiding this comment.
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: 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.
|
Thanks for the reviews, based on the latest comments I'm proposing complete removal instead, see #36598 |

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.