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