/root/bitcoin/src/consensus/params.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) 2009-2010 Satoshi Nakamoto |
2 | | // Copyright (c) 2009-2022 The Bitcoin Core developers |
3 | | // Distributed under the MIT software license, see the accompanying |
4 | | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
5 | | |
6 | | #ifndef BITCOIN_CONSENSUS_PARAMS_H |
7 | | #define BITCOIN_CONSENSUS_PARAMS_H |
8 | | |
9 | | #include <script/verify_flags.h> |
10 | | #include <uint256.h> |
11 | | |
12 | | #include <array> |
13 | | #include <chrono> |
14 | | #include <limits> |
15 | | #include <map> |
16 | | #include <vector> |
17 | | |
18 | | namespace Consensus { |
19 | | |
20 | | /** |
21 | | * A buried deployment is one where the height of the activation has been hardcoded into |
22 | | * the client implementation long after the consensus change has activated. See BIP 90. |
23 | | */ |
24 | | enum BuriedDeployment : int16_t { |
25 | | // buried deployments get negative values to avoid overlap with DeploymentPos |
26 | | DEPLOYMENT_HEIGHTINCB = std::numeric_limits<int16_t>::min(), |
27 | | DEPLOYMENT_CLTV, |
28 | | DEPLOYMENT_DERSIG, |
29 | | DEPLOYMENT_CSV, |
30 | | DEPLOYMENT_SEGWIT, |
31 | | }; |
32 | 0 | constexpr bool ValidDeployment(BuriedDeployment dep) { return dep <= DEPLOYMENT_SEGWIT; } |
33 | | |
34 | | enum DeploymentPos : uint16_t { |
35 | | DEPLOYMENT_TESTDUMMY, |
36 | | DEPLOYMENT_TAPROOT, // Deployment of Schnorr/Taproot (BIPs 340-342) |
37 | | // NOTE: Also add new deployments to VersionBitsDeploymentInfo in deploymentinfo.cpp |
38 | | MAX_VERSION_BITS_DEPLOYMENTS |
39 | | }; |
40 | 0 | constexpr bool ValidDeployment(DeploymentPos dep) { return dep < MAX_VERSION_BITS_DEPLOYMENTS; } |
41 | | |
42 | | /** |
43 | | * Struct for each individual consensus rule change using BIP9. |
44 | | */ |
45 | | struct BIP9Deployment { |
46 | | /** Bit position to select the particular bit in nVersion. */ |
47 | | int bit{28}; |
48 | | /** Start MedianTime for version bits miner confirmation. Can be a date in the past */ |
49 | | int64_t nStartTime{NEVER_ACTIVE}; |
50 | | /** Timeout/expiry MedianTime for the deployment attempt. */ |
51 | | int64_t nTimeout{NEVER_ACTIVE}; |
52 | | /** If lock in occurs, delay activation until at least this block |
53 | | * height. Note that activation will only occur on a retarget |
54 | | * boundary. |
55 | | */ |
56 | | int min_activation_height{0}; |
57 | | /** Period of blocks to check signalling in (usually retarget period, ie params.DifficultyAdjustmentInterval()) */ |
58 | | uint32_t period{2016}; |
59 | | /** |
60 | | * Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period, |
61 | | * which is also used for BIP9 deployments. |
62 | | * Examples: 1916 for 95%, 1512 for testchains. |
63 | | */ |
64 | | uint32_t threshold{1916}; |
65 | | |
66 | | /** Constant for nTimeout very far in the future. */ |
67 | | static constexpr int64_t NO_TIMEOUT = std::numeric_limits<int64_t>::max(); |
68 | | |
69 | | /** Special value for nStartTime indicating that the deployment is always active. |
70 | | * This is useful for testing, as it means tests don't need to deal with the activation |
71 | | * process (which takes at least 3 BIP9 intervals). Only tests that specifically test the |
72 | | * behaviour during activation cannot use this. */ |
73 | | static constexpr int64_t ALWAYS_ACTIVE = -1; |
74 | | |
75 | | /** Special value for nStartTime indicating that the deployment is never active. |
76 | | * This is useful for integrating the code changes for a new feature |
77 | | * prior to deploying it on some or all networks. */ |
78 | | static constexpr int64_t NEVER_ACTIVE = -2; |
79 | | }; |
80 | | |
81 | | /** |
82 | | * Parameters that influence chain consensus. |
83 | | */ |
84 | | struct Params { |
85 | | uint256 hashGenesisBlock; |
86 | | int nSubsidyHalvingInterval; |
87 | | /** |
88 | | * Hashes of blocks that |
89 | | * - are known to be consensus valid, and |
90 | | * - buried in the chain, and |
91 | | * - fail if the default script verify flags are applied. |
92 | | */ |
93 | | std::map<uint256, script_verify_flags> script_flag_exceptions; |
94 | | /** Block height and hash at which BIP34 becomes active */ |
95 | | int BIP34Height; |
96 | | uint256 BIP34Hash; |
97 | | /** Block height at which BIP65 becomes active */ |
98 | | int BIP65Height; |
99 | | /** Block height at which BIP66 becomes active */ |
100 | | int BIP66Height; |
101 | | /** Block height at which CSV (BIP68, BIP112 and BIP113) becomes active */ |
102 | | int CSVHeight; |
103 | | /** Block height at which Segwit (BIP141, BIP143 and BIP147) becomes active. |
104 | | * Note that segwit v0 script rules are enforced on all blocks except the |
105 | | * BIP 16 exception blocks. */ |
106 | | int SegwitHeight; |
107 | | /** Don't warn about unknown BIP 9 activations below this height. |
108 | | * This prevents us from warning about the CSV and segwit activations. */ |
109 | | int MinBIP9WarningHeight; |
110 | | std::array<BIP9Deployment,MAX_VERSION_BITS_DEPLOYMENTS> vDeployments; |
111 | | /** Proof of work parameters */ |
112 | | uint256 powLimit; |
113 | | bool fPowAllowMinDifficultyBlocks; |
114 | | /** |
115 | | * Enforce BIP94 timewarp attack mitigation. On testnet4 this also enforces |
116 | | * the block storm mitigation. |
117 | | */ |
118 | | bool enforce_BIP94; |
119 | | bool fPowNoRetargeting; |
120 | | int64_t nPowTargetSpacing; |
121 | | int64_t nPowTargetTimespan; |
122 | | std::chrono::seconds PowTargetSpacing() const |
123 | 0 | { |
124 | 0 | return std::chrono::seconds{nPowTargetSpacing}; |
125 | 0 | } |
126 | 0 | int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; } |
127 | | /** The best chain should have at least this much work */ |
128 | | uint256 nMinimumChainWork; |
129 | | /** By default assume that the signatures in ancestors of this block are valid */ |
130 | | uint256 defaultAssumeValid; |
131 | | |
132 | | /** |
133 | | * If true, witness commitments contain a payload equal to a Bitcoin Script solution |
134 | | * to the signet challenge. See BIP325. |
135 | | */ |
136 | | bool signet_blocks{false}; |
137 | | std::vector<uint8_t> signet_challenge; |
138 | | |
139 | | int DeploymentHeight(BuriedDeployment dep) const |
140 | 0 | { |
141 | 0 | switch (dep) { |
142 | 0 | case DEPLOYMENT_HEIGHTINCB: |
143 | 0 | return BIP34Height; |
144 | 0 | case DEPLOYMENT_CLTV: |
145 | 0 | return BIP65Height; |
146 | 0 | case DEPLOYMENT_DERSIG: |
147 | 0 | return BIP66Height; |
148 | 0 | case DEPLOYMENT_CSV: |
149 | 0 | return CSVHeight; |
150 | 0 | case DEPLOYMENT_SEGWIT: |
151 | 0 | return SegwitHeight; |
152 | 0 | } // no default case, so the compiler can warn about missing cases |
153 | 0 | return std::numeric_limits<int>::max(); |
154 | 0 | } |
155 | | }; |
156 | | |
157 | | } // namespace Consensus |
158 | | |
159 | | #endif // BITCOIN_CONSENSUS_PARAMS_H |