mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-16 13:01:19 +02:00
Merge d4e92d8436 into merged_master (Bitcoin PR bitcoin/bitcoin#23508)
This commit is contained in:
commit
5931d7d47c
16 changed files with 294 additions and 129 deletions
|
|
@ -109,29 +109,38 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
|
|||
return state;
|
||||
}
|
||||
|
||||
BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const
|
||||
BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params, std::vector<bool>* signalling_blocks) const
|
||||
{
|
||||
BIP9Stats stats = {};
|
||||
|
||||
stats.period = Period(params);
|
||||
stats.threshold = Threshold(params);
|
||||
|
||||
if (pindex == nullptr)
|
||||
return stats;
|
||||
if (pindex == nullptr) return stats;
|
||||
|
||||
// Find beginning of period
|
||||
const CBlockIndex* pindexEndOfPrevPeriod = pindex->GetAncestor(pindex->nHeight - ((pindex->nHeight + 1) % stats.period));
|
||||
stats.elapsed = pindex->nHeight - pindexEndOfPrevPeriod->nHeight;
|
||||
int blocks_in_period = 1 + (pindex->nHeight % stats.period);
|
||||
|
||||
// Count from current block to beginning of period
|
||||
int count = 0;
|
||||
const CBlockIndex* currentIndex = pindex;
|
||||
while (pindexEndOfPrevPeriod->nHeight != currentIndex->nHeight){
|
||||
if (Condition(currentIndex, params))
|
||||
count++;
|
||||
currentIndex = currentIndex->pprev;
|
||||
// Reset signalling_blocks
|
||||
if (signalling_blocks) {
|
||||
signalling_blocks->assign(blocks_in_period, false);
|
||||
}
|
||||
|
||||
// Count from current block to beginning of period
|
||||
int elapsed = 0;
|
||||
int count = 0;
|
||||
const CBlockIndex* currentIndex = pindex;
|
||||
do {
|
||||
++elapsed;
|
||||
--blocks_in_period;
|
||||
if (Condition(currentIndex, params)) {
|
||||
++count;
|
||||
if (signalling_blocks) signalling_blocks->at(blocks_in_period) = true;
|
||||
}
|
||||
currentIndex = currentIndex->pprev;
|
||||
} while(blocks_in_period > 0);
|
||||
|
||||
stats.elapsed = elapsed;
|
||||
stats.count = count;
|
||||
stats.possible = (stats.period - stats.threshold ) >= (stats.elapsed - count);
|
||||
|
||||
|
|
@ -219,9 +228,9 @@ ThresholdState VersionBitsCache::State(const CBlockIndex* pindexPrev, const Cons
|
|||
return VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params, m_caches[pos]);
|
||||
}
|
||||
|
||||
BIP9Stats VersionBitsCache::Statistics(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||
BIP9Stats VersionBitsCache::Statistics(const CBlockIndex* pindex, const Consensus::Params& params, Consensus::DeploymentPos pos, std::vector<bool>* signalling_blocks)
|
||||
{
|
||||
return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindexPrev, params);
|
||||
return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindex, params, signalling_blocks);
|
||||
}
|
||||
|
||||
int VersionBitsCache::StateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue