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.
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-
stringintech commented at 1:28 PM on November 15, 2025: contributor
- DrahtBot added the label Validation on Nov 15, 2025
-
DrahtBot commented at 1:28 PM on November 15, 2025: contributor
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--006a51241073e994b41acfe9ec718e94-->
Code Coverage & Benchmarks
For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/33877.
<!--021abf342d371248e50ceaed478a90ca-->
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 <code><!--meta-tag:bot-skip--></code> into the comment that the bot should ignore.
<!--174a7506f384e20aa4161008e828411d-->
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.
<!--5faf32d7da4f0f540f40219e4f7537a3-->
- stringintech marked this as a draft on Nov 15, 2025
-
3ac69a6192
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.
- stringintech force-pushed on Nov 15, 2025
- stringintech marked this as ready for review on Nov 15, 2025
- DrahtBot added the label CI failed on Nov 15, 2025
-
DrahtBot commented at 1:47 PM on November 15, 2025: contributor
<!--85328a0da195eb286784d51f73fa0af9-->
🚧 At least one of the CI tasks failed. <sub>Task
Linux->Windows cross, no tests: https://github.com/bitcoin/bitcoin/actions/runs/19390523535/job/55483324598</sub> <sub>LLM reason (✨ experimental): Compile error: missing initializer for member coins_error_cb in ChainstateManagerOptions, with warnings treated as errors.</sub><details><summary>Hints</summary>
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.
</details>
- DrahtBot removed the label CI failed on Nov 15, 2025
-
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.
-
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 -
ChainstateManagerOptionsctor) for options we have setters for. Looks more intentional and readable to me this way. Butcoins_error_cb = {}is to make the compiler happy.yuvicc commented at 6:27 AM on November 16, 2025: contributorConcept ACK
Makes sense to refractor update to set and remove the int parameter here.
stickies-v commented at 11:50 AM on November 17, 2025: contributorHmm, 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 ofif (value) object.set_bool(). It generalizes better, and makes using the object more flexible. For example, ifvaluedepends on multiple factors, with the last one taking priority, the value can be updated multiple times withobject.set_bool(value)without needing extra state.In the case of
test_kernel.cpp, I personally would have just written it as:<details> <summary>git diff on 3ac69a6192</summary>
diff --git a/src/test/kernel/test_kernel.cpp b/src/test/kernel/test_kernel.cpp index df0c8ca1b5..3ebec5b59b 100644 --- a/src/test/kernel/test_kernel.cpp +++ b/src/test/kernel/test_kernel.cpp @@ -653,12 +653,8 @@ std::unique_ptr<ChainMan> create_chainman(TestDirectory& test_directory, if (wipe_chainstate) { chainman_opts.SetWipeDbs(/*wipe_block_tree=*/false, /*wipe_chainstate=*/wipe_chainstate); } - if (block_tree_db_in_memory) { - chainman_opts.SetBlockTreeDbInMemory(); - } - if (chainstate_db_in_memory) { - chainman_opts.SetChainstateDbInMemory(); - } + chainman_opts.UpdateBlockTreeDbInMemory(block_tree_db_in_memory); + chainman_opts.UpdateChainstateDbInMemory(chainstate_db_in_memory); auto chainman{std::make_unique<ChainMan>(context, chainman_opts)}; return chainman;</details>
Do you have an example of how this makes things better for you?
stringintech commented at 12:41 PM on November 17, 2025: contributorGood 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.stickies-v commented at 1:07 PM on November 17, 2025: contributorwouldn'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?
stringintech commented at 1:46 PM on November 17, 2025: contributorI 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!
TheCharlatan commented at 10:33 AM on November 26, 2025: contributorI 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.
stringintech commented at 10:55 AM on November 26, 2025: contributorFair points! Thank you for the feedback.
Closing as this is not as helpful as I initially thought.
stringintech closed this on Nov 26, 2025ContributorsLabels
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-04-30 21:12 UTC
More mirrored repositories can be found on mirror.b10c.me