Bitcoin Core 29.99.0
P2P Digital Currency
versionbits.h
Go to the documentation of this file.
1// Copyright (c) 2016-2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_VERSIONBITS_H
6#define BITCOIN_VERSIONBITS_H
7
8#include <chain.h>
9#include <sync.h>
10
11#include <array>
12#include <map>
13#include <optional>
14#include <vector>
15
16class CChainParams;
17
19static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION = 4;
21static const int32_t VERSIONBITS_TOP_BITS = 0x20000000UL;
23static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
25static const int32_t VERSIONBITS_NUM_BITS = 29;
26
28enum class ThresholdState : uint8_t;
29
30// A map that gives the state for blocks whose height is a multiple of Period().
31// The map is indexed by the block's parent, however, so all keys in the map
32// will either be nullptr or a block with (height + 1) % Period() == 0.
33typedef std::map<const CBlockIndex*, ThresholdState> ThresholdConditionCache;
34
36struct BIP9Stats {
38 uint32_t period{0};
40 uint32_t threshold{0};
42 uint32_t elapsed{0};
44 uint32_t count{0};
46 bool possible{false};
47};
48
50struct BIP9Info {
52 int since{0};
54 std::string current_state{};
56 std::string next_state{};
58 std::optional<BIP9Stats> stats;
60 std::vector<bool> signalling_blocks;
62 std::optional<int> active_since;
63};
64
66 struct Info {
67 int bit;
68 uint32_t mask;
70 };
71 std::map<std::string, const Info, std::less<>> signalling, locked_in, active;
72};
73
77{
78private:
80 std::array<ThresholdConditionCache,VERSIONBITS_NUM_BITS> m_warning_caches GUARDED_BY(m_mutex);
81 std::array<ThresholdConditionCache,Consensus::MAX_VERSION_BITS_DEPLOYMENTS> m_caches GUARDED_BY(m_mutex);
82
83public:
85
87
90
92 int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
93
97 std::vector<std::pair<int,bool>> CheckUnknownActivations(const CBlockIndex* pindex, const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
98
100};
101
102#endif // BITCOIN_VERSIONBITS_H
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:141
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:69
BIP 9 allows multiple softforks to be deployed in parallel.
Definition: versionbits.h:77
BIP9GBTStatus GBTStatus(const CBlockIndex &block_index, const Consensus::Params &params) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Determine what nVersion a new block should use.
std::vector< std::pair< int, bool > > CheckUnknownActivations(const CBlockIndex *pindex, const CChainParams &chainparams) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Check for unknown activations Returns a vector containing the bit number used for signalling and a bo...
std::array< ThresholdConditionCache, Consensus::MAX_VERSION_BITS_DEPLOYMENTS > m_caches GUARDED_BY(m_mutex)
BIP9Info Info(const CBlockIndex &block_index, const Consensus::Params &params, Consensus::DeploymentPos id) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
void Clear() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
std::array< ThresholdConditionCache, VERSIONBITS_NUM_BITS > m_warning_caches GUARDED_BY(m_mutex)
bool IsActiveAfter(const CBlockIndex *pindexPrev, const Consensus::Params &params, Consensus::DeploymentPos pos) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Get the BIP9 state for a given deployment for the block after pindexPrev.
DeploymentPos
Definition: params.h:33
std::map< std::string, const Info, std::less<> > signalling
Definition: versionbits.h:71
std::map< std::string, const Info, std::less<> > active
Definition: versionbits.h:71
std::map< std::string, const Info, std::less<> > locked_in
Definition: versionbits.h:71
Detailed status of an enabled BIP9 deployment.
Definition: versionbits.h:50
std::string current_state
String representing the current state.
Definition: versionbits.h:54
std::vector< bool > signalling_blocks
Which blocks signalled; empty if signalling is not applicable.
Definition: versionbits.h:60
int since
Height at which current_state started.
Definition: versionbits.h:52
std::string next_state
String representing the next block's state.
Definition: versionbits.h:56
std::optional< BIP9Stats > stats
For states where signalling is applicable, information about the signalling.
Definition: versionbits.h:58
std::optional< int > active_since
Height at which the deployment is active, if known.
Definition: versionbits.h:62
Display status of an in-progress BIP9 softfork.
Definition: versionbits.h:36
uint32_t count
Number of blocks with the version bit set since the beginning of the current period.
Definition: versionbits.h:44
uint32_t threshold
Number of blocks with the version bit set required to activate the softfork.
Definition: versionbits.h:40
uint32_t elapsed
Number of blocks elapsed since the beginning of the current period.
Definition: versionbits.h:42
bool possible
False if there are not enough blocks left in this period to pass activation threshold.
Definition: versionbits.h:46
uint32_t period
Length of blocks of the BIP9 signalling period.
Definition: versionbits.h:38
Parameters that influence chain consensus.
Definition: params.h:83
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
std::map< const CBlockIndex *, ThresholdState > ThresholdConditionCache
Definition: versionbits.h:33
static const int32_t VERSIONBITS_NUM_BITS
Total bits available for versionbits.
Definition: versionbits.h:25
static const int32_t VERSIONBITS_TOP_BITS
What bits to set in version for versionbits blocks.
Definition: versionbits.h:21
static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION
What block version to use for new blocks (pre versionbits)
Definition: versionbits.h:19
static const int32_t VERSIONBITS_TOP_MASK
What bitmask determines whether versionbits is in use.
Definition: versionbits.h:23
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.