mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 12:20:38 +00:00
WIP: kernel: add manual pruning #36856
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!36856
Loading…
Reference in a new issue
No description provided.
Delete branch "kernel-prune-up-to-height"
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?
Part of #35627 and kernel-node/kernel-node#111. The kernel can't open a data directory that a pruned node created, and it has no way to prune.
This adds a prune option on the block manager,
btck_block_manager_prune_up_to_heightandbtck_chainstate_manager_flush. With the option set, the kernel opens pruned data directories. The chainstate manager created with the block manager decides what may be deleted, so pruning fails without one.Pruning writes only block storage, never the chainstate. After an unclean shutdown the chainstate on disk is at the last flush, and recovering from there needs the blocks above it. Pruning therefore keeps every block above the fork point between the last flushed block and the active chain, and reports
btck_PruneStatus_NEEDS_FLUSHwhen that bound limited what it could delete. The caller can flush and prune again.The fork point matters when the flushed block was reorged out. Recovery then disconnects the stale blocks, which needs their block and undo data, and connects the new ones from their block data.
btck_block_manager_prune_reorg_testscovers that case and fails if the bound uses the flushed block's height instead.A fast prune option lets tests prune, since test chains never fill a 128 MiB block file.
Based on #36738 and #36854. Draft until both are merged.
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
Reviewers, this pull request conflicts with the following ones:
-Wunusedby fanquake)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.
LLM Linter (✨ experimental)
Possible places where comparison-specific test macros should replace generic comparisons:
src/test/kernel/test_kernel.cpp:BOOST_CHECK_THROW(BlockManagerOptions(context, data_dir, blocks_dir), std::runtime_error)→ PreferBOOST_CHECK_EXCEPTION(..., std::runtime_error, HasReason{"..."})to verify the failure reason.src/test/kernel/test_kernel.cpp: BothBOOST_CHECK_THROWchecks for emptyChainstateManagerOptionspaths → PreferBOOST_CHECK_EXCEPTION(..., std::runtime_error, HasReason{"..."}).src/test/kernel/test_kernel.cpp: TheBOOST_CHECK_THROWchecks for a different context and for reusing a block manager → PreferBOOST_CHECK_EXCEPTION(..., std::runtime_error, HasReason{"..."})to check the specific failure message.src/test/kernel/test_kernel.cpp:BOOST_CHECK_THROW(create_chainman(...), std::runtime_error)when opening a pruned directory without pruning enabled → PreferBOOST_CHECK_EXCEPTION(..., std::runtime_error, HasReason{"..."}).src/test/kernel/test_kernel.cpp: The twoBOOST_CHECK_THROW(blockman.ReadBlockSpentOutputs(...), std::runtime_error)checks after spent-output data is unavailable → PreferBOOST_CHECK_EXCEPTION(..., std::runtime_error, HasReason{"..."}).2026-11-13 15:25:50
🟠 Minor · Storage exceptions escape the pruning C API
A local storage exception during an eligible prune bypasses the documented error return and
fatalError; no current test or caller producing a block-tree write failure was found.Location:
src/kernel/bitcoinkernel.cpp:1345(head).🔵 Suggestion · An in-memory flush satisfies the durable pruning bound
With an in-memory coins database and disk-backed block storage, pruning can remove blocks needed for rebuilding after restart; the API does not define whether this combination is disposable-only.
Location:
src/kernel/bitcoinkernel.cpp:1336(head).🔵 Suggestion · Wipe-plus-prune file deletion is missing from the API docs
Combining pruning and block-tree wiping deletes block and undo files during block-manager creation, before import or manual pruning, but the new option docs describe only database wiping.
Location:
src/kernel/bitcoinkernel.h:1255(head).🔵 Suggestion ·
NEEDS_FLUSHcan be set when no file is held backThe height-only status can prompt a forced coins-cache sync even when flushing cannot make another file eligible for deletion.
Location:
src/kernel/bitcoinkernel.cpp:1338(head).🔵 Suggestion · Reorg recovery after a persisted prune is not tested
The reorg fixture checks in-process readability but never reloads a persisted prune while the coins database still points to the stale branch.
Location:
src/test/kernel/test_kernel.cpp:1446(head).🔵 Suggestion · Deleting prunes do not test the no-chainstate-flush invariant
The kernel prune tests delete files only immediately after an explicit flush, so they do not detect a chainstate sync added only to the deleting path.
Location:
src/test/kernel/test_kernel.cpp:1376(head).Review coverage was incomplete.
Reviewed:
2e21a991cbc3· Review report · Previous reportspermalink
🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/43452418783/job/131977732637LLM reason (✨ experimental): CI failed because IWYU added missing includes in
src/kernel/bitcoinkernel.cpp, leaving an uncommitted diff that the lint check rejects.Hints
Try to run the tests locally, according to the documentation. However, a CI failure may still
happen due to a number of reasons, for example:
Possibly due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.
A sanitizer issue, which can only be found by compiling with the sanitizer and running the
affected test.
An intermittent issue.
Leave a comment here, if you need help tracking down a confusing failure.