Skip to content

Commit dd07e6d

Browse files
committed
fuzz: test versionbits delayed activation
1 parent dd85d54 commit dd07e6d

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/test/fuzz/versionbits.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,24 @@ class TestConditionChecker : public AbstractThresholdConditionChecker
2929
const int64_t m_end;
3030
const int m_period;
3131
const int m_threshold;
32+
const int m_min_activation_height;
3233
const int m_bit;
3334

34-
TestConditionChecker(int64_t begin, int64_t end, int period, int threshold, int bit)
35-
: m_begin{begin}, m_end{end}, m_period{period}, m_threshold{threshold}, m_bit{bit}
35+
TestConditionChecker(int64_t begin, int64_t end, int period, int threshold, int min_activation_height, int bit)
36+
: m_begin{begin}, m_end{end}, m_period{period}, m_threshold{threshold}, m_min_activation_height{min_activation_height}, m_bit{bit}
3637
{
3738
assert(m_period > 0);
3839
assert(0 <= m_threshold && m_threshold <= m_period);
3940
assert(0 <= m_bit && m_bit < 32 && m_bit < VERSIONBITS_NUM_BITS);
41+
assert(0 <= m_min_activation_height);
4042
}
4143

4244
bool Condition(const CBlockIndex* pindex, const Consensus::Params& params) const override { return Condition(pindex->nVersion); }
4345
int64_t BeginTime(const Consensus::Params& params) const override { return m_begin; }
4446
int64_t EndTime(const Consensus::Params& params) const override { return m_end; }
4547
int Period(const Consensus::Params& params) const override { return m_period; }
4648
int Threshold(const Consensus::Params& params) const override { return m_threshold; }
49+
int MinActivationHeight(const Consensus::Params& params) const override { return m_min_activation_height; }
4750

4851
ThresholdState GetStateFor(const CBlockIndex* pindexPrev) const { return AbstractThresholdConditionChecker::GetStateFor(pindexPrev, dummy_params, m_cache); }
4952
int GetStateSinceHeightFor(const CBlockIndex* pindexPrev) const { return AbstractThresholdConditionChecker::GetStateSinceHeightFor(pindexPrev, dummy_params, m_cache); }
@@ -168,8 +171,9 @@ FUZZ_TARGET_INIT(versionbits, initialize)
168171
never_active_test = true;
169172
}
170173
}
174+
int min_activation = fuzzed_data_provider.ConsumeIntegralInRange<int>(0, period * max_periods);
171175

172-
TestConditionChecker checker(start_time, timeout, period, threshold, bit);
176+
TestConditionChecker checker(start_time, timeout, period, threshold, min_activation, bit);
173177

174178
// Early exit if the versions don't signal sensibly for the deployment
175179
if (!checker.Condition(ver_signal)) return;
@@ -306,11 +310,16 @@ FUZZ_TARGET_INIT(versionbits, initialize)
306310
}
307311
break;
308312
case ThresholdState::LOCKED_IN:
309-
assert(exp_state == ThresholdState::STARTED);
310-
assert(current_block->GetMedianTimePast() < checker.m_end);
311-
assert(blocks_sig >= threshold);
313+
if (exp_state == ThresholdState::LOCKED_IN) {
314+
assert(current_block->nHeight + 1 < min_activation);
315+
} else {
316+
assert(exp_state == ThresholdState::STARTED);
317+
assert(current_block->GetMedianTimePast() < checker.m_end);
318+
assert(blocks_sig >= threshold);
319+
}
312320
break;
313321
case ThresholdState::ACTIVE:
322+
assert(always_active_test || min_activation <= current_block->nHeight + 1);
314323
assert(exp_state == ThresholdState::ACTIVE || exp_state == ThresholdState::LOCKED_IN);
315324
break;
316325
case ThresholdState::FAILED:

0 commit comments

Comments
 (0)