20 case ACTIVE:
return "active";
21 case FAILED:
return "failed";
32 int64_t nTimeTimeout =
EndTime();
45 if (pindexPrev !=
nullptr) {
50 std::vector<const CBlockIndex*> vToCompute;
51 while (!cache.contains(pindexPrev)) {
52 if (pindexPrev ==
nullptr) {
62 vToCompute.push_back(pindexPrev);
67 assert(cache.contains(pindexPrev));
71 while (!vToCompute.empty()) {
73 pindexPrev = vToCompute.back();
74 vToCompute.pop_back();
87 for (
int i = 0; i < nPeriod; i++) {
91 pindexCount = pindexCount->
pprev;
93 if (
count >= nThreshold) {
102 if (pindexPrev->
nHeight + 1 >= min_activation_height) {
113 cache[pindexPrev] = state = stateNext;
126 if (pindex ==
nullptr)
return stats;
132 if (signalling_blocks) {
133 signalling_blocks->assign(blocks_in_period,
false);
145 if (signalling_blocks) signalling_blocks->at(blocks_in_period) =
true;
147 currentIndex = currentIndex->
pprev;
148 }
while(blocks_in_period > 0);
171 const int nPeriod =
Period();
183 while (previousPeriodParent !=
nullptr &&
GetStateFor(previousPeriodParent, cache) == initialState) {
184 pindexPrev = previousPeriodParent;
189 return pindexPrev->
nHeight + 1;
203 next_state = checker.
GetStateFor(&block_index, m_caches[
id]);
210 const bool has_signal = (
STARTED == current_state ||
LOCKED_IN == current_state);
214 result.stats->threshold = 0;
215 result.stats->possible =
false;
219 if (current_state ==
ACTIVE) {
221 }
else if (next_state ==
ACTIVE) {
246 result.signalling.try_emplace(vbdepinfo.
name, gbtinfo);
249 result.locked_in.try_emplace(vbdepinfo.
name, gbtinfo);
252 result.active.try_emplace(vbdepinfo.
name, gbtinfo);
274 nVersion |= checker.
Mask();
303 std::array<ThresholdConditionCache, Consensus::MAX_VERSION_BITS_DEPLOYMENTS>& m_caches;
309 explicit 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)
314 threshold = period * 3 / 4;
318 int64_t
BeginTime()
const override {
return 0; }
319 int64_t
EndTime()
const override {
return std::numeric_limits<int64_t>::max(); }
320 int Period()
const override {
return period; }
321 int Threshold()
const override {
return threshold; }
327 ((pindex->
nVersion >> m_bit) & 1) != 0 &&
336 std::vector<std::pair<int, bool>>
result;
338 WarningBitsConditionChecker checker(chainparams, m_caches, bit);
339 ThresholdState state = checker.GetStateFor(pindex, m_warning_caches.at(bit));
virtual int64_t BeginTime() const =0
Opaque type for BIP9 state.
std::array< BIP9Deployment, MAX_VERSION_BITS_DEPLOYMENTS > vDeployments
bool gbt_optional_rule
Whether GBT clients can safely ignore this rule in simplified usage.
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
CBlockIndex * pprev
pointer to the index of the predecessor of this block
uint32_t threshold
Number of blocks with the version bit set required to activate the softfork.
static const int32_t VERSIONBITS_TOP_MASK
What bitmask determines whether versionbits is in use.
static int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, std::array< ThresholdConditionCache, Consensus::MAX_VERSION_BITS_DEPLOYMENTS > &caches)
virtual bool Condition(const CBlockIndex *pindex) const =0
static constexpr int64_t ALWAYS_ACTIVE
Special value for nStartTime indicating that the deployment is always active.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
void Clear() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
ThresholdState GetStateFor(const CBlockIndex *pindexPrev, ThresholdConditionCache &cache) const
Returns the state for pindex A based on parent pindexPrev B.
virtual int MinActivationHeight() const
Class to implement versionbits logic.
Abstract class that implements BIP9-style threshold logic, and caches results.
const std::array< VBDeploymentInfo, Consensus::MAX_VERSION_BITS_DEPLOYMENTS > VersionBitsDeploymentInfo
static constexpr int64_t NEVER_ACTIVE
Special value for nStartTime indicating that the deployment is never active.
Parameters that influence chain consensus.
int64_t GetMedianTimePast() const
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Determine what nVersion a new block should use.
int64_t DifficultyAdjustmentInterval() const
virtual int Period() const =0
virtual int Threshold() const =0
int32_t nVersion
block header
std::string StateName(ThresholdState state)
Get a string with the state name.
Detailed status of an enabled BIP9 deployment.
bool IsTestChain() const
If this chain is exclusively used for testing.
BIP9Stats GetStateStatisticsFor(const CBlockIndex *pindex, std::vector< bool > *signalling_blocks=nullptr) const
Returns the numerical statistics of an in-progress BIP9 softfork in the period including pindex If pr...
const char * name
Deployment name.
The block chain is a tree shaped structure starting with the genesis block at the root...
static const int32_t VERSIONBITS_TOP_BITS
What bits to set in version for versionbits blocks.
BIP9Info Info(const CBlockIndex &block_index, const Consensus::Params ¶ms, Consensus::DeploymentPos id) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
int MinBIP9WarningHeight
Don't warn about unknown BIP 9 activations below this height.
bool possible
False if there are not enough blocks left in this period to pass activation threshold.
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev, ThresholdConditionCache &cache) const
Returns the height since when the ThresholdState has started for pindex A based on parent pindexPrev ...
uint32_t period
Length of blocks of the BIP9 signalling period.
virtual int64_t EndTime() const =0
int nHeight
height of the entry in the chain. The genesis block has height 0
const Consensus::Params & GetConsensus() const
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
uint32_t count
Number of blocks with the version bit set since the beginning of the current period.
std::vector< std::pair< int, bool > > CheckUnknownActivations(const CBlockIndex *pindex, const CChainParams &chainparams) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Check for unknown activations Returns a vector containing the bit number used for signalling and a bo...
static const int32_t VERSIONBITS_NUM_BITS
Total bits available for versionbits.
BIP9GBTStatus GBTStatus(const CBlockIndex &block_index, const Consensus::Params ¶ms) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
uint32_t elapsed
Number of blocks elapsed since the beginning of the current period.
#define Assert(val)
Identity function.
bool IsActiveAfter(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::DeploymentPos pos) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Get the BIP9 state for a given deployment for the block after pindexPrev.