| 117 | } |
| 118 | |
| 119 | BIP9Stats 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 | |
| 157 | int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex* pindexPrev, ThresholdConditionCache& cache) const |
| 158 | { |
no test coverage detected