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):
- Added tck_chainstate_manager_options_set_prune_target(opts, prune_target_bytes).
- Exposed tck_PRUNE_TARGET_MANUAL (matching ode::BlockManager::PRUNE_TARGET_MANUAL) for manual pruning (-prune=1).
- Exposed tck_MIN_PRUNE_TARGET_BYTES (550 MiB, matching MIN_DISK_SPACE_FOR_BLOCK_FILES).
Kernel Implementation (src/kernel/bitcoinkernel.cpp):
- Implemented tck_chainstate_manager_options_set_prune_target().
- Validates that prune_target_bytes is either 0 (unpruned), tck_PRUNE_TARGET_MANUAL, or >= btck_MIN_PRUNE_TARGET_BYTES.
- Sets m_blockman_options.prune_target = prune_target_bytes and m_chainstate_load_options.prune = (prune_target_bytes > 0) under LOCK(opts.m_mutex).
C++ Wrapper & Tests:
- Added SetPruneTarget() in src/kernel/bitcoinkernel_wrapper.h.
- Added boundary tests in src/test/kernel/test_kernel.cpp (verifying rejection of < 550_MiB, acceptance of minimum, manual, and unpruned values).
Fixes #35627.