aboutsummaryrefslogtreecommitdiff
path: root/src/versionbits.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/versionbits.cpp')
-rw-r--r--src/versionbits.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/versionbits.cpp b/src/versionbits.cpp
index 8a7cce7485..80786233f5 100644
--- a/src/versionbits.cpp
+++ b/src/versionbits.cpp
@@ -3,7 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "versionbits.h"
-
#include "consensus/params.h"
const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS] = {
@@ -105,6 +104,36 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
return state;
}
+// return the numerical statistics of blocks signalling the specified BIP9 condition in this current period
+BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockIndex* pindex, const Consensus::Params& params) const
+{
+ BIP9Stats stats;
+
+ stats.period = Period(params);
+ stats.threshold = Threshold(params);
+
+ if (pindex == NULL)
+ return stats;
+
+ // Find beginning of period
+ const CBlockIndex* pindexEndOfPrevPeriod = pindex->GetAncestor(pindex->nHeight - ((pindex->nHeight + 1) % stats.period));
+ stats.elapsed = pindex->nHeight - pindexEndOfPrevPeriod->nHeight;
+
+ // 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;
+ }
+
+ stats.count = count;
+ stats.possible = (stats.period - stats.threshold ) >= (stats.elapsed - count);
+
+ return stats;
+}
+
int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
{
const ThresholdState initialState = GetStateFor(pindexPrev, params, cache);
@@ -167,6 +196,11 @@ ThresholdState VersionBitsState(const CBlockIndex* pindexPrev, const Consensus::
return VersionBitsConditionChecker(pos).GetStateFor(pindexPrev, params, cache.caches[pos]);
}
+BIP9Stats VersionBitsStatistics(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos)
+{
+ return VersionBitsConditionChecker(pos).GetStateStatisticsFor(pindexPrev, params);
+}
+
int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache)
{
return VersionBitsConditionChecker(pos).GetStateSinceHeightFor(pindexPrev, params, cache.caches[pos]);