kernel: let callers create the block manager #36854

pull pzafonte wants to merge 4 commits into bitcoin:master from pzafonte:kernel-create-block-manager changing 14 files +497 −187
  1. pzafonte commented at 3:08 PM on November 13, 2026: contributor

    The kernel creates its block storage inside btck_chainstate_manager_create, configures it through the chainstate manager's options and reads blocks through the chainstate manager. Pruning (#35627) needs block storage that the caller can configure, keep and prune directly.

    This adds btck_BlockManagerOptions and btck_BlockManager. btck_chainstate_manager_create takes a block manager and keeps a shared reference to it, so either handle can be destroyed first. A block manager can be passed to only one chainstate manager, and a failed creation still uses it up unless the contexts differ. btck_block_read and btck_block_spent_outputs_read take the block manager, and block tree entries are valid for its lifetime, which can be longer than the chainstate manager's.

    Changes for callers:

    • btck_chainstate_manager_options_create no longer takes a blocks directory.
    • btck_chainstate_manager_options_set_wipe_dbs is replaced by btck_block_manager_options_update_wipe_block_tree_db and btck_chainstate_manager_options_update_wipe_chainstate_db. The block tree db is wiped when the block manager is created, and wiping it also wipes the chainstate db, which the old function required anyway.
    • btck_chainstate_manager_options_update_block_tree_db_in_memory moves to the block manager options.
    • Both options objects take the same total database cache, and each uses its own share.

    Based on #36739. Draft until it is merged. Feedback on the API is welcome in the meantime.

  2. kernel: destroy chainstate manager first
    ChainMan declares m_context last, which destroys it before the
    ChainstateManager that refers into it. Reset the chainstate manager
    explicitly, making the order independent of member declaration order.
    05aa0b7d38
  3. refactor: pass BlockManager to ChainstateManager
    Create the BlockManager first and pass it in by reference. NodeContext
    and the kernel own both and destroy ChainstateManager first.
    
    The block tree database opens before the script verification threads
    start, which swaps their startup log lines.
    b9a83c74bd
  4. refactor: remove ChainstateLoadOptions::prune
    The flag duplicated the BlockManager's prune mode. Init and the test
    setup copied it, and the kernel left it false. Check the BlockManager
    directly, keeping one source of truth before the kernel can enable
    pruning.
    bfb52b50f5
  5. kernel: let callers create the block manager
    Block storage was configured and read through the chainstate manager.
    Add btck_BlockManagerOptions and btck_BlockManager, and pass the block
    manager to btck_chainstate_manager_create, which keeps a shared
    reference, so either can be destroyed first. A block manager serves
    one chainstate manager.
    
    btck_block_read and btck_block_spent_outputs_read take the block
    manager. Each options object takes the total database cache and uses
    its part. Wiping the block tree db also wipes the chainstate db.
    d26ba9d2e2
  6. DrahtBot added the label Validation on Nov 13, 2026
  7. DrahtBot commented at 3:08 PM on November 13, 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 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) → Prefer BOOST_CHECK_EXCEPTION with a HasReason predicate that checks the failure message.
    • src/test/kernel/test_kernel.cpp: BOOST_CHECK_THROW(ChainstateManagerOptions(context, ""), std::runtime_error) and the null-path equivalent → Prefer BOOST_CHECK_EXCEPTION with a HasReason predicate.
    • src/test/kernel/test_kernel.cpp: BOOST_CHECK_THROW(ChainMan(context, chainman_opts, blockman), std::runtime_error) for the context mismatch and already-used block manager → Prefer BOOST_CHECK_EXCEPTION with a HasReason predicate.
    • src/test/kernel/test_kernel.cpp: BOOST_CHECK_THROW(blockman.ReadBlockSpentOutputs(tip), std::runtime_error) → Prefer BOOST_CHECK_EXCEPTION with a HasReason predicate.

    <sup>2026-11-13 15:09:15</sup>


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-11-14 11:51 UTC

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