| 110 | } |
| 111 | |
| 112 | BIP9Stats 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 | |
| 150 | int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const |
| 151 | { |