aboutsummaryrefslogtreecommitdiff
path: root/src/versionbits.cpp
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2021-11-14 07:55:34 +1000
committerAnthony Towns <aj@erisian.com.au>2022-01-15 04:37:56 +1000
commita7469bcd35692d56f57e91b3f21d30855bdf6531 (patch)
tree7360a5d1ddbdfbcfa1dd592d586faa19eab447a8 /src/versionbits.cpp
parent7f15c1841b98de6931a7ac68e16635a05d3e96cf (diff)
downloadbitcoin-a7469bcd35692d56f57e91b3f21d30855bdf6531.tar.xz
rpc: getdeploymentinfo: change stats to always refer to current period
On a period boundary, getdeploymentinfo (and previously getblockchaininfo) would report the status and statistics for the next block rather than the current block. Change this to always report the status/statistics of the current block, but add status-next to report the status for the next block.
Diffstat (limited to 'src/versionbits.cpp')
-rw-r--r--src/versionbits.cpp19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/versionbits.cpp b/src/versionbits.cpp
index 94c3c9559f..f8945b78b3 100644
--- a/src/versionbits.cpp
+++ b/src/versionbits.cpp
@@ -105,22 +105,23 @@ BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockI
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 start_height = pindex->nHeight - (pindex->nHeight % stats.period);
// Count from current block to beginning of period
+ int elapsed = 0;
int count = 0;
const CBlockIndex* currentIndex = pindex;
- while (pindexEndOfPrevPeriod->nHeight != currentIndex->nHeight){
- if (Condition(currentIndex, params))
- count++;
+ for(;;) {
+ ++elapsed;
+ if (Condition(currentIndex, params)) ++count;
+ if (currentIndex->nHeight <= start_height) break;
currentIndex = currentIndex->pprev;
}
+ stats.elapsed = elapsed;
stats.count = count;
stats.possible = (stats.period - stats.threshold ) >= (stats.elapsed - count);
@@ -196,9 +197,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)
{
- return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindexPrev, params);
+ return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindex, params);
}
int VersionBitsCache::StateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)