diff options
-rw-r--r-- | src/miner.cpp | 2 | ||||
-rw-r--r-- | src/test/versionbits_tests.cpp | 5 | ||||
-rw-r--r-- | src/validation.cpp | 2 | ||||
-rw-r--r-- | src/versionbits.cpp | 10 | ||||
-rw-r--r-- | src/versionbits.h | 9 |
5 files changed, 16 insertions, 12 deletions
diff --git a/src/miner.cpp b/src/miner.cpp index c1a992b9e9..d9186a5d6d 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -121,7 +121,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc assert(pindexPrev != nullptr); nHeight = pindexPrev->nHeight + 1; - pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); + pblock->nVersion = g_versionbitscache.ComputeBlockVersion(pindexPrev, chainparams.GetConsensus()); // -regtest only: allow overriding block.nVersion with // -blockversion=N to test forking scenarios if (chainparams.MineBlocksOnDemand()) diff --git a/src/test/versionbits_tests.cpp b/src/test/versionbits_tests.cpp index 946b35f3b9..60a8373cf4 100644 --- a/src/test/versionbits_tests.cpp +++ b/src/test/versionbits_tests.cpp @@ -15,6 +15,11 @@ /* Define a virtual block time, one block per 10 minutes after Nov 14 2014, 0:55:36am */ static int32_t TestTime(int nHeight) { return 1415926536 + 600 * nHeight; } +static int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params) +{ + return g_versionbitscache.ComputeBlockVersion(pindexPrev, params); +} + static const std::string StateName(ThresholdState state) { switch (state) { diff --git a/src/validation.cpp b/src/validation.cpp index ee10e047bd..65d2dfa3b7 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1627,7 +1627,7 @@ public: return pindex->nHeight >= params.MinBIP9WarningHeight && ((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) && ((pindex->nVersion >> bit) & 1) != 0 && - ((ComputeBlockVersion(pindex->pprev, params) >> bit) & 1) == 0; + ((g_versionbitscache.ComputeBlockVersion(pindex->pprev, params) >> bit) & 1) == 0; } }; diff --git a/src/versionbits.cpp b/src/versionbits.cpp index 3497fc049e..94c3c9559f 100644 --- a/src/versionbits.cpp +++ b/src/versionbits.cpp @@ -212,16 +212,16 @@ uint32_t VersionBitsCache::Mask(const Consensus::Params& params, Consensus::Depl return VersionBitsConditionChecker(pos).Mask(params); } -extern VersionBitsCache g_versionbitscache; // removed in next commit - -int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params) +int32_t VersionBitsCache::ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params) { + LOCK(m_mutex); int32_t nVersion = VERSIONBITS_TOP_BITS; for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) { - ThresholdState state = g_versionbitscache.State(pindexPrev, params, static_cast<Consensus::DeploymentPos>(i)); + Consensus::DeploymentPos pos = static_cast<Consensus::DeploymentPos>(i); + ThresholdState state = VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params, m_caches[pos]); if (state == ThresholdState::LOCKED_IN || state == ThresholdState::STARTED) { - nVersion |= g_versionbitscache.Mask(params, static_cast<Consensus::DeploymentPos>(i)); + nVersion |= Mask(params, pos); } } diff --git a/src/versionbits.h b/src/versionbits.h index c18a8d1176..0b2f4a0258 100644 --- a/src/versionbits.h +++ b/src/versionbits.h @@ -93,12 +93,11 @@ public: /** Get the block height at which the BIP9 deployment switched into the state for the block after pindexPrev. */ int StateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos); + /** Determine what nVersion a new block should use + */ + int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params); + void Clear(); }; -/** - * Determine what nVersion a new block should use. - */ -int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params); - #endif // BITCOIN_VERSIONBITS_H |