Created
April 14, 2021 16:21
-
-
Save JeremyRubin/72c793401c8dbdca581c1498f5794091 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/consensus/params.h b/src/consensus/params.h | |
index 28c95e088..076a57f10 100644 | |
--- a/src/consensus/params.h | |
+++ b/src/consensus/params.h | |
@@ -8,6 +8,7 @@ | |
#include <uint256.h> | |
#include <limits> | |
+#include <optional> | |
namespace Consensus { | |
@@ -34,6 +35,7 @@ struct BIP9Deployment { | |
* boundary. | |
*/ | |
int min_activation_height{0}; | |
+ int preceding_deployments_on_this_bit{0}; | |
/** Constant for nTimeout very far in the future. */ | |
static constexpr int64_t NO_TIMEOUT = std::numeric_limits<int64_t>::max(); | |
diff --git a/src/versionbits.cpp b/src/versionbits.cpp | |
index df2ec4e05..d09f1ff0b 100644 | |
--- a/src/versionbits.cpp | |
+++ b/src/versionbits.cpp | |
@@ -10,6 +10,7 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* | |
int nPeriod = Period(params); | |
int nThreshold = Threshold(params); | |
int min_activation_height = MinActivationHeight(params); | |
+ int deployments_preceding = DeploymentsPreceding(params); | |
int64_t nTimeStart = BeginTime(params); | |
int64_t nTimeTimeout = EndTime(params); | |
@@ -58,7 +59,19 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex* | |
switch (state) { | |
case ThresholdState::DEFINED: { | |
if (pindexPrev->GetMedianTimePast() >= nTimeStart) { | |
- stateNext = ThresholdState::STARTED; | |
+ if (pindexPrev->GetMedianTimePast() >= nTimeTimeout) { | |
+ int count_periods = 0; | |
+ for (int i = 0; i < deployments_preceding; ++i) { | |
+ const CBlockIndex* lookback = pindexPrev->GetAncestor(pindexPrev->nHeight - (nPeriod*i)); | |
+ count_periods += lookback->GetMedianTimePast() >= nTimeStart; | |
+ } | |
+ // give each deployment 4 periods | |
+ if (count_periods >= deployments_preceding*4) { | |
+ stateNext = ThresholdState::STARTED; | |
+ } | |
+ } else { | |
+ stateNext = ThresholdState::STARTED; | |
+ } | |
} | |
break; | |
} | |
diff --git a/src/versionbits.h b/src/versionbits.h | |
index 634a848ef..a1b31749b 100644 | |
--- a/src/versionbits.h | |
+++ b/src/versionbits.h | |
@@ -58,6 +58,7 @@ protected: | |
virtual int64_t BeginTime(const Consensus::Params& params) const =0; | |
virtual int64_t EndTime(const Consensus::Params& params) const =0; | |
virtual int MinActivationHeight(const Consensus::Params& params) const { return 0; } | |
+ virtual int DeploymentsPreceding(const Consensus::Params& params) const { return 0; } | |
virtual int Period(const Consensus::Params& params) const =0; | |
virtual int Threshold(const Consensus::Params& params) const =0; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment