mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 19:53:38 +00:00
indexes: Save progress on early flushes #36948
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!36948
Loading…
Reference in a new issue
No description provided.
Delete branch "issue-36939"
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?
Since #34897, a flush in
ConnectTip()can report a block before the index receivesBlockConnectedfor it. The locator check inChainStateFlushed()then skips saving the index tip. On a pruned assumeutxo node, repeated skips can leave the saved tip so far behind that the index needs blocks that were pruned by the time it restarts after background validation.This PR uses Fabian Jahr’s two commits. The first adds a unit test that reproduces the skipped write. The second removes the locator check and updates the test to verify the saved tip after reopening the index.
Commit()allows the write only if the index tip is at or is an ancestor of the chainstate’s last flushed block.Fixes #36939
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.Hi @mzumsande, @fjahr, and @l0rinc, could you take a look ?
Since the locator change in #34897, a flush can report a block before the index receives BlockConnected for it. Would you prefer letting the index save its current tip when the flushed block is ahead on the same chain, or changing the callback order in validation?
🔵 Suggestion · The flush-ahead test misses cross-branch commit rejection
The same-chain commit tests would still pass with a height-only
Commit()guard, so they do not verify the cross-branch rejection now relied on after removing the callback guard.Location:
src/test/baseindex_tests.cpp:115(head).Review coverage was incomplete.
Reviewed:
ea1b6cba295b· Review report · Previous reportspermalink
@LakshyaBagani I already developed a fix, just didn't get around to open the PR yet. You can see the branch here: https://github.com/fjahr/bitcoin/commits/2026-11-index-flush-commit/ I think that approach is better because
Commit()already refuses to write unless the index's best block is an ancestor of the chainstate's last flushed block, so the locator check that you keep and even widen here can only block commits that are safe, and removing it leaves one rule in one place. If you want you maintain it you can pull my commits in here, otherwise I can open a separate PR.Thanks for sharing your fix. I will bring both of your commits into this PR, credit you in the description, and follow up on reviews.
ACK
ea1b6cba29(Obviously not worth that much under the circumstances)
The CI currently doesn't run because you are a first time contributor @LakshyaBagani , I hope a maintainer can approve it soon.
Concept ACK
Commit()already checks whether the index tip is safe to save, so letting it handle a flush that arrives before its block notification fixes the skipped write.It complements #37044, which fixes block filter and CoinStats restart and rewind problems after reorgs, while this one keeps the saved index tip from falling behind when a flush is notified first.
I like the characterization before the fix, but I'd prefer the test to use the real flush notification so the ordering is easy to follow.
We don't actually need the locator here anymore.
Commit()already checks the index tip against the last flushed block, so the lookup doesn't affect whether the tip gets saved. The test can also use the real flush notification instead of callingChainStateFlushed()directly.CreateAndProcessBlock()drains the queue while the index is unregistered, so registering it beforeForceFlushStateToDisk()keeps the same ordering. The same test change works in the characterization commit too (where you could add a TODO to the incorrect line about to be changes i the next commit).Example patch