mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 16:17:38 +00:00
kernel: Add function for setting prune target in ChainstateManagerOptions #36630
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!36630
Loading…
Reference in a new issue
No description provided.
Delete branch "kernel-prune-target"
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?
Motivation & Background
Currently, the libbitcoinkernel C API does not provide a way to configure block pruning on tck_ChainstateManagerOptions. Even though the underlying
ode::BlockManager::Options and
ode::ChainstateLoadOptions structures support pruning, libbitcoinkernel callers cannot pass a prune target.
Consequently, trying to open an existing pruned node's data directory fails during
ode::LoadChainstate() with:
[error] Failed to load chain state from your data directory: You need to rebuild the database using -reindex to go back to unpruned mode.because chainman.m_blockman.m_have_pruned is true while options.prune defaults to false.
Description of Changes
C API (src/kernel/bitcoinkernel.h):
ode::BlockManager::PRUNE_TARGET_MANUAL) for manual pruning (-prune=1).
Kernel Implementation (src/kernel/bitcoinkernel.cpp):
C++ Wrapper & Tests:
Fixes #35627.
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:
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.
Base:
df0dc1e2d2059213e49a9f115fd55a9f0119d26cHead:
d42579ffb9aea429ce76934c90bbb65da21d62b2Findings
Major
Pass a name to
TestDirectory(src/test/kernel/test_kernel.cpp:904, head)TestDirectoryonly has a constructor that takes astd::string, so this default construction is ill-formed and prevents the test target from compiling. Construct it with a directory-name string.Suggestions
Test loading a datadir with persisted pruning state (src/test/kernel/test_kernel.cpp:901, head)
The construction at this line uses
test_directory, which was initialized with default, unpruned options; the other added construction uses a fresh directory. Neither establishesm_have_pruned, which is required for the load rejection inCompleteChainstateInitialization. Consequently, these checks would not catch a regression that stopped settingm_chainstate_load_options.prune. Add a fixture with persisted pruned state and verify reopening it with pruning enabled; retain the boundary checks separately.Design and approach
Concept and approach. Separate the explicit opt-in to load an already-pruned datadir from automatic target pruning. Before offering automatic deletion, establish how callers can protect blocks they still need, for example through a public retention mechanism. The current API combines load compatibility with deletion policy but cannot represent application-specific retention needs. (discussion, discussion, discussion)
Review coverage was incomplete.
Review limitations
Full review report
Could you revisit the discussion in #35627? This PR exposes automatic pruning through
ChainstateManagerOptions, while the storage-interface and application-retention concerns raised in the issue remain unresolved.The added tests do not exercise the reported problem. They check four setter return values, then reset the target to 0 before constructing the chainstate manager. They therefore do not demonstrate that an existing pruned directory can be opened successfully, or that automatic pruning behaves correctly.
Thanks for the thoughtful review and feedback @musaHaruna!
Good catch on the test; resetting the target back to 0 right before constructing
ChainManonly verified the option boundary validation rather than exercisingChainstateManagerconstruction in pruned mode. I have updated the test to construct and verifyChainManwith a pruned configuration.Regarding the broader architectural discussion in #35627: the intent here was to provide the minimal options setter needed to unblock loading existing pruned datadirs (where
chainman.m_blockman.m_have_prunedrequiresoptions.pruneinnode::LoadChainstate), while respectingBlockManager's existing manual/target semantics.However, I completely understand the concern regarding full automatic pruning without application-level prune locks / retention controls in place. Would you recommend scoping this PR down strictly to an explicit compatibility opt-in (e.g. allowing existing pruned storage without exposing automatic disk-target pruning), or how would you prefer we structure this first step?
violates https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md, quite obviously
Understood, apologies for the writeup format.
The patch itself is a small, concrete fix for libbitcoinkernel (#35627): exposing
prune_targetinbtck_ChainstateManagerOptionsso that loading an existing pruned datadir doesn't fail onm_have_pruned.Added unit tests in
src/test/kernel/test_kernel.cppverifying the boundary limits (unpruned, manual, >= 550 MiB).Happy to reopen whenever @stickies-v or @TheCharlatan have bandwidth to review the kernel API changes.