11 int nPeriod =
Period(params);
14 int64_t nTimeTimeout =
EndTime(params);
24 if (pindexPrev !=
nullptr) {
31 std::vector<const CBlockIndex *> vToCompute;
32 while (cache.count(pindexPrev) == 0) {
33 if (pindexPrev ==
nullptr) {
44 vToCompute.push_back(pindexPrev);
49 assert(cache.count(pindexPrev));
53 while (!vToCompute.empty()) {
55 pindexPrev = vToCompute.back();
56 vToCompute.pop_back();
75 for (
int i = 0; i < nPeriod; i++) {
79 pindexCount = pindexCount->
pprev;
81 if (
count >= nThreshold) {
97 cache[pindexPrev] = state = stateNext;
110 if (pindex ==
nullptr) {
126 currentIndex = currentIndex->
pprev;
152 const int nPeriod =
Period(params);
164 ((pindexPrev->
nHeight + 1) % nPeriod));
169 while (previousPeriodParent !=
nullptr &&
170 GetStateFor(previousPeriodParent, params, cache) == initialState) {
171 pindexPrev = previousPeriodParent;
172 previousPeriodParent =
177 return pindexPrev->
nHeight + 1;
206 (pindex->
nVersion & Mask(params)) != 0);
223 return VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params,
230 return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindexPrev,
238 return VersionBitsConditionChecker(pos).GetStateSinceHeightFor(
239 pindexPrev, params, m_caches[pos]);
244 return VersionBitsConditionChecker(pos).Mask(params);
254 ThresholdState state = VersionBitsConditionChecker(pos).GetStateFor(
255 pindexPrev, params, m_caches[pos]);
258 nVersion |=
Mask(params, pos);
263 return nVersion & ~uint32_t(0x0f);
Abstract class that implements BIP9-style threshold logic, and caches results.
virtual bool Condition(const CBlockIndex *pindex, const Consensus::Params ¶ms) const =0
virtual int Period(const Consensus::Params ¶ms) const =0
BIP9Stats GetStateStatisticsFor(const CBlockIndex *pindex, const Consensus::Params ¶ms) const
Returns the numerical statistics of an in-progress BIP9 softfork in the current period.
ThresholdState GetStateFor(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, ThresholdConditionCache &cache) const
Returns the state for pindex A based on parent pindexPrev B.
virtual int64_t EndTime(const Consensus::Params ¶ms) const =0
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, ThresholdConditionCache &cache) const
Returns the height since when the ThresholdState has started for pindex.
virtual int64_t BeginTime(const Consensus::Params ¶ms) const =0
virtual int Threshold(const Consensus::Params ¶ms) const =0
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
int64_t GetMedianTimePast() const
int32_t nVersion
block header
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
int nHeight
height of the entry in the chain. The genesis block has height 0
static BIP9Stats Statistics(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the numerical statistics for a given deployment for the signalling period that includes the block...
ThresholdState State(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the BIP9 state for a given deployment for the block after pindexPrev.
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms)
Determine what nVersion a new block should use.
int StateSinceHeight(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the block height at which the BIP9 deployment switched into the state for the block after pindexP...
static uint32_t Mask(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
@ MAX_VERSION_BITS_DEPLOYMENTS
Display status of an in-progress BIP9 softfork.
int count
Number of blocks with the version bit set since the beginning of the current period.
int elapsed
Number of blocks elapsed since the beginning of the current period.
int threshold
Number of blocks with the version bit set required to activate the softfork.
bool possible
False if there are not enough blocks left in this period to pass activation threshold.
int period
Length of blocks of the BIP9 signalling period.
int bit
Bit position to select the particular bit in nVersion.
static constexpr int64_t ALWAYS_ACTIVE
Special value for nStartTime indicating that the deployment is always active.
int64_t nTimeout
Timeout/expiry MedianTime for the deployment attempt.
uint32_t nActivationThreshold
Minimum number of blocks within an activation window that must signal to activate the deployement.
int64_t nStartTime
Start MedianTime for version bits miner confirmation.
Parameters that influence chain consensus.
uint32_t nMinerConfirmationWindow
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]
std::map< const CBlockIndex *, ThresholdState > ThresholdConditionCache
static const int32_t VERSIONBITS_TOP_BITS
What bits to set in version for versionbits blocks.
static const int32_t VERSIONBITS_TOP_MASK
What bitmask determines whether versionbits is in use.
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.