Kernel blockstorage pruning #36419

pull pzafonte wants to merge 10 commits into bitcoin:master from pzafonte:kernel-blockstorage-pruning changing 18 files +783 −301
  1. pzafonte commented at 3:20 PM on October 2, 2026: contributor

    I would like to be able to do pruning in the kernel-node, but right now the kernel can't open a data directory that Bitcoin Core has pruned or prune its own block storage.

    This separates block storage from chainstate management first and then adds pruning to the kernel API.

    Commits 1 to 6 are refactors, and should not impose any behavior change. Commits 7 to 10 add a block manager and pruning to the kernel API

    1. Apply prune locks in BlockManager instead of in validation.
    2. Give BlockManager a height range and sizes to prune within, instead of letting it read the chainstate.
    3. Move ImportBlocks, which drives validation, out of block storage.
    4. Remove the friend declarations, so validation only uses BlockManager's public interface.
    5. Create the BlockManager first and pass it to ChainstateManager by reference. Block storage then no longer belongs to chainstate management.
    6. Remove ChainstateLoadOptions::prune, which duplicated BlockManager's prune mode.
    7. Add btck_BlockManager and read blocks through it. This changes the first parameter of btck_block_read and btck_block_spent_outputs_read.
    8. Add pruning up to a height and prune locks. Also lets the kernel open a data directory that Bitcoin Core has pruned.
    9. Add automatic pruning to a target size.
    10. Add btck_chainstate_manager_get_first_available_entry
  2. refactor: apply prune locks in BlockManager
    Validation read BlockManager's prune locks directly. Move that code and
    PRUNE_LOCK_BUFFER into BlockManager.
    38961e38fb
  3. refactor: pass prune limits to BlockManager
    BlockManager used the chainstate to decide what to prune. Make that
    decision in validation and pass BlockManager only a height range and
    sizes.
    b600af49c3
  4. refactor: move ImportBlocks to node/chainstate
    ImportBlocks drives validation and does not belong in block storage.
    Review with --color-moved.
    5090f1ee12
  5. refactor: remove BlockManager's friend declarations
    Validation only needed three non-public members and the blocks
    directory. Make those public, with a getter for the directory, and drop
    the friend declarations.
    7b7d30a61f
  6. refactor: let ChainstateManager borrow its BlockManager
    Create the BlockManager separately and pass it in by reference.
    NodeContext and the kernel own both and destroy ChainstateManager first.
    f617a4b2f5
  7. refactor: remove ChainstateLoadOptions::prune
    Every caller set it from the BlockManager's prune mode. Check that
    directly.
    9a17b52012
  8. kernel: read blocks through a block manager
    Add btck_BlockManager and read blocks and spent outputs through it, not
    the chainstate manager. This changes the first parameter of
    btck_block_read and btck_block_spent_outputs_read.
    dcd04e32f9
  9. kernel: add pruning
    Add an option to enable pruning, and block manager functions to prune up
    to a height and to set and delete prune locks. The option also lets the
    kernel open a data directory that Bitcoin Core has pruned.
    
    Pruning still goes through the active chainstate, which decides what may
    be deleted.
    
    Export a fast prune setter only for test_kernel, since test chains never
    fill a 128 MiB block file.
    3cd617e1ac
  10. kernel: add automatic pruning
    Add a target size option. Blocks are then deleted to stay below it,
    except the 288 most recent and those kept by prune locks. Prune locks
    can also be set in the options, because loading can already trigger
    pruning.
    
    Automatic deletion is untested, as test chains never reach the 550 MiB
    minimum target.
    ee5cc5e735
  11. kernel: expose first available block tree entry
    Return the lowest active chain entry from which every block up to the
    tip can be read with its spent outputs. Spent outputs count because a
    pruned block that is processed again is stored without them.
    
    Move GetPruneHeight from rpc to node/blockstorage so the kernel can use
    it. Review with --color-moved.
    820d333e49
  12. DrahtBot commented at 3:20 PM on October 2, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    External sites

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline and AI policy for information on the review process. A summary of reviews will appear here.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

    LLM Linter (✨ experimental)

    Possible typos and grammar issues:

    • // make sure we don't prune above any of the prune locks bestblocks -> // make sure we don't prune above any of the prune locks' best blocks [“bestblocks” is a typo; the intended phrase is unclear without splitting it into two words]

    Possible places where comparison-specific test macros should replace generic comparisons:

    • [src/test/kernel/test_kernel.cpp] BOOST_CHECK_THROW(chain.GetByHeight(1000), std::runtime_error); -> Prefer BOOST_CHECK_EXCEPTION with a predicate that checks the exception text, rather than only the generic exception type.
    • [src/test/kernel/test_kernel.cpp] BOOST_CHECK_THROW(blockman.ReadBlockSpentOutputs(chain.GetByHeight(1)), std::runtime_error); -> Prefer BOOST_CHECK_EXCEPTION with a message matcher to validate the specific failure.
    • [src/test/kernel/test_kernel.cpp] BOOST_CHECK_THROW(create_chainman(test_directory, /*reindex=*/false, /*wipe_chainstate=*/false, /*block_tree_db_in_memory=*/false, /*chainstate_db_in_memory=*/false, context), std::runtime_error); -> Prefer BOOST_CHECK_EXCEPTION with a predicate on the error message.
    • [src/test/kernel/test_kernel.cpp] BOOST_CHECK_THROW(blockman.ReadBlockSpentOutputs(tip), std::runtime_error); -> Prefer BOOST_CHECK_EXCEPTION with a message matcher instead of only asserting the exception type.

    <sup>2026-10-02 15:21:02</sup>

  13. pzafonte closed this on Oct 2, 2026

Contributors

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-10-11 10:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me