MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / GetStateStatisticsFor

Method GetStateStatisticsFor

src/versionbits.cpp:113–140  ·  view source on GitHub ↗

return the numerical statistics of blocks signalling the specified BIP9 condition in this current period

Source from the content-addressed store, hash-verified

111
112// return the numerical statistics of blocks signalling the specified BIP9 condition in this current period
113BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const
114{
115 BIP9Stats stats = {};
116
117 stats.period = Period(params);
118 stats.threshold = Threshold(params);
119
120 if (pindex == nullptr)
121 return stats;
122
123 // Find beginning of period
124 const CBlockIndex* pindexEndOfPrevPeriod = pindex->GetAncestor(pindex->nHeight - ((pindex->nHeight + 1) % stats.period));
125 stats.elapsed = pindex->nHeight - pindexEndOfPrevPeriod->nHeight;
126
127 // Count from current block to beginning of period
128 int count = 0;
129 const CBlockIndex* currentIndex = pindex;
130 while (pindexEndOfPrevPeriod->nHeight != currentIndex->nHeight){
131 if (Condition(currentIndex, params))
132 count++;
133 currentIndex = currentIndex->pprev;
134 }
135
136 stats.count = count;
137 stats.possible = (stats.period - stats.threshold ) >= (stats.elapsed - count);
138
139 return stats;
140}
141
142int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
143{

Callers 1

VersionBitsStatisticsFunction · 0.80

Calls 1

GetAncestorMethod · 0.80

Tested by

no test coverage detected