Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
versionbits.cpp
Go to the documentation of this file.
8 const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] = {
46 ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
52 // A block's state is always the same as that of the first of its period, so it is computed based on a pindexPrev whose height equals a multiple of nPeriod - 1.
54 pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - ((pindexPrev->nHeight + 1) % nPeriod));
66 // Optimization: don't recompute down further, as we know every earlier block will be before the start time
139 // return the numerical statistics of blocks signalling the specified BIP9 condition in this current period
140 BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params, ThresholdConditionCache& cache) const
151 const CBlockIndex* pindexEndOfPrevPeriod = pindex->GetAncestor(pindex->nHeight - ((pindex->nHeight + 1) % stats.period));
178 int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
182 // BIP 9 about state DEFINED: "The genesis block is by definition in this state for each deployment."
189 // A block's state is always the same as that of the first of its period, so it is computed based on a pindexPrev whose height equals a multiple of nPeriod - 1.
192 // if we are computing for the last block of a period, then pindexPrev points to the second to last block of the period, and
193 // if we are computing for the first block of a period, then pindexPrev points to the last block of the previous period.
195 pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - ((pindexPrev->nHeight + 1) % nPeriod));
197 const CBlockIndex* previousPeriodParent = pindexPrev->GetAncestor(pindexPrev->nHeight - nPeriod);
199 while (previousPeriodParent != nullptr && GetStateFor(previousPeriodParent, params, cache) == initialState) {
218 int64_t BeginTime(const Consensus::Params& params) const override { return params.vDeployments[id].nStartTime; }
219 int64_t EndTime(const Consensus::Params& params) const override { return params.vDeployments[id].nTimeout; }
220 int Period(const Consensus::Params& params) const override { return params.vDeployments[id].nWindowSize ? params.vDeployments[id].nWindowSize : params.nMinerConfirmationWindow; }
229 int64_t nThresholdCalc = params.vDeployments[id].nThresholdStart - nAttempt * nAttempt * Period(params) / 100 / params.vDeployments[id].nFalloffCoeff;
235 return (((pindex->nVersion & VERSIONBITS_TOP_MASK) == VERSIONBITS_TOP_BITS) && (pindex->nVersion & Mask(params)) != 0);
240 uint32_t Mask(const Consensus::Params& params) const { return ((uint32_t)1) << params.vDeployments[id].bit; }
245 ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
250 BIP9Stats VersionBitsStatistics(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
252 return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindexPrev, params, cache.caches[pos]);
255 int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
257 return VersionBitsConditionChecker(pos).GetStateSinceHeightFor(pindexPrev, params, cache.caches[pos]);
Definition: versionbits.h:42
Definition: versionbits.h:33
virtual int64_t EndTime(const Consensus::Params ¶ms) const =0
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, ThresholdConditionCache &cache) const
Definition: versionbits.cpp:178
Definition: versionbits.h:22
static const int32_t VERSIONBITS_TOP_MASK
What bitmask determines whether versionbits is in use.
Definition: versionbits.h:16
Definition: versionbits.h:23
virtual bool Condition(const CBlockIndex *pindex, const Consensus::Params ¶ms) const =0
Definition: versionbits.h:25
const struct VBDeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS]
Definition: versionbits.cpp:8
virtual int Threshold(const Consensus::Params ¶ms, int nAttempt) const =0
ThresholdConditionCache caches[Consensus::MAX_VERSION_BITS_DEPLOYMENTS]
Definition: versionbits.h:72
uint32_t VersionBitsMask(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Definition: versionbits.cpp:260
BIP9Stats GetStateStatisticsFor(const CBlockIndex *pindex, const Consensus::Params ¶ms, ThresholdConditionCache &cache) const
Definition: versionbits.cpp:140
Definition: params.h:13
int64_t nFalloffCoeff
A coefficient which adjusts the speed a required number of signaling blocks is decreasing from nThres...
Definition: params.h:45
Definition: versionbits.h:70
int VersionBitsStateSinceHeight(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::DeploymentPos pos, VersionBitsCache &cache)
Definition: versionbits.cpp:255
Abstract class that implements BIP9-style threshold logic, and caches results.
Definition: versionbits.h:55
int64_t nWindowSize
The number of past blocks (including the block under consideration) to be taken into account for lock...
Definition: params.h:39
uint32_t nMinerConfirmationWindow
Definition: params.h:170
int64_t nThresholdMin
A minimum number of blocks, in the range of 1..nWindowSize, which must signal for a fork in order to ...
Definition: params.h:43
std::map< const CBlockIndex *, ThresholdState > ThresholdConditionCache
Definition: versionbits.h:31
Definition: versionbits.h:24
ThresholdState GetStateFor(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, ThresholdConditionCache &cache) const
Definition: versionbits.cpp:46
Definition: versionbits.h:21
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
static const int32_t VERSIONBITS_TOP_BITS
What bits to set in version for versionbits blocks.
Definition: versionbits.h:14
virtual int64_t BeginTime(const Consensus::Params ¶ms) const =0
int64_t nThresholdStart
A starting number of blocks, in the range of 1..nWindowSize, which must signal for a fork in order to...
Definition: params.h:41
uint32_t nRuleChangeActivationThreshold
Minimum blocks including miner confirmation of the total of nMinerConfirmationWindow blocks in a reta...
Definition: params.h:168
virtual int Period(const Consensus::Params ¶ms) const =0
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
Definition: chain.cpp:110
ThresholdState VersionBitsState(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::DeploymentPos pos, VersionBitsCache &cache)
Definition: versionbits.cpp:245
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]
Definition: params.h:171
BIP9Stats VersionBitsStatistics(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::DeploymentPos pos, VersionBitsCache &cache)
Definition: versionbits.cpp:250