mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
WIP: refactor: break the blockstorage/validation circular dependency #36858
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!36858
Loading…
Reference in a new issue
No description provided.
Delete branch "blockstorage-drop-friends"
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?
node/blockstorage.cppincludesvalidation.h, and the lint listsnode/blockstorage -> validation -> node/blockstorageas an expected circular dependency. This removes it, and the lint confirms the cycle is gone.The largest user of validation in block storage is
ImportBlocks, which drives validation. It moves tonode/chainstateand sets the reindex flag through the newBlockManager::SetBlockfilesIndexed(), which writes the flag to the block tree database and sets the in-memory flag under onecs_mainhold. The last commit movesFatalErrortokernel/fatal_error.h, after whichblockstorage.cppno longer includesvalidation.h.validation.hstill exportsFatalErrorfor its other users.Validation also reaches into
BlockManager's private members as a friend.RequestPrune()andMarkBlockIndexDirty()replace the friend declarations, keepingm_check_for_pruningandm_dirty_blockindexnon-public. Both requirecs_main, and the annotations let the compiler check it. After this, nothing outsideBlockManagerwrites its private state or the block tree database.There is no behavior change to my knowledge.
Based on #36738. Draft until it is merged.
Thanks to musaHaruna, who suggested
RequestPrune()in his review on my fork. The flag marks a pending pruning check, so callers request it and storage decides whether anything qualifies, which keeps the flag private once the friend declarations are gone.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.
🔵 Suggestion · Pending-unlink cancellation lacks regression coverage
The new failure test would still pass without
m_files_to_unlink.erase(nFile)because it never writes into a file while that file is queued for deletion.Location:
src/node/blockstorage.cpp:967(head).🔵 Suggestion · The pruned flag remains a caller-managed prerequisite
The sole caller correctly sets
prunedblockfiles, but the extracted storage API leaves this invariant dependent on a separate caller step thatBlockManagercan own.Location:
src/node/blockstorage.cpp:831(head).🔵 Suggestion · Negative prune limits disable the upper-height filter
No current caller producing negative limits was found, but
{0, -1}disables the public selectors' upper-height filter in production builds.Location:
src/node/blockstorage.cpp:317(head).🔵 Suggestion · Forced recovery does not test deferred unlink scheduling
The forced retry in
prune_flush_failurecannot distinguish the intended deferred unlink scheduling from a regression that makes pending deletions trigger another write.Location:
src/test/chainstate_write_tests.cpp:210(head).🔵 Suggestion · Prune selection lacks a caller-side
cs_maincontractCurrent callers hold
cs_main, but the public selectors do not require it, so thread-safety analysis cannot flag unlocked selection after callers compute chainstate-dependent limits.Location:
src/node/blockstorage.h:370(head).🔵 Suggestion · The uncoordinated block-index writer remains public
WriteBlockStorage()is now the only caller ofWriteBlockIndexDB(), but the public helper still permits bypassing the block-file flush and pending-unlink sequence.Location:
src/node/blockstorage.cpp:849(head).Review coverage was incomplete.
Reviewed:
552b3a46a027· Review report · Previous reportspermalink
Concept ACK