MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetStateStatisticsFor

Method GetStateStatisticsFor

src/versionbits.cpp:112–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

110}
111
112BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params, std::vector<bool>* signalling_blocks) const
113{
114 BIP9Stats stats = {};
115
116 stats.period = Period(params);
117 stats.threshold = Threshold(params);
118
119 if (pindex == nullptr) return stats;
120
121 // Find how many blocks are in the current period
122 int blocks_in_period = 1 + (pindex->nHeight % stats.period);
123
124 // Reset signalling_blocks
125 if (signalling_blocks) {
126 signalling_blocks->assign(blocks_in_period, false);
127 }
128
129 // Count from current block to beginning of period
130 int elapsed = 0;
131 int count = 0;
132 const CBlockIndex* currentIndex = pindex;
133 do {
134 ++elapsed;
135 --blocks_in_period;
136 if (Condition(currentIndex, params)) {
137 ++count;
138 if (signalling_blocks) signalling_blocks->at(blocks_in_period) = true;
139 }
140 currentIndex = currentIndex->pprev;
141 } while(blocks_in_period > 0);
142
143 stats.elapsed = elapsed;
144 stats.count = count;
145 stats.possible = (stats.period - stats.threshold ) >= (stats.elapsed - count);
146
147 return stats;
148}
149
150int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
151{

Callers 1

StatisticsMethod · 0.45

Calls 1

assignMethod · 0.45

Tested by

no test coverage detected