|
6 | 6 | #ifndef BITCOIN_CHAINPARAMS_H |
7 | 7 | #define BITCOIN_CHAINPARAMS_H |
8 | 8 |
|
| 9 | +#include <kernel/chainparams.h> |
| 10 | + |
9 | 11 | #include <chainparamsbase.h> |
10 | 12 | #include <consensus/params.h> |
11 | 13 | #include <llmq/params.h> |
|
14 | 16 | #include <protocol.h> |
15 | 17 | #include <util/hash_type.h> |
16 | 18 |
|
| 19 | +#include <cstdint> |
17 | 20 | #include <memory> |
18 | 21 | #include <optional> |
19 | 22 | #include <string> |
| 23 | +#include <unordered_map> |
20 | 24 | #include <vector> |
21 | 25 |
|
22 | | -typedef std::map<int, uint256> MapCheckpoints; |
23 | | - |
24 | | -struct CCheckpointData { |
25 | | - MapCheckpoints mapCheckpoints; |
26 | | - |
27 | | - int GetHeight() const { |
28 | | - const auto& final_checkpoint = mapCheckpoints.rbegin(); |
29 | | - return final_checkpoint->first /* height */; |
30 | | - } |
31 | | -}; |
32 | | - |
33 | | -struct AssumeutxoHash : public BaseHash<uint256> { |
34 | | - explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {} |
35 | | -}; |
36 | | - |
37 | | -struct EvoSnapshotHash : public BaseHash<uint256> { |
38 | | - explicit EvoSnapshotHash(const uint256& hash) : BaseHash(hash) {} |
39 | | -}; |
40 | | - |
41 | | -/** |
42 | | - * Holds configuration for use during UTXO snapshot load and validation. The contents |
43 | | - * here are security critical, since they dictate which UTXO snapshots are recognized |
44 | | - * as valid. |
45 | | - */ |
46 | | -struct AssumeutxoData { |
47 | | - //! The expected hash of the deserialized UTXO set. |
48 | | - const AssumeutxoHash hash_serialized; |
49 | | - |
50 | | - //! The expected single-SHA256 hash of the canonical Dash evo section. |
51 | | - const EvoSnapshotHash evo_hash; |
52 | | - |
53 | | - //! Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex(). |
54 | | - //! |
55 | | - //! We need to hardcode the value here because this is computed cumulatively using block data, |
56 | | - //! which we do not necessarily have at the time of snapshot load. |
57 | | - const unsigned int nChainTx; |
58 | | -}; |
59 | | - |
60 | | -using MapAssumeutxo = std::map<int, const AssumeutxoData>; |
61 | | - |
62 | | -/** |
63 | | - * Holds various statistics on transactions within a chain. Used to estimate |
64 | | - * verification progress during chain sync. |
65 | | - * |
66 | | - * See also: CChainParams::TxData, GuessVerificationProgress. |
67 | | - */ |
68 | | -struct ChainTxData { |
69 | | - int64_t nTime; |
70 | | - int64_t nTxCount; |
71 | | - double dTxRate; |
72 | | -}; |
73 | | - |
74 | | -/** |
75 | | - * CChainParams defines various tweakable parameters of a given instance of the |
76 | | - * Dash system. |
77 | | - */ |
78 | | -class CChainParams |
79 | | -{ |
80 | | -public: |
81 | | - enum Base58Type { |
82 | | - PUBKEY_ADDRESS, |
83 | | - SCRIPT_ADDRESS, |
84 | | - SECRET_KEY, // BIP16 |
85 | | - EXT_PUBLIC_KEY, // BIP32 |
86 | | - EXT_SECRET_KEY, // BIP32 |
87 | | - |
88 | | - MAX_BASE58_TYPES |
89 | | - }; |
90 | | - |
91 | | - const Consensus::Params& GetConsensus() const { return consensus; } |
92 | | - const CMessageHeader::MessageStartChars& MessageStart() const { return pchMessageStart; } |
93 | | - uint16_t GetDefaultPort() const { return nDefaultPort; } |
94 | | - uint16_t GetDefaultPort(Network net) const |
95 | | - { |
96 | | - return net == NET_I2P ? I2P_SAM31_PORT : GetDefaultPort(); |
97 | | - } |
98 | | - uint16_t GetDefaultPort(const std::string& addr) const |
99 | | - { |
100 | | - CNetAddr a; |
101 | | - return a.SetSpecial(addr) ? GetDefaultPort(a.GetNetwork()) : GetDefaultPort(); |
102 | | - } |
103 | | - uint16_t GetDefaultPlatformP2PPort() const { return nDefaultPlatformP2PPort; } |
104 | | - uint16_t GetDefaultPlatformHTTPPort() const { return nDefaultPlatformHTTPPort; } |
105 | | - |
106 | | - const CBlock& GenesisBlock() const { return genesis; } |
107 | | - const CBlock& DevNetGenesisBlock() const { return devnetGenesis; } |
108 | | - /** Default value for -checkmempool and -checkblockindex argument */ |
109 | | - bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; } |
110 | | - /** Require addresses specified with "-externalip" parameter to be routable */ |
111 | | - bool RequireRoutableExternalIP() const { return fRequireRoutableExternalIP; } |
112 | | - /** If this chain allows time to be mocked */ |
113 | | - bool IsMockableChain() const { return m_is_mockable_chain; } |
114 | | - /** If this chain is exclusively used for testing */ |
115 | | - bool IsTestChain() const { return m_is_test_chain; } |
116 | | - uint64_t PruneAfterHeight() const { return nPruneAfterHeight; } |
117 | | - /** Minimum free space (in GB) needed for data directory */ |
118 | | - uint64_t AssumedBlockchainSize() const { return m_assumed_blockchain_size; } |
119 | | - /** Minimum free space (in GB) needed for data directory when pruned; Does not include prune target*/ |
120 | | - uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; } |
121 | | - /** Whether it is possible to mine blocks on demand (no retargeting) */ |
122 | | - bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; } |
123 | | - /** Allow multiple addresses to be selected from the same network group (e.g. 192.168.x.x) */ |
124 | | - bool AllowMultipleAddressesFromGroup() const { return fAllowMultipleAddressesFromGroup; } |
125 | | - /** How long to wait until we allow retrying of a LLMQ connection */ |
126 | | - int LLMQConnectionRetryTimeout() const { return nLLMQConnectionRetryTimeout; } |
127 | | - /** Return the network string */ |
128 | | - std::string NetworkIDString() const { return strNetworkID; } |
129 | | - /** Return the list of hostnames to look up for DNS seeds */ |
130 | | - const std::vector<std::string>& DNSSeeds() const { return vSeeds; } |
131 | | - const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; } |
132 | | - /** DIP-18 Platform address bech32m HRP: "dash" on mainnet, "tdash" on test chains */ |
133 | | - const std::string& Bech32PlatformHRP() const { return bech32_platform_hrp; } |
134 | | - int ExtCoinType() const { return nExtCoinType; } |
135 | | - const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; } |
136 | | - const CCheckpointData& Checkpoints() const { return checkpointData; } |
137 | | - |
138 | | - //! Get allowed assumeutxo configuration. |
139 | | - //! @see ChainstateManager |
140 | | - const MapAssumeutxo& Assumeutxo() const { return m_assumeutxo_data; } |
141 | | - |
142 | | - const ChainTxData& TxData() const { return chainTxData; } |
143 | | - void UpdateDIP3Parameters(int nActivationHeight, int nEnforcementHeight); |
144 | | - void UpdateDIP8Parameters(int nActivationHeight); |
145 | | - void UpdateBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock); |
146 | | - void UpdateLLMQInstantSend(Consensus::LLMQType llmqType); |
147 | | - /** |
148 | | - * Validate params for Masternodes EHF |
149 | | - * |
150 | | - * @param[in] nBit The version bit to update |
151 | | - * @param[in] timePast The block time to validate if release is already time-outed |
152 | | - * @return Whether params are legit and params are updated (if release is known) |
153 | | - */ |
154 | | - bool IsValidMNActivation(int nBit, int64_t timePast) const; |
155 | | - int PoolMinParticipants() const { return nPoolMinParticipants; } |
156 | | - int PoolMaxParticipants() const { return nPoolMaxParticipants; } |
157 | | - int FulfilledRequestExpireTime() const { return nFulfilledRequestExpireTime; } |
158 | | - const std::string& SporkAddress() const { return strSporkAddress; } |
159 | | - int CreditPoolPeriodBlocks() const { return nCreditPoolPeriodBlocks; } |
160 | | - [[nodiscard]] std::optional<Consensus::LLMQParams> GetLLMQ(Consensus::LLMQType llmqType) const; |
161 | | - |
162 | | -protected: |
163 | | - CChainParams() {} |
164 | | - |
165 | | - Consensus::Params consensus; |
166 | | - CMessageHeader::MessageStartChars pchMessageStart; |
167 | | - uint16_t nDefaultPort; |
168 | | - uint64_t nPruneAfterHeight; |
169 | | - uint64_t m_assumed_blockchain_size; |
170 | | - uint64_t m_assumed_chain_state_size; |
171 | | - std::vector<std::string> vSeeds; |
172 | | - std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES]; |
173 | | - std::string bech32_platform_hrp; |
174 | | - int nExtCoinType; |
175 | | - std::string strNetworkID; |
176 | | - CBlock genesis; |
177 | | - CBlock devnetGenesis; |
178 | | - std::vector<uint8_t> vFixedSeeds; |
179 | | - bool fDefaultConsistencyChecks; |
180 | | - bool fRequireRoutableExternalIP; |
181 | | - bool m_is_test_chain; |
182 | | - bool fAllowMultipleAddressesFromGroup; |
183 | | - bool m_is_mockable_chain; |
184 | | - int nLLMQConnectionRetryTimeout; |
185 | | - CCheckpointData checkpointData; |
186 | | - MapAssumeutxo m_assumeutxo_data; |
187 | | - ChainTxData chainTxData; |
188 | | - int nPoolMinParticipants; |
189 | | - int nPoolMaxParticipants; |
190 | | - int nFulfilledRequestExpireTime; |
191 | | - std::string strSporkAddress; |
192 | | - uint16_t nDefaultPlatformP2PPort; |
193 | | - uint16_t nDefaultPlatformHTTPPort; |
194 | | - /// The number of blocks the credit pool tracks; 576 (one day) on mainnet, reduced on regtest |
195 | | - int nCreditPoolPeriodBlocks; |
196 | | - |
197 | | - void AddLLMQ(Consensus::LLMQType llmqType); |
198 | | -}; |
199 | | - |
200 | 26 | /** |
201 | 27 | * Creates and returns a std::unique_ptr<CChainParams> of the chosen chain. |
202 | 28 | * @returns a CChainParams* of the chosen chain. |
|
0 commit comments