From 4a69b4dbe0d7f504811b67c399da7e6d11e4f805 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 16 Apr 2021 18:33:02 +1000 Subject: [move-only] Move ComputeBlockVersion from validation to versionbits --- src/versionbits.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/versionbits.cpp') diff --git a/src/versionbits.cpp b/src/versionbits.cpp index 0fbad0a64e..3497fc049e 100644 --- a/src/versionbits.cpp +++ b/src/versionbits.cpp @@ -212,6 +212,22 @@ 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 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(i)); + if (state == ThresholdState::LOCKED_IN || state == ThresholdState::STARTED) { + nVersion |= g_versionbitscache.Mask(params, static_cast(i)); + } + } + + return nVersion; +} + void VersionBitsCache::Clear() { LOCK(m_mutex); -- cgit v1.2.3