Skip to content

Commit d07ee77

Browse files
committed
Always-active versionbits support
1 parent 18e0718 commit d07ee77

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/consensus/params.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ struct BIP9Deployment {
3535

3636
/** Constant for nTimeout very far in the future. */
3737
static constexpr int64_t NO_TIMEOUT = std::numeric_limits<int64_t>::max();
38+
39+
/** Special value for nStartTime indicating that the deployment is always active.
40+
* This is useful for testing, as it means tests don't need to deal with the activation
41+
* process (which takes at least 3 BIP9 intervals). Only tests that specifically test the
42+
* behaviour during activation cannot use this. */
43+
static constexpr int64_t ALWAYS_ACTIVE = -1;
3844
};
3945

4046
/**

src/versionbits.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ ThresholdState AbstractThresholdConditionChecker::GetStateFor(const CBlockIndex*
2727
int64_t nTimeStart = BeginTime(params);
2828
int64_t nTimeTimeout = EndTime(params);
2929

30+
// Check if this deployment is always active.
31+
if (nTimeStart == Consensus::BIP9Deployment::ALWAYS_ACTIVE) {
32+
return THRESHOLD_ACTIVE;
33+
}
34+
3035
// 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.
3136
if (pindexPrev != nullptr) {
3237
pindexPrev = pindexPrev->GetAncestor(pindexPrev->nHeight - ((pindexPrev->nHeight + 1) % nPeriod));
@@ -136,6 +141,11 @@ BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockI
136141

137142
int AbstractThresholdConditionChecker::GetStateSinceHeightFor(const CBlockIndex* pindexPrev, const Consensus::Params& params, ThresholdConditionCache& cache) const
138143
{
144+
int64_t start_time = BeginTime(params);
145+
if (start_time == Consensus::BIP9Deployment::ALWAYS_ACTIVE) {
146+
return 0;
147+
}
148+
139149
const ThresholdState initialState = GetStateFor(pindexPrev, params, cache);
140150

141151
// BIP 9 about state DEFINED: "The genesis block is by definition in this state for each deployment."

0 commit comments

Comments
 (0)