Gives ChainstateManager a reference to the CChainParams its working on, and simplifies some of the functions that would otherwise take that as a parameter. Removes the g_versionbitscache global by moving it into ChainstateManager.
deploymentstatus: move g_versionbitscache global to ChainstateManager #24595
pull ajtowns wants to merge 9 commits into bitcoin:master from ajtowns:202202-cchainparams-chainstatemanager changing 18 files +200 −170-
ajtowns commented at 2:08 AM on March 17, 2022: member
-
dongcarl commented at 2:53 AM on March 17, 2022: member
Concept ACK!
Also wanted to note that in one of my branches for
libbitcoinkernelI giveChainstateManageraCChainParamsas well, so it definitely makes sense! - DrahtBot added the label Block storage on Mar 17, 2022
- DrahtBot added the label Mining on Mar 17, 2022
- DrahtBot added the label P2P on Mar 17, 2022
- DrahtBot added the label RPC/REST/ZMQ on Mar 17, 2022
- DrahtBot added the label Utils/log/libs on Mar 17, 2022
- DrahtBot added the label UTXO Db and Indexes on Mar 17, 2022
- DrahtBot added the label Validation on Mar 17, 2022
- ajtowns force-pushed on Mar 17, 2022
- DrahtBot added the label Needs rebase on Mar 17, 2022
- ajtowns force-pushed on Mar 17, 2022
- ajtowns renamed this:
WIP remove g_versionbitscache global
WIP: deploymentstatus: move g_versionbitscache global to ChainstateManager
on Mar 17, 2022 - DrahtBot removed the label Needs rebase on Mar 17, 2022
-
DrahtBot commented at 1:20 PM on March 19, 2022: member
<!--e57a25ab6845829454e8d69fc972939a-->
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
<!--174a7506f384e20aa4161008e828411d-->
Conflicts
Reviewers, this pull request conflicts with the following ones:
- #25073 (test: Cleanup miner_tests by MarcoFalke)
- #25064 ([kernel 2b/n] Add
ChainstateManager::m_adjusted_time_callbackby dongcarl) - #24737 (Remove taproot chain param by MarcoFalke)
- #24571 (p2p: Prevent block index fingerprinting by sending additional getheaders messages by dergoegge)
- #24565 (Remove LOCKTIME_MEDIAN_TIME_PAST constant by MarcoFalke)
- #24232 (assumeutxo: add init and completion logic by jamesob)
- #24008 (assumeutxo: net_processing changes by jamesob)
- #20799 (net processing: Only support version 2 compact blocks by jnewbery)
- #18933 (rpc: Add submit option to generateblock by MarcoFalke)
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.
- ajtowns force-pushed on Mar 25, 2022
- ajtowns renamed this:
WIP: deploymentstatus: move g_versionbitscache global to ChainstateManager
deploymentstatus: move g_versionbitscache global to ChainstateManager
on Mar 25, 2022 - ajtowns marked this as ready for review on Mar 25, 2022
-
ajtowns commented at 2:59 PM on March 25, 2022: member
Should be ready for review now
- ajtowns force-pushed on Apr 4, 2022
- DrahtBot added the label Needs rebase on Apr 4, 2022
- ajtowns force-pushed on Apr 4, 2022
- DrahtBot removed the label Needs rebase on Apr 4, 2022
- ajtowns force-pushed on Apr 5, 2022
- ajtowns force-pushed on Apr 7, 2022
- ajtowns force-pushed on Apr 14, 2022
- ajtowns force-pushed on Apr 14, 2022
-
in src/validation.h:944 in 555eb9344c outdated
935 | @@ -935,6 +936,11 @@ class ChainstateManager 936 | return m_blockman.m_block_index; 937 | } 938 | 939 | + /** 940 | + * Track versionbit status 941 | + */ 942 | + mutable VersionBitsCache m_versionbitscache;
dongcarl commented at 6:29 PM on April 18, 2022:Could you explain a bit why
m_versionbitscacheis markedmutable?
ajtowns commented at 10:40 PM on April 18, 2022:It's a cache, so its existence doesn't impact the logical API of the class -- if we didn't use a cache, you could have a
const ChainstateManagerand get answers as to whether a deployment is active/enabled and what version to use for new blocks; so adding a cache shouldn't mean that you can only do that with a non-constChainstateManager.ie, I'm treating
const ChainstateManageras being "logically" constant, not bitwise constant.
dongcarl commented at 6:47 PM on April 19, 2022:Sounds good!
in src/validation.h:860 in 16f51f5cc2 outdated
857 | public: 858 | explicit ChainstateManager(const CChainParams& chainparams) : m_chainparams{chainparams} { } 859 | 860 | + const CChainParams& GetParams() const { return m_chainparams; } 861 | + const Consensus::Params& GetConsensus() const { return m_chainparams.GetConsensus(); } 862 | +
dongcarl commented at 6:37 PM on April 18, 2022:Perhaps these additions could be made in the previous commit where we introduce the private
m_chainparamsmemberin src/validation.h:497 in 9fccb380e1 outdated
494 | @@ -495,6 +495,7 @@ class CChainState 495 | node::BlockManager& m_blockman; 496 | 497 | /** Chain parameters for this chainstate */ 498 | + /* TODO: replace with m_chainman.GetParams() */
dongcarl commented at 6:39 PM on April 18, 2022:By this, do you mean all references to
(CChainState::)m_paramsbyCChainStatemember functions should instead be references tom_chainman.GetParams()?
ajtowns commented at 10:41 PM on April 18, 2022:Yeah. Or perhaps add a
GetParams()andGetConsensus()toCChainStatethat just callm_chainman.GetParams()orm_chainman.GetConsensus().
ajtowns commented at 5:53 AM on April 19, 2022:(I didn't start on this here since I imagine it would have a bunch of conflicts with other PRs)
dongcarl commented at 6:47 PM on April 19, 2022:Sounds good!
in src/validation.cpp:3402 in e49e7cca6e outdated
3360 | @@ -3361,19 +3361,19 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu 3361 | return true; 3362 | } 3363 | 3364 | -void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams) 3365 | +void ChainstateManager::UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev) const
dongcarl commented at 6:44 PM on April 18, 2022:nit: I'm not sure that this change is 100% necessary. The change seems to trade one reference for another, and since
ChainstateManageris much larger in scope, it is harder to see after the change that this is a function that is limited in scope.However, this is not at all a bit deal and up to subjective taste so feel free to ignore!
ajtowns commented at 10:48 PM on April 18, 2022:It needs to call
DeploymentActive(.., SEGWIT), and that's something that theChainstateManageris responsible for being able to answer. At least that was my logic.Note that it's a
constmember function, so it's not doing anything to change the chain state, if that counts as reducing the scope?
dongcarl commented at 6:48 PM on April 19, 2022:Sounds good!
in src/validation.cpp:1910 in 555eb9344c outdated
1893 | @@ -1894,10 +1894,11 @@ void StopScriptCheckWorkerThreads() 1894 | class WarningBitsConditionChecker : public AbstractThresholdConditionChecker 1895 | { 1896 | private: 1897 | - int bit; 1898 | + const ChainstateManager& m_chainman;
dongcarl commented at 6:49 PM on April 18, 2022:Perhaps we can use a
const VersionBitsCache&here?
ajtowns commented at 10:51 PM on April 18, 2022:Could, but it should all get optimised away since
WarningBitsConditionCheckeris only briefly instantiated while it's being checked.
dongcarl commented at 6:49 PM on April 19, 2022:Sure!
dongcarl commented at 6:51 PM on April 18, 2022: memberMedium Code-Review ACK 555eb9344ca83f772fa810570e1aa07881d33a41
💥 🔫 Another mutable global bites the dust!
ajtowns force-pushed on Apr 18, 2022DrahtBot added the label Needs rebase on Apr 20, 2022ajtowns force-pushed on Apr 20, 2022DrahtBot removed the label Needs rebase on Apr 20, 2022MarcoFalke commented at 6:48 AM on April 25, 2022: memberAre you sure this is ready for review? Looks like it is based on #22564 for now, which might change its commits. So maybe leave it in draft until #22564 is merged? (Reviewers can still ACK your commits here, but I don't think it can be merged before #22564).
Also, I am wondering what to do with #24917. Should that go before/after #22564 or should it be included there? cc @dongcarl @ajtowns
ajtowns commented at 8:28 AM on April 25, 2022: memberAre you sure this is ready for review? Looks like it is based on #22564 for now,
Yeah, there's a trivial conflict between #22564 and these patches in that they both change the call to
g_versionbitscache.Clear(); seemed more sensible to review the changes in #22564 first, so I rebased the changes here on top of that.Also, I am wondering what to do with #24917. Should that go before/after #22564 or should it be included there?
Seems fine to keep it separate, and 22564 seems higher priority and not blocked on anything; so I'd say 22564 first and keep 24917 separate.
DrahtBot added the label Needs rebase on Apr 26, 2022ajtowns force-pushed on Apr 27, 2022DrahtBot removed the label Needs rebase on Apr 27, 2022ajtowns force-pushed on Apr 28, 2022DrahtBot added the label Needs rebase on Apr 28, 2022ajtowns force-pushed on Apr 29, 2022DrahtBot removed the label Needs rebase on Apr 29, 2022in src/validation.h:859 in 4cbc4e94b7 outdated
853 | @@ -851,6 +854,11 @@ class ChainstateManager 854 | friend CChainState; 855 | 856 | public: 857 | + explicit ChainstateManager(const CChainParams& chainparams) : m_chainparams{chainparams} { } 858 | + 859 | + const CChainParams& GetParams() const { return m_chainparams; } 860 | + const Consensus::Params& GetConsensus() const { return m_chainparams.GetConsensus(); }
MarcoFalke commented at 2:46 PM on April 29, 2022:4cbc4e94b764ba2b4a79610fadbb092a7bdd076e: What about a public
m_paramsandm_consensus? There shouldn't be any risk associated with read-only references. And a public member removes the need for a function wrapper that only returns the member.
ajtowns commented at 4:13 PM on April 29, 2022:6 to one, half a dozen the other? I thought accessors were more common than extra variables, and make it a bit clearer that they can't get out of sync? shrug
in src/validation.h:18 in 0fc617a406 outdated
14 | @@ -15,6 +15,7 @@ 15 | #include <chain.h> 16 | #include <chainparams.h> 17 | #include <consensus/amount.h> 18 | +#include <consensus/params.h>
MarcoFalke commented at 2:48 PM on April 29, 2022:0fc617a406232e21bdc8b39b2f8308f965775825 Any reason to add this include when the existing fwd-decl is enough?
ajtowns commented at 4:20 PM on April 29, 2022:Adding
#include <chainparams.h>in the previous commit already bringsconsensus/params.hin so the fwd declaration isn't saving anything. Later,DeploymentActive*use info fromconsensus/params.htoo.
MarcoFalke commented at 8:23 AM on May 3, 2022:I think for passing references or pointers, a fwd-decl is enough.
iwyu seems to agree:
validation.h should remove these lines: - #include <config/bitcoin-config.h> // lines 10-10 - #include <consensus/params.h> // lines 18-18 - #include <stdint.h> // lines 39-39 - #include <util/hasher.h> // lines 30-30 - class CBlockTreeDB; // lines 46-46 - class CTxMemPool; // lines 47-47 - struct AssumeutxoData; // lines 53-53 - struct ChainTxData; // lines 49-49 - struct DisconnectedBlockTransactions; // lines 50-50 - struct LockPoints; // lines 52-52(Not saying you should fix all includes in this pull here, but I think not making it worse is a good compromise)
ajtowns commented at 2:11 PM on May 3, 2022:Ah, iwyu treats the
DeploymentActivestuff as recommending that deploymentstatus.h add the#include <consensus/params.h>not validation.h. I've got some later commits that move those functions into validation.h which updates iwyu's recommendations to a #include.Since it's already included indirectly by chainparams.h I don't really see the include as making it worse, but it's not really better either, so will change it back if there are other fixes to bundle it with.
ajtowns commented at 2:13 AM on May 10, 2022:Done now
MarcoFalke approvedMarcoFalke commented at 2:56 PM on April 29, 2022: memberACK
MarcoFalke removed the label UTXO Db and Indexes on Apr 29, 2022MarcoFalke removed the label RPC/REST/ZMQ on Apr 29, 2022MarcoFalke removed the label P2P on Apr 29, 2022MarcoFalke removed the label Mining on Apr 29, 2022MarcoFalke removed the label Validation on Apr 29, 2022MarcoFalke removed the label Block storage on Apr 29, 2022MarcoFalke removed the label Utils/log/libs on Apr 29, 2022MarcoFalke added the label Refactoring on Apr 29, 2022dongcarl commented at 7:13 PM on May 2, 2022: memberACK d490648b2591f523a096f926e3f29e34d72da55a
Since last review @ 555eb9344ca83f772fa810570e1aa07881d33a41
- Rebased over merge of #22564
- Addressed #24595 (review)
DrahtBot added the label Needs rebase on May 6, 2022ajtowns force-pushed on May 9, 2022DrahtBot removed the label Needs rebase on May 9, 2022ajtowns commented at 8:42 PM on May 9, 2022: memberRebased past #24538
EDIT: also tweaked validation.h to not directly include consensus/params.h as per #24595 (review)
validation: add CChainParams to ChainstateManager 69675ea4e7validation: remove redundant CChainParams params from ChainstateManager methods 38860f93b6validation: replace ::Params() calls with chainstate/chainman member 5c67e84d37validation: move UpdateUncommittedBlockStructures and GenerateCoinbaseCommitment into ChainstateManager eaa2e3f25cdeploymentstatus: allow chainman in place of consensusParams deffe0df6crefactor: use chainman instead of chainParams for DeploymentActive* 78adef1753deploymentstatus: make versionbitscache a parameter d603f1d8a7test/versionbits: make versionbitscache a parameter eca22c726avalidation: move g_versionbitscache into ChainstateManager bb5c24b120ajtowns force-pushed on May 10, 2022dongcarl commented at 8:11 PM on May 12, 2022: memberreACK bb5c24b120a3ac7df367a1c5d9b075ca564efb5f
in src/validation.cpp:1460 in 5c67e84d37 outdated
1456 | @@ -1457,7 +1457,7 @@ PackageMempoolAcceptResult ProcessNewPackage(CChainState& active_chainstate, CTx 1457 | assert(std::all_of(package.cbegin(), package.cend(), [](const auto& tx){return tx != nullptr;})); 1458 | 1459 | std::vector<COutPoint> coins_to_uncache; 1460 | - const CChainParams& chainparams = Params(); 1461 | + const CChainParams& chainparams = active_chainstate.m_params;
MarcoFalke commented at 6:55 AM on May 13, 2022:5c67e84d37d452e9186a6357e5405fabeff241c7 nit:
.m_chainman.GetParams()Seems odd to add a TODO and violate it in the same commit ( /* TODO: replace with m_chainman.GetParams() */)
in src/test/versionbits_tests.cpp:432 in eca22c726a outdated
428 | @@ -429,7 +429,7 @@ BOOST_AUTO_TEST_CASE(versionbits_computeblockversion) 429 | const uint32_t dep_mask{g_versionbitscache.Mask(chainParams->GetConsensus(), dep)}; 430 | BOOST_CHECK(!(chain_all_vbits & dep_mask)); 431 | chain_all_vbits |= dep_mask; 432 | - check_computeblockversion(chainParams->GetConsensus(), dep); 433 | + check_computeblockversion(g_versionbitscache, chainParams->GetConsensus(), dep);
MarcoFalke commented at 6:58 AM on May 13, 2022:eca22c726ac48b4216bb68cc0f0bbd655c43ac12 nit: Later diff could be smaller by a few lines if you added a
VersionBitsCache& vbcache{g_versionbitscache};in this commit already.MarcoFalke approvedMarcoFalke commented at 6:59 AM on May 13, 2022: memberreview ACK bb5c24b120a3ac7df367a1c5d9b075ca564efb5f 📙
<details><summary>Show signature</summary>
Signature:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 review ACK bb5c24b120a3ac7df367a1c5d9b075ca564efb5f 📙 -----BEGIN PGP SIGNATURE----- iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p pUi6+Qv8Dw67I3SBVnRjV/M10aNNkHAduz39CLI+zz2TwT/0IyAbgOEB9QAwzWS1 RFEQdpklN4Vxu+4qwkpEUWtl0cpJV8buVab33eUgDI1WuN/jo8nzF0GWpFwkHUJp 4VEYDP+9zWssKUGgtsV0LPadXFsk74f9KW0q1FN+UljnEBBksPtRfGok1TQSzesH m0JlsdZcOBMFjNA+k7cQ3xyZi4b7tERRe8NZ1dewvHMBGpeh5J/n/TwHVO/4NO4Z S7qAENfXCP8PWblW5LgvUSlxpyKbwma5ygHe7M1/RnmzMQO1BRkcq0x78ktyxWwU Nq1hh4/ETvJgy3j3FIIm2AZeRRo+I1HhhJ1DuqKsqs3KNsM/+jToHrkel7Qi4WtT nzyK66L2Tb/MKGsXq2lyU9UC2U4REW3FTi0btmEnRl35RCUyhWbNppl2eZDaheHk NKnJV/wgZvgJUVra4Gt6pverD2dPL9/PA6V/M27tF1R9/buUMeEyQYVcBPBw5zSB ySIzD/fI =er/p -----END PGP SIGNATURE-----</details>
MarcoFalke merged this on May 13, 2022MarcoFalke closed this on May 13, 2022sidhujag referenced this in commit 16e302dcf4 on May 13, 2022in src/test/versionbits_tests.cpp:416 in bb5c24b120
416 | + BOOST_CHECK_EQUAL(versionbitscache.ComputeBlockVersion(lastBlock, params) & (1 << bit), 0); 417 | } 418 | 419 | BOOST_AUTO_TEST_CASE(versionbits_computeblockversion) 420 | { 421 | + VersionBitsCache vbcache; // don't use chainman versionbitscache since we want custom chain params
MarcoFalke commented at 12:21 PM on May 16, 2022:Removed chainman completely from this test in https://github.com/bitcoin/bitcoin/pull/25125
aureleoules referenced this in commit 83efe632d7 on Aug 12, 2022aureleoules referenced this in commit 672fdf35b0 on Sep 16, 2022aureleoules referenced this in commit 5d3f98d278 on Oct 10, 2022MarcoFalke referenced this in commit a97791d9fb on Oct 19, 2022adam2k referenced this in commit 993d6f7c40 on Oct 19, 2022satsie referenced this in commit 2484cba86a on Oct 31, 2022DrahtBot locked this on May 16, 2023
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-04-26 09:14 UTC
This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me