Repository navigation
kernel: Add function for setting prune target in ChainstateManagerOptions - #36630
rahadbhuiya wants to merge 2 commits into
Conversation
…ions Currently, libbitcoinkernel's C API does not expose any mechanism to configure the block pruning target on btck_ChainstateManagerOptions, even though the underlying node::BlockManager::Options and node::ChainstateLoadOptions fully support pruning. Consequently, attempting to use libbitcoinkernel with an existing pruned datadir fails during LoadChainstate() with an error directing the user to reindex. Introduce btck_chainstate_manager_options_set_prune_target() to allow configuring the prune target on btck_ChainstateManagerOptions. - Disabling pruning is represented by 0 (the default). - Manual pruning is represented by btck_PRUNE_TARGET_MANUAL (matching node::BlockManager::PRUNE_TARGET_MANUAL). - Automatic pruning requires at least btck_MIN_PRUNE_TARGET_BYTES (550 MiB, matching MIN_DISK_SPACE_FOR_BLOCK_FILES). Setting a non-zero prune target sets opts.m_blockman_options.prune_target and enables opts.m_chainstate_load_options.prune under the options mutex, allowing libbitcoinkernel to open and operate on pruned datadirs. Also adds C++ wrapper method SetPruneTarget() and unit tests validating boundary behavior in test_kernel.cpp. Closes bitcoin#35627.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process. ConflictsReviewers, 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. |
|
Could you revisit the discussion in #35627? This PR exposes automatic pruning through 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 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 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? |
|
Understood, apologies for the writeup format. The patch itself is a small, concrete fix for libbitcoinkernel (#35627): exposing Added unit tests in Happy to reopen whenever @stickies-v or @TheCharlatan have bandwidth to review the kernel API changes. |

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.