6#include <chainparams.h>
47 std::vector<std::unique_ptr<CBlockIndex>> m_blocks;
48 const uint32_t m_start_time;
49 const uint32_t m_interval;
50 const int32_t m_signal;
51 const int32_t m_no_signal;
54 Blocks(uint32_t start_time, uint32_t interval, int32_t signal, int32_t no_signal)
55 : m_start_time{start_time}, m_interval{interval}, m_signal{signal}, m_no_signal{no_signal} {}
57 size_t size()
const {
return m_blocks.size(); }
61 return m_blocks.empty() ? nullptr : m_blocks.back().get();
67 header.
nVersion = signal ? m_signal : m_no_signal;
68 header.
nTime = m_start_time + m_blocks.size() * m_interval;
69 header.
nBits = 0x1d00ffff;
71 auto current_block = std::make_unique<CBlockIndex>(header);
72 current_block->pprev = tip();
73 current_block->nHeight = m_blocks.size();
74 current_block->BuildSkip();
76 return m_blocks.emplace_back(std::move(current_block)).get();
80std::unique_ptr<const CChainParams> g_params;
86 assert(g_params !=
nullptr);
89constexpr uint32_t MAX_START_TIME = 4102444800;
96 assert(interval < std::numeric_limits<int32_t>::max());
101 const uint32_t period = 32;
102 const size_t max_periods = 16;
103 const size_t max_blocks = 2 * period * max_periods;
107 assert(std::numeric_limits<uint32_t>::max() - MAX_START_TIME > interval * max_blocks);
114 if (ver_nosignal < 0)
return;
117 Blocks blocks(block_start_time, interval, ver_signal, ver_nosignal);
132 if (always_active_test) {
135 }
else if (never_active_test) {
144 dep.
nStartTime = block_start_time + start_block * interval;
145 dep.
nTimeout = block_start_time + end_block * interval;
157 if (!checker.Condition(ver_signal))
return;
158 if (checker.Condition(ver_nosignal))
return;
184 for (uint32_t b = 0; b < period; ++b) {
185 blocks.mine_block(signal);
189 if (blocks.size() + 2 * period > max_blocks)
break;
196 uint32_t blocks_sig = 0;
200 const int exp_since = checker.GetStateSinceHeightFor(prev);
205 last_stats.
period = period;
209 std::vector<bool> last_signals{};
211 int prev_next_height = (prev ==
nullptr ? 0 : prev->
nHeight + 1);
212 assert(exp_since <= prev_next_height);
215 for (uint32_t b = 1; b < period; ++b) {
216 const bool signal = (signalling_mask >> (b % 32)) & 1;
217 if (signal) ++blocks_sig;
219 CBlockIndex* current_block = blocks.mine_block(signal);
226 const int since = checker.GetStateSinceHeightFor(current_block);
227 assert(state == exp_state);
228 assert(since == exp_since);
231 std::vector<bool> signals;
232 const BIP9Stats stats = checker.GetStateStatisticsFor(current_block, &signals);
233 const BIP9Stats stats_no_signals = checker.GetStateStatisticsFor(current_block);
245 assert(signals.size() == last_signals.size() + 1);
246 assert(signals.back() == signal);
247 last_signals.push_back(signal);
248 assert(signals == last_signals);
257 bool signal = (signalling_mask >> (period % 32)) & 1;
258 if (signal) ++blocks_sig;
259 CBlockIndex* current_block = blocks.mine_block(signal);
262 const BIP9Stats stats = checker.GetStateStatisticsFor(current_block);
271 const int since = checker.GetStateSinceHeightFor(current_block);
274 assert(since % period == 0);
276 if (state == exp_state) {
277 assert(since == exp_since);
323 if (blocks.size() >= period * max_periods) {
328 if (always_active_test) {
333 }
else if (never_active_test) {
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const ChainType chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
ThresholdState GetStateFor(const CBlockIndex *pindexPrev, ThresholdConditionCache &cache) const
Returns the state for pindex A based on parent pindexPrev B.
int GetStateSinceHeightFor(const CBlockIndex *pindexPrev, ThresholdConditionCache &cache) const
Returns the height since when the ThresholdState has started for pindex A based on parent pindexPrev ...
The block chain is a tree shaped structure starting with the genesis block at the root,...
int64_t GetMedianTimePast() const
int32_t nVersion
block header
int nHeight
height of the entry in the chain. The genesis block has height 0
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
const CBlock & GenesisBlock() const
const Consensus::Params & GetConsensus() const
T ConsumeIntegralInRange(T min, T max)
Class to implement versionbits logic.
Display status of an in-progress BIP9 softfork.
uint32_t count
Number of blocks with the version bit set since the beginning of the current period.
uint32_t threshold
Number of blocks with the version bit set required to activate the softfork.
uint32_t elapsed
Number of blocks elapsed since the beginning of the current period.
bool possible
False if there are not enough blocks left in this period to pass activation threshold.
uint32_t period
Length of blocks of the BIP9 signalling period.
Struct for each individual consensus rule change using BIP9.
int min_activation_height
If lock in occurs, delay activation until at least this block height.
int bit
Bit position to select the particular bit in nVersion.
static constexpr int64_t ALWAYS_ACTIVE
Special value for nStartTime indicating that the deployment is always active.
static constexpr int64_t NEVER_ACTIVE
Special value for nStartTime indicating that the deployment is never active.
uint32_t period
Period of blocks to check signalling in (usually retarget period, ie params.DifficultyAdjustmentInter...
uint32_t threshold
Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period,...
int64_t nTimeout
Timeout/expiry MedianTime for the deployment attempt.
static constexpr int64_t NO_TIMEOUT
Constant for nTimeout very far in the future.
int64_t nStartTime
Start MedianTime for version bits miner confirmation.
int64_t nPowTargetSpacing
static constexpr int VERSIONBITS_MAX_NUM_BITS
Total possible bits available for versionbits per original BIP 9 specification.
std::map< const CBlockIndex *, ThresholdState > ThresholdConditionCache
static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION
What block version to use for new blocks (pre versionbits)
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
FuzzedDataProvider & fuzzed_data_provider