kernel: Rename in-memory DB option setters and simplify API #33877

pull stringintech wants to merge 1 commits into bitcoin:master from stringintech:2025/11/kernel-in-mem-options changing 4 files +23 −25
  1. stringintech commented at 1:28 pm on November 15, 2025: contributor
    Remove the int parameter from btck_chainstate_manager_options_*_in_memory functions and rename them from “update” to “set”. These functions now only set the options to true for enabling in-memory mode. This, combined with explicit default initialization of in-memory options to false in ChainstateManagerOptions constructor, should remove ambiguity about what happens when these functions are not called.
  2. DrahtBot added the label Validation on Nov 15, 2025
  3. DrahtBot commented at 1:28 pm on November 15, 2025: contributor

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

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33877.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept NACK stickies-v
    Concept ACK yuvicc

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #32427 ((RFC) kernel: Replace leveldb-based BlockTreeDB with flat-file based store by TheCharlatan)

    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.

  4. stringintech marked this as a draft on Nov 15, 2025
  5. kernel: Rename in-memory DB option setters and simplify API
    Remove the int parameter from `btck_chainstate_manager_options_*_in_memory` functions and rename them from "update" to "set". These functions now only set the options to `true` for enabling in-memory mode. This, combined with explicit default initialization to `false`, removes ambiguity about what happens when these functions are not called and makes the typical use case (disk-based storage) require no action from the user.
    3ac69a6192
  6. stringintech force-pushed on Nov 15, 2025
  7. stringintech marked this as ready for review on Nov 15, 2025
  8. DrahtBot added the label CI failed on Nov 15, 2025
  9. DrahtBot commented at 1:47 pm on November 15, 2025: contributor

    🚧 At least one of the CI tasks failed. Task Linux->Windows cross, no tests: https://github.com/bitcoin/bitcoin/actions/runs/19390523535/job/55483324598 LLM reason (✨ experimental): Compile error: missing initializer for member coins_error_cb in ChainstateManagerOptions, with warnings treated as errors.

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  10. DrahtBot removed the label CI failed on Nov 15, 2025
  11. stringintech commented at 4:11 pm on November 15, 2025: contributor

    This occurred to me while refactoring the context and chainstate manager options in the Go wrapper, so I opened this PR to get feedback.

    cc @TheCharlatan @stickies-v

  12. in src/kernel/bitcoinkernel.cpp:468 in 3ac69a6192
    460@@ -461,8 +461,12 @@ struct ChainstateManagerOptions {
    461               .block_tree_db_params = DBParams{
    462                   .path = data_dir / "blocks" / "index",
    463                   .cache_bytes = kernel::CacheSizes{DEFAULT_KERNEL_CACHE}.block_tree_db,
    464+                  .memory_only = false,
    465               }}},
    466-          m_context{context}, m_chainstate_load_options{node::ChainstateLoadOptions{}}
    467+          m_context{context}, m_chainstate_load_options{node::ChainstateLoadOptions{
    468+              .coins_db_in_memory = false,
    469+              .coins_error_cb = {},
    


    yuvicc commented at 6:26 am on November 16, 2025:
    I think these options are set by default?

    stringintech commented at 10:54 am on November 16, 2025:
    Yes they are. No strong opinion, but it might be better to also explicitly set the default values here (in the kernel code - ChainstateManagerOptions ctor) for options we have setters for. Looks more intentional and readable to me this way. But coins_error_cb = {} is to make the compiler happy.
  13. yuvicc commented at 6:27 am on November 16, 2025: contributor

    Concept ACK

    Makes sense to refractor update to set and remove the int parameter here.

  14. stickies-v commented at 11:50 am on November 17, 2025: contributor

    Hmm, I think I’m ~0 on this, leaning towards Concept NACK. Removing unnecessary parameters is good, but I personally find an interface more ergonomic when you can call object.set_bool(value) instead of if (value) object.set_bool(). It generalizes better, and makes using the object more flexible. For example, if value depends on multiple factors, with the last one taking priority, the value can be updated multiple times with object.set_bool(value) without needing extra state.

    In the case of test_kernel.cpp, I personally would have just written it as:

     0diff --git a/src/test/kernel/test_kernel.cpp b/src/test/kernel/test_kernel.cpp
     1index df0c8ca1b5..3ebec5b59b 100644
     2--- a/src/test/kernel/test_kernel.cpp
     3+++ b/src/test/kernel/test_kernel.cpp
     4@@ -653,12 +653,8 @@ std::unique_ptr<ChainMan> create_chainman(TestDirectory& test_directory,
     5     if (wipe_chainstate) {
     6         chainman_opts.SetWipeDbs(/*wipe_block_tree=*/false, /*wipe_chainstate=*/wipe_chainstate);
     7     }
     8-    if (block_tree_db_in_memory) {
     9-        chainman_opts.SetBlockTreeDbInMemory();
    10-    }
    11-    if (chainstate_db_in_memory) {
    12-        chainman_opts.SetChainstateDbInMemory();
    13-    }
    14+    chainman_opts.UpdateBlockTreeDbInMemory(block_tree_db_in_memory);
    15+    chainman_opts.UpdateChainstateDbInMemory(chainstate_db_in_memory);
    16 
    17     auto chainman{std::make_unique<ChainMan>(context, chainman_opts)};
    18     return chainman;
    

    Do you have an example of how this makes things better for you?

  15. stringintech commented at 12:41 pm on November 17, 2025: contributor
    Good point! I understand your rationale, but wouldn’t the cases you’re describing be mostly for debugging/testing purposes? It seems to me that for typical use cases, we would know whether to enable in-memory mode at compile time, not something that is derived dynamically, so it feels more natural/clear to simply call a function that does that with no input parameter. Also, having an update(bool_value) function might indicate that we’re supporting some meaningful toggleable functionality, while in reality once we construct the chainman, changing these options has no effect.
  16. stickies-v commented at 1:07 pm on November 17, 2025: contributor

    wouldn’t the cases you’re describing be mostly for debugging/testing purposes … we would know whether to enable in-memory mode at compile time

    I don’t know? I wouldn’t find it unreasonable to use kernel for ephemeral in-memory operations.

    Also, having an update(bool_value) function might indicate that we’re supporting some meaningful toggleable functionality, while in reality once we construct the chainman, changing these options has no effect.

    The same issue exist with either approach, I don’t think there’s a meaningful difference there?

  17. stringintech commented at 1:46 pm on November 17, 2025: contributor

    I don’t know? I wouldn’t find it unreasonable to use kernel for ephemeral in-memory operations.

    Of course. I meant that maybe the case where we would “dynamically” decide to use in-memory mode wouldn’t be that common.

    I found the approach in this PR to be a slight improvement for the common use cases, making it a bit more straightforward. But I understand if you find the dynamic use cases more common than I do. Thanks for the feedback!

  18. TheCharlatan commented at 10:33 am on November 26, 2025: contributor
    I tend to agree with stickies-v here. I think when it comes to setting up these options structs we should support dynamic settings. In my view that is the point of them. You get this “toggle” behaviour through the options structs, but not when passing arguments when creating the actual underlying object.
  19. stringintech commented at 10:55 am on November 26, 2025: contributor

    Fair points! Thank you for the feedback.

    Closing as this is not as helpful as I initially thought.

  20. stringintech closed this on Nov 26, 2025


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: 2025-11-30 00:13 UTC

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