Bitcoin Core  31.0.0
P2P Digital Currency
versionbits.h
Go to the documentation of this file.
1 // Copyright (c) 2016-present 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 
16 class CChainParams;
17 
19 static const int32_t VERSIONBITS_LAST_OLD_BLOCK_VERSION = 4;
21 static const int32_t VERSIONBITS_TOP_BITS = 0x20000000UL;
23 static const int32_t VERSIONBITS_TOP_MASK = 0xE0000000UL;
25 static const int32_t VERSIONBITS_NUM_BITS = 29;
26 
28 enum 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.
33 typedef std::map<const CBlockIndex*, ThresholdState> ThresholdConditionCache;
34 
36 struct 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 
50 struct 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 
65 struct BIP9GBTStatus {
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 {
78 private:
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 
83 public:
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
Opaque type for BIP9 state.
Definition: versionbits.h:36
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
std::map< std::string, const Info, std::less<> > locked_in
Definition: versionbits.h:71
DeploymentPos
Definition: params.h:34
static const int32_t VERSIONBITS_TOP_MASK
What bitmask determines whether versionbits is in use.
Definition: versionbits.h:23
std::vector< bool > signalling_blocks
Which blocks signalled; empty if signalling is not applicable.
Definition: versionbits.h:60
std::map< std::string, const Info, std::less<> > active
Definition: versionbits.h:71
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Definition: chainparams.h:76
void Clear() EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
std::string next_state
String representing the next block&#39;s state.
Definition: versionbits.h:56
std::string current_state
String representing the current state.
Definition: versionbits.h:54
std::array< ThresholdConditionCache, VERSIONBITS_NUM_BITS > m_warning_caches GUARDED_BY(m_mutex)
std::optional< int > active_since
Height at which the deployment is active, if known.
Definition: versionbits.h:62
int since
Height at which current_state started.
Definition: versionbits.h:52
Parameters that influence chain consensus.
Definition: params.h:84
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
Determine what nVersion a new block should use.
BIP 9 allows multiple softforks to be deployed in parallel.
Definition: versionbits.h:76
std::map< std::string, const Info, std::less<> > signalling
Definition: versionbits.h:71
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
Detailed status of an enabled BIP9 deployment.
Definition: versionbits.h:50
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:93
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_BITS
What bits to set in version for versionbits blocks.
Definition: versionbits.h:21
BIP9Info Info(const CBlockIndex &block_index, const Consensus::Params &params, Consensus::DeploymentPos id) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex)
static int count
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...
static const int32_t VERSIONBITS_NUM_BITS
Total bits available for versionbits.
Definition: versionbits.h:25
std::optional< BIP9Stats > stats
For states where signalling is applicable, information about the signalling.
Definition: versionbits.h:58
BIP9GBTStatus GBTStatus(const CBlockIndex &block_index, const Consensus::Params &params) EXCLUSIVE_LOCKS_REQUIRED(!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.