mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
validation: fix false corruption errors after pruning or AssumeUTXO #36452
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!36452
Loading…
Reference in a new issue
No description provided.
Delete branch "l0rinc/verify-pruned-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:
getblockfrompeerrestores a pruned block's body without recreating its undo record. If startup verification reaches that block at level >2, it attempts to disconnect it and reports database corruption, preventing the node from restarting.With ordinary pruning, reaching the restored block requires a deeper check than the default six blocks. The AssumeUTXO case can occur with the default checks.
Fix: Stop deep verification when a pruned node reaches missing undo data, using the existing result for unavailable history. The same allowance covers missing undo on AssumeUTXO snapshot chainstates, matching the existing treatment of unavailable snapshot history. Level 4 still reconnects the newer blocks that were disconnected.
verifychainreturnsfalseto indicate incomplete verification, including when undo is missing at the snapshot base. Lower verification levels and corruption checks for undo records marked as present retain their existing behavior.An AssumeUTXO restart can still hit a separate block-index candidate assertion after verification.
This came up during pruned
txindexreview. The pendingpruneassumevalidchange also needs verification to handle missing undo correctly, so this fix is being split out to land first.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.
A summary of reviews will appear here.
Conflicts
No conflicts as of last run.
🟠 Minor · Missing undo stops lower-level checks after cache exhaustion
When cache pressure has already disabled level-3 disconnects, the new missing-undo stop also omits lower-level checks of older available bodies, although no concrete deployment exhibiting this combination was identified.
Location:
src/validation.cpp:4775(head).🔵 Suggestion · Snapshot undo allowance extends above the snapshot base
On an unpruned snapshot chainstate, local index damage clearing
BLOCK_HAVE_UNDOabove the base can now bypass startup corruption detection when deep verification reaches that block with sufficient cache.Location:
src/validation.cpp:4728(head).🔵 Suggestion · Level-4 assertions miss an early missing-data return
The new level-4 test would accept a premature
SKIPPED_MISSING_DATAreturn that skips reconnection, and its RPC assertion cannot distinguish a reconnect error from expected incompleteness.Location:
test/functional/rpc_getblockfrompeer.py:167(head).🔵 Suggestion · Deep-verification tests do not pin boundary-body validation
The new valid-body fixture would still pass if the level-3/4 missing-undo stop moved ahead of
ReadBlockandCheckBlock, bypassing validation of the restored boundary body.Location:
test/functional/rpc_getblockfrompeer.py:165(head).Review coverage was incomplete.
Reviewed:
f685225d6857· Review report · Previous reportspermalink
IIUC this bug can't realistically be triggered with default
checkblocks=6config.This would require a
checkblocksvalue of > 288 (or 0 to go all the way back) and the user would have to callgetblockfrompeerfor the block at the exact prune boundary. If a single fully-pruned block sits between the last non-pruned block and the fetched block with no undo, then this bug will not trigger.@andrewtoth, that’s right for ordinary pruning, but this can also happen with default checks under AssumeUTXO before background validation reaches the requested block, so I’ve added a small test for that and expanded the
verifychaintest coverage following Ralph AI’s suggestions - hope it's clearer now.This change is also a prerequisite for the
pruneassumevalidchange I’m currently working on, which won’t retain the 288-block reorg buffer in the assumevalid region during IBD since we don’t expect reorgs there after headers-first sync.Question first: when the snapshot base block's body is present but has no undo data (the state the new
feature_assumeutxo.pycase creates; it arrives the same way viasubmitblockor as an unsolicitedblockmessage from a peer), a restart of that node with default-checkblocks/-checklevelone262a1fbf7now passesVerifyDB(Block verification stopping at height 299 (no undo data).) and then aborts at startup:validation.cpp:3144: CBlockIndex* Chainstate::FindMostWorkChain(): Assertion `pindexTest->HaveNumChainTxs() || pindexTest->nHeight == 0' failed.Is the AssumeUTXO part of this PR meant to make startup verification stop erroring on such a node, with the restart itself left to #35307? A line in the description would make that explicit.The abort is not introduced here: the merge-base with
-checklevel=1(soVerifyDBdoes not fail first) hits the same assertion on the same line, and so does a snapshot tip above the base (base + 6 blocks, base body delivered first) on both trees; without the base body the restart works on both. With #35307 merged the same restarts succeed, and applying only itsPopulateBlockIndexCandidateshunk on top of this head is enough.Related: #35307 adds
if (is_snapshot_cs && pindex == chainstate.SnapshotBase()) break;in the samenCheckLevel >= 3block, and this PR removesis_snapshot_cs. The two conflict invalidation.cpp, and keeping #35307's hunk as is does not compile ('is_snapshot_cs' was not declared in this scope). Itsbreakdoes not setskipped_missing_data, so the order of the two checks decides whatverifychain()returns at the snapshot base: with this PR's check first the newfeature_assumeutxo.pyassertion passes, with #35307's first it fails (not(True == False)). Which value is intended once both land?Tested on Linux aarch64 (Debian 13), GCC 14.2.0, Release,
e262a1fbf7(merges cleanly with masterde96f3ae6d).feature_assumeutxo.pyandrpc_getblockfrompeer.pyfrom this PR fail on the merge-basecce32b1687(Block verification stopping at height 299 / 752 (no undo data).not found) and pass on the head. On a pruned regtest node with the highest pruned block (249) refetched viagetblockfrompeer, a restart with-checkblocks=0fails at-checklevel=3and4on the merge-base (irrecoverable inconsistency in block data at 249) and starts on the head (checked last 551 blocks); level 2 and default checks start on both.verifychainat levels 3 and 4 returns false both before and after. A flipped last byte of the newestrev*.datis still rejected at levels 2 and 3 on both trees (found bad undo data at 800). The neighbouring prune, reindex and assumeutxo functional tests (10, incl.feature_pruning.pyandwallet_assumeutxo.py) pass on the head. With #35307 merged (conflict resolved by keeping both checks),feature_assumeutxo.py,rpc_getblockfrompeer.pyandwallet_assumeutxo.pypass.Reading the code: the new check sits after the level 0-2 reads; it tests the
BLOCK_HAVE_UNDObit directly, while the level-2 check reads the undo position viaGetUndoPos().PruneOneBlockFileclears the bit and zeroes the position together. The code comment notes that a block refetched after pruning has its body but not its undo data. Nit:SKIPPED_MISSING_BLOCKSnow also covers a missing undo record; the local flag was renamed, the enum value was not.Rebased, renamed
SKIPPED_MISSING_BLOCKStoSKIPPED_MISSING_DATAto cover missing undo, and clarified that default checks can reach this case under AssumeUTXO and that a separate startup assertion can still occur.