mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:47:36 +00:00
blockstorage: keep snapshot base in normal blockfile range #35307
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!35307
Loading…
Reference in a new issue
No description provided.
Delete branch "blockstorage-assumeutxo-base-range"
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?
A node that has the assumeutxo snapshot base block on disk before
loadtxoutset()runs ends upin a state it cannot recover from. Depending on whether it is restarted, it either aborts or
refuses to start.
Aborting, when background validation reaches the base block:
Refusing to start, if the node is restarted after the snapshot is loaded:
The block database is not corrupt, so the reindex that message asks for is wasted work.
Reaching this needs the base block stored before the snapshot is loaded, which
submitblockdoes: it is accepted and written while
BlockManager::m_snapshot_heightis still unset, so itgoes to the normal blockfile cursor.
loadtxoutset()then setsm_snapshot_heightto that sameheight, and
BlockfileTypeForHeight()starts reportingASSUMEDfor it.From there the two failures follow:
WriteBlockUndo()looks up the cursor for the block's height and does*Assert(m_blockfile_cursors[type]). The block is nowASSUMED, but nothing above thesnapshot height has been written, so that cursor does not exist and the assertion fires when
the background chainstate connects the base.
FindNextBlockPos()creates the cursor lazily inthe same situation;
WriteBlockUndo()asserts instead.VerifyDB()skips blocks withoutBLOCK_HAVE_DATAon a snapshot chainstate(
validation.cpp:4674), which is why the base is normally left alone. Here the base does havedata, and no undo data because the snapshot chainstate never connected it, so the skip does not
apply and
DisconnectBlock()is attempted on it.The base block is connected by the background chainstate, not the snapshot one, so it belongs to
the normal blockfile range.
BlockfileTypeForHeight()now classifies only blocks above thesnapshot height as
ASSUMED. A snapshot chainstate sitting at the base height must not flush thenormal cursor, so
FlushChainstateBlockFile()takes the chainstate into account.VerifyDB()stops before disconnecting the snapshot base, where the snapshot database does nothave the ancestor UTXO data the disconnect needs.
When a snapshot chainstate is loaded from disk, the base's hardcoded
m_chain_tx_countdoes notmean the background chainstate has processed its parents, so the base is kept in
m_blocks_unlinkeduntil they arrive, and a historical chainstate does not add its target to theblock index candidates before then.
The functional test submits the base block, loads the snapshot, restarts, then feeds the missing
historical blocks and checks that background validation completes. Both failures above are what
it hits without this change.
Tested:
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:
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.
why would someone load a snapshot when they already downloaded the block, which means that their tip must be no more than 1024 blocks behind that block.
I don't think the normal P2P download path is a strong motivation here. In that case, as you say, the node would already be close to the snapshot height.
The case covered here is that this blockstorage state is accepted through local block submission/import before snapshot activation. For example,
submitblockcan store the snapshot base block whilem_snapshot_heightis still unset, so it is accounted under the normal blockfile cursor. Afterloadtxoutset(), the same height maps toASSUMED; if no assumed blockfile cursor exists yet, background validation can later connect that block and hit the cursor assertion inWriteBlockUndo().So I’d frame this as making an accepted blockstorage state not abort, rather than as an important/common assumeutxo path. If maintainers prefer not to support that state, rejecting it during snapshot
activation would be another possible direction.
Taking this back to draft for now.
Following up with what this actually does on master, in May I only described the assertion.
If the node is restarted after the snapshot is loaded, it doesn't come back up:
The database isn't corrupt, with this change the same sequence restarts and background
validation completes. On a snapshot chainstate
VerifyDB()stops its walk at the first blockwith no data, which is normally the base, so it never gets that far. Here the base does have
data, and no undo data because the snapshot chainstate never connected it, so the walk goes into
it and the disconnect fails. The
WriteBlockUndo()assertion I mentioned in May is the otherpath, when the node keeps running rather than restarting.
I've kept this as fixing the state rather than rejecting it at activation, since rejecting
wouldn't help a node that has already reached it.
Rebased.
Review failed because required verification did not complete.
Earlier concerns remain unresolved; see the full report for their current assessments.
Review coverage was incomplete.
Reviewed:
d07900cf8cc7· Full review report · Previous reportsralph referenced this pull request2026-10-15 11:46:23 +00:00
🐙 This pull request conflicts with the target branch and needs rebase.
I agree that this is an issue that can only be hit in theory and I don't think it's important enough to fix as the motivation is stated.
Concept NACK
Closing for now due to controversy. If there is need in the future, this can be re-opened, or a new pull can be opened.