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
.
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
.
Concept ACK!
Also wanted to note that in one of my branches for libbitcoinkernel
I give ChainstateManager
a CChainParams
as well, so it definitely makes sense!
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
Reviewers, this pull request conflicts with the following ones:
ChainstateManager::m_adjusted_time_callback
by dongcarl)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.
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;
m_versionbitscache
is marked mutable
?
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 ChainstateManager
and 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-const ChainstateManager
.
ie, I’m treating const ChainstateManager
as being “logically” constant, not bitwise constant.
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+
m_chainparams
member
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() */
(CChainState::)m_params
by CChainState
member functions should instead be references to m_chainman.GetParams()
?
GetParams()
and GetConsensus()
to CChainState
that just call m_chainman.GetParams()
or m_chainman.GetConsensus()
.
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
nit: I’m not sure that this change is 100% necessary. The change seems to trade one reference for another, and since ChainstateManager
is 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!
It needs to call DeploymentActive(.., SEGWIT)
, and that’s something that the ChainstateManager
is responsible for being able to answer. At least that was my logic.
Note that it’s a const
member function, so it’s not doing anything to change the chain state, if that counts as reducing the scope?
1893@@ -1894,10 +1894,11 @@ void StopScriptCheckWorkerThreads()
1894 class WarningBitsConditionChecker : public AbstractThresholdConditionChecker
1895 {
1896 private:
1897- int bit;
1898+ const ChainstateManager& m_chainman;
const VersionBitsCache&
here?
WarningBitsConditionChecker
is only briefly instantiated while it’s being checked.
Medium Code-Review ACK 555eb9344ca83f772fa810570e1aa07881d33a41
💥 🔫 Another mutable global bites the dust!
Are 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
Are 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.
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(); }
m_params
and m_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.
14@@ -15,6 +15,7 @@
15 #include <chain.h>
16 #include <chainparams.h>
17 #include <consensus/amount.h>
18+#include <consensus/params.h>
#include <chainparams.h>
in the previous commit already brings consensus/params.h
in so the fwd declaration isn’t saving anything. Later, DeploymentActive*
use info from consensus/params.h
too.
I think for passing references or pointers, a fwd-decl is enough.
iwyu seems to agree:
0validation.h should remove these lines:
1- #include <config/bitcoin-config.h> // lines 10-10
2- #include <consensus/params.h> // lines 18-18
3- #include <stdint.h> // lines 39-39
4- #include <util/hasher.h> // lines 30-30
5- class CBlockTreeDB; // lines 46-46
6- class CTxMemPool; // lines 47-47
7- struct AssumeutxoData; // lines 53-53
8- struct ChainTxData; // lines 49-49
9- struct DisconnectedBlockTransactions; // lines 50-50
10- 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)
Ah, iwyu treats the DeploymentActive
stuff 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.
ACK d490648b2591f523a096f926e3f29e34d72da55a
Since last review @ 555eb9344ca83f772fa810570e1aa07881d33a41
Rebased past #24538
EDIT: also tweaked validation.h to not directly include consensus/params.h as per #24595 (review)
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;
5c67e84d37d452e9186a6357e5405fabeff241c7 nit: .m_chainman.GetParams()
Seems odd to add a TODO and violate it in the same commit ( /* TODO: replace with m_chainman.GetParams() */)
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);
VersionBitsCache& vbcache{g_versionbitscache};
in this commit already.
review ACK bb5c24b120a3ac7df367a1c5d9b075ca564efb5f 📙
Signature:
0-----BEGIN PGP SIGNED MESSAGE-----
1Hash: SHA512
2
3review ACK bb5c24b120a3ac7df367a1c5d9b075ca564efb5f 📙
4-----BEGIN PGP SIGNATURE-----
5
6iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
7pUi6+Qv8Dw67I3SBVnRjV/M10aNNkHAduz39CLI+zz2TwT/0IyAbgOEB9QAwzWS1
8RFEQdpklN4Vxu+4qwkpEUWtl0cpJV8buVab33eUgDI1WuN/jo8nzF0GWpFwkHUJp
94VEYDP+9zWssKUGgtsV0LPadXFsk74f9KW0q1FN+UljnEBBksPtRfGok1TQSzesH
10m0JlsdZcOBMFjNA+k7cQ3xyZi4b7tERRe8NZ1dewvHMBGpeh5J/n/TwHVO/4NO4Z
11S7qAENfXCP8PWblW5LgvUSlxpyKbwma5ygHe7M1/RnmzMQO1BRkcq0x78ktyxWwU
12Nq1hh4/ETvJgy3j3FIIm2AZeRRo+I1HhhJ1DuqKsqs3KNsM/+jToHrkel7Qi4WtT
13nzyK66L2Tb/MKGsXq2lyU9UC2U4REW3FTi0btmEnRl35RCUyhWbNppl2eZDaheHk
14NKnJV/wgZvgJUVra4Gt6pverD2dPL9/PA6V/M27tF1R9/buUMeEyQYVcBPBw5zSB
15ySIzD/fI
16=er/p
17-----END PGP SIGNATURE-----
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
ajtowns
dongcarl
DrahtBot
MarcoFalke
Labels
Refactoring