The function does not need anything from any chainstate, so it should not sit in the Chainstate class.
refactor: Move LoadGenesisBlock to ChainstateManager #35673
pull maflcko wants to merge 1 commits into bitcoin:master from maflcko:2607-LoadGenesisBlock-mv changing 6 files +17 −16-
maflcko commented at 8:49 AM on July 7, 2026: member
- DrahtBot added the label Refactoring on Jul 7, 2026
-
DrahtBot commented at 8:49 AM on July 7, 2026: 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/35673.
<!--021abf342d371248e50ceaed478a90ca-->
Reviews
See the guideline and AI policy for information on the review process.
Type Reviewers ACK l0rinc, janb84, sedited Stale ACK ismaelsadeeq, stickies-v, 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:
- #30342 (kernel, logging: Pass Logger instances to kernel objects by ryanofsky)
- #26022 (Add util::ResultPtr class by ryanofsky)
- #25722 (refactor: Use util::Result class for wallet loading by ryanofsky)
- #25665 (refactor: Add util::Result failure types and ability to merge result values by ryanofsky)
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-->
-
in src/validation.cpp:4950 in fa202e628f
4947 | +bool ChainstateManager::LoadGenesisBlock() 4948 | { 4949 | LOCK(cs_main); 4950 | 4951 | - const CChainParams& params{m_chainman.GetParams()}; 4952 | + const CBlock& block{GetParams().GenesisBlock()};
sedited commented at 9:43 AM on July 7, 2026:Nit: Maybe rename this to
genesis_blockfor clarity?sedited approvedsedited commented at 9:43 AM on July 7, 2026: contributorNice, ACK fa202e628f47771c0ebfa725038c59cfeaf690d2
I have the same commit lying on my chainman/chainstate split branch: https://github.com/sedited/bitcoin/commit/d8a0306ad8b5b99948ce618d58a3f1081e6ddd5d
ismaelsadeeq approvedismaelsadeeq commented at 9:44 AM on July 7, 2026: memberACK fa202e628f47771c0ebfa725038c59cfeaf690d2
maflcko force-pushed on Jul 7, 2026sedited approvedsedited commented at 12:40 PM on July 7, 2026: contributorACK fa28a7b7a6ec00312ccc55e8b6cf24a918610ef2
DrahtBot requested review from ismaelsadeeq on Jul 7, 2026ismaelsadeeq commented at 12:50 PM on July 7, 2026: memberreACK fa28a7b7a6ec00312ccc55e8b6cf24a918610ef2
Minor rename changes in the last push.
in src/validation.cpp:4953 in fa28a7b7a6
4950 | 4951 | - const CChainParams& params{m_chainman.GetParams()}; 4952 | + const CBlock& genesis_block{GetParams().GenesisBlock()}; 4953 | 4954 | // Check whether we're already initialized by checking for genesis in 4955 | // m_blockman.m_block_index. Note that we can't use m_chain here, since it is
stickies-v commented at 2:23 PM on July 7, 2026:nit:
m_chainis not a member ofChainstateManager, so this comment is stale.// m_blockman.m_block_index. Note that we can't use the chain tip here, since it isin src/validation.h:1087 in fa28a7b7a6
1082 | @@ -1085,6 +1083,9 @@ class ChainstateManager 1083 | //! coins databases. This will be split somehow across chainstates. 1084 | size_t m_total_coinsdb_cache{0}; 1085 | 1086 | + /// Ensures a genesis block is in the block tree, possibly writing one to disk. 1087 | + bool LoadGenesisBlock();
stickies-v commented at 2:27 PM on July 7, 2026:pre-existing: this should probably be
[[nodiscard]], and we have one callsite inImportBlocksthat ignores the return value. It's alreadyLogError'd and there's not much more we can do withImportBlockscurrently returningvoid, but might be worth updating and returning early (or casting tovoid), so future users don't silently ignore errors?
yuvicc commented at 5:07 PM on July 7, 2026:Looks like a behavior change, could be done in a follow-up?
maflcko commented at 5:14 PM on July 7, 2026:Heh, I'd say more important than any logging and bool-return or early-return is probably the calling the fatal error function.
ImportBlocksalready does that correctly, so ignoring the return value seems correct here.Also, added the
[[nodiscard]]here.Also, fixed up the
__func__stuff, while pushing.[Edit: So I'd even be fine with making this function
void(assuming that any fatal error results in an interrupt+shutdown anyway), but this may be too spicy for this pull request here and maybe also not worth the review.]stickies-v approvedstickies-v commented at 2:27 PM on July 7, 2026: contributorACK fa28a7b7a6ec00312ccc55e8b6cf24a918610ef2
janb84 commented at 3:28 PM on July 7, 2026: contributorACK fa28a7b7a6ec00312ccc55e8b6cf24a918610ef2
Nice cleanup.
LoadGenesisBlocknever used any Chainstate member, it is pureChainstateManagerstate.Simple grep confirmed no missed callers.
yuvicc commented at 5:06 PM on July 7, 2026: contributorACK fa28a7b7a6ec00312ccc55e8b6cf24a918610ef2
fa615bd163refactor: Move LoadGenesisBlock to ChainstateManager
The function does not need anything from any chainstate, so it should not sit in the Chainstate class. Also, mark it [[nodiscard]], and the one place that ignores the return value with (void). Also, change the error log strings to not include the __func__, which is redundant with -logsourcelocations. This is not a refactor, but this log is only for debugging extremely rare errors.
maflcko force-pushed on Jul 7, 2026l0rinc commented at 10:00 PM on July 7, 2026: contributorTested ACK fa615bd163ac74c11a8e15ed8513a5b81ed9ef3b
I rebased this locally and generated a few throw-away unit/functional checks to sanity-check the move (covering fresh/already-loaded genesis, failure paths, and startup/reindex/loadblock behavior).
DrahtBot requested review from yuvicc on Jul 7, 2026DrahtBot requested review from sedited on Jul 7, 2026DrahtBot requested review from janb84 on Jul 7, 2026DrahtBot requested review from stickies-v on Jul 7, 2026DrahtBot requested review from ismaelsadeeq on Jul 7, 2026janb84 commented at 7:10 AM on July 8, 2026: contributorreACK fa615bd163ac74c11a8e15ed8513a5b81ed9ef3b
changes since last ACK:
- fixed func in logging
- added [[nodiscard]] attribute to func. to increase safety.
sedited approvedsedited commented at 8:00 AM on July 8, 2026: contributorACK fa615bd163ac74c11a8e15ed8513a5b81ed9ef3b
sedited merged this on Jul 8, 2026sedited closed this on Jul 8, 2026maflcko deleted the branch on Jul 8, 2026stickies-v commented at 7:18 PM on July 8, 2026: contributorpost merge ACK fa615bd163ac74c11a8e15ed8513a5b81ed9ef3b
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-07-09 06:47 UTC