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

Method GetStateStatisticsFor

src/versionbits.cpp:119–155  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

InfoMethod · 0.80
versionbits.cppFile · 0.80

Calls 2

assignMethod · 0.45
atMethod · 0.45

Tested by

no test coverage detected