Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
251case ACTIVE:252result.active.try_emplace(vbdepinfo.name, gbtinfo);253break;254}255}256return result;257}259bool VersionBitsCache::IsActiveAfter(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)260{261LOCK(m_mutex);262return ThresholdState::ACTIVE == VersionBitsConditionChecker(params, pos).GetStateFor(pindexPrev, m_caches[pos]);263}265static int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params, std::array<ThresholdConditionCache, Consensus::MAX_VERSION_BITS_DEPLOYMENTS>& caches)266{267int32_t nVersion = VERSIONBITS_TOP_BITS;269for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) {270Consensus::DeploymentPos pos = static_cast<Consensus::DeploymentPos>(i);271VersionBitsConditionChecker checker(params, pos);272ThresholdState state = checker.GetStateFor(pindexPrev, caches[pos]);273if (state == ThresholdState::LOCKED_IN || state == ThresholdState::STARTED) {274nVersion |= checker.Mask();275}276}278return nVersion;279}281int32_t VersionBitsCache::ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params)282{283LOCK(m_mutex);284return ::ComputeBlockVersion(pindexPrev, params, m_caches);285}287void VersionBitsCache::Clear()288{289LOCK(m_mutex);290for (unsigned int d = 0; d < Consensus::MAX_VERSION_BITS_DEPLOYMENTS; d++) {291m_caches[d].clear();292}293}295namespace {296/**297* Threshold condition checker that triggers when unknown versionbits are seen on the network.298*/299class WarningBitsConditionChecker : public AbstractThresholdConditionChecker300{301private:302const Consensus::Params& m_params;303std::array<ThresholdConditionCache, Consensus::MAX_VERSION_BITS_DEPLOYMENTS>& m_caches;304int m_bit;305int period{2016};306int threshold{1815}; // 90% threshold used in BIP 341308public:309explicit WarningBitsConditionChecker(const CChainParams& chainparams, std::array<ThresholdConditionCache, Consensus::MAX_VERSION_BITS_DEPLOYMENTS>& caches, int bit)310: m_params{chainparams.GetConsensus()}, m_caches{caches}, m_bit(bit)311{312if (chainparams.IsTestChain()) {313period = chainparams.GetConsensus().DifficultyAdjustmentInterval();314threshold = period * 3 / 4; // 75% for test nets per BIP9 suggestion315}316}318int64_t BeginTime() const override { return 0; }319int64_t EndTime() const override { return std::numeric_limits<int64_t>::max(); }320int Period() const override { return period; }321int Threshold() const override { return threshold; }323bool Condition(const CBlockIndex* pindex) const override324{325return pindex->nHeight >= m_params.MinBIP9WarningHeight &&326((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) &&327((pindex->nVersion >> m_bit) & 1) != 0 &&328((::ComputeBlockVersion(pindex->pprev, m_params, m_caches) >> m_bit) & 1) == 0;329}330};331} // anonymous namespace333std::vector<std::pair<int, bool>> VersionBitsCache::CheckUnknownActivations(const CBlockIndex* pindex, const CChainParams& chainparams)334{335LOCK(m_mutex);336std::vector<std::pair<int, bool>> result;337for (int bit = 0; bit < VERSIONBITS_NUM_BITS; ++bit) {338WarningBitsConditionChecker checker(chainparams, m_caches, bit);339ThresholdState state = checker.GetStateFor(pindex, m_warning_caches.at(bit));340if (state == ACTIVE || state == LOCKED_IN) {341result.emplace_back(bit, state == ACTIVE);342}343}344return result;345}
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.