mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-19 13:27:35 +02:00
Merge 2cd834e6c0 into merged_master (Bitcoin PR #21377)
This commit is contained in:
commit
6d4961766a
9 changed files with 324 additions and 163 deletions
|
|
@ -18,6 +18,7 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
|
|||
{
|
||||
int nPeriod = Period(params);
|
||||
int nThreshold = Threshold(params);
|
||||
int min_activation_height = MinActivationHeight(params);
|
||||
// ELEMENTS: We interpret this as block height, not block time!
|
||||
int64_t nTimeStart = BeginTime(params);
|
||||
int64_t nTimeTimeout = EndTime(params);
|
||||
|
|
@ -27,6 +28,11 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
|
|||
return ThresholdState::ACTIVE;
|
||||
}
|
||||
|
||||
// Check if this deployment is never active.
|
||||
if (nTimeStart == Consensus::BIP9Deployment::NEVER_ACTIVE) {
|
||||
return ThresholdState::FAILED;
|
||||
}
|
||||
|
||||
// A block's state is always the same as that of the first of its period, so it is computed based on a pindexPrev whose height equals a multiple of nPeriod - 1.
|
||||
if (pindexPrev != nullptr) {
|
||||
pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - ((pindexPrev->nHeight + 1) % nPeriod));
|
||||
|
|
@ -61,18 +67,12 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
|
|||
|
||||
switch (state) {
|
||||
case ThresholdState::DEFINED: {
|
||||
if (GetBIP9Time(pindexPrev, params) >= nTimeTimeout) {
|
||||
stateNext = ThresholdState::FAILED;
|
||||
} else if (GetBIP9Time(pindexPrev, params) >= nTimeStart) {
|
||||
if (GetBIP9Time(pindexPrev, params) >= nTimeStart) {
|
||||
stateNext = ThresholdState::STARTED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ThresholdState::STARTED: {
|
||||
if (GetBIP9Time(pindexPrev, params) >= nTimeTimeout) {
|
||||
stateNext = ThresholdState::FAILED;
|
||||
break;
|
||||
}
|
||||
// We need to count
|
||||
const CBlockIndex* pindexCount = pindexPrev;
|
||||
int count = 0;
|
||||
|
|
@ -84,12 +84,16 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
|
|||
}
|
||||
if (count >= nThreshold) {
|
||||
stateNext = ThresholdState::LOCKED_IN;
|
||||
} else if (GetBIP9Time(pindexPrev, params) >= nTimeTimeout) {
|
||||
stateNext = ThresholdState::FAILED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ThresholdState::LOCKED_IN: {
|
||||
// Always progresses into ACTIVE.
|
||||
stateNext = ThresholdState::ACTIVE;
|
||||
// Progresses into ACTIVE provided activation height will have been reached.
|
||||
if (pindexPrev->nHeight + 1 >= min_activation_height) {
|
||||
stateNext = ThresholdState::ACTIVE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ThresholdState::FAILED:
|
||||
|
|
@ -136,7 +140,7 @@ BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockI
|
|||
int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
|
||||
{
|
||||
int64_t start_time = BeginTime(params);
|
||||
if (start_time == Consensus::BIP9Deployment::ALWAYS_ACTIVE) {
|
||||
if (start_time == Consensus::BIP9Deployment::ALWAYS_ACTIVE || start_time == Consensus::BIP9Deployment::NEVER_ACTIVE) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -180,6 +184,7 @@ private:
|
|||
protected:
|
||||
int64_t BeginTime(const Consensus::Params& params) const override { return params.vDeployments[id].nStartTime; }
|
||||
int64_t EndTime(const Consensus::Params& params) const override { return params.vDeployments[id].nTimeout; }
|
||||
int MinActivationHeight(const Consensus::Params& params) const override { return params.vDeployments[id].min_activation_height; }
|
||||
int Period(const Consensus::Params& params) const override { return params.nMinerConfirmationWindow; }
|
||||
int Threshold(const Consensus::Params& params) const override { return params.nRuleChangeActivationThreshold; }
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue