LCOV - code coverage report
Current view: top level - src/kernel - chainparams.h (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 15 25 60.0 %
Date: 2023-09-26 12:08:55 Functions: 18 28 64.3 %

          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_KERNEL_CHAINPARAMS_H
       7             : #define BITCOIN_KERNEL_CHAINPARAMS_H
       8             : 
       9             : #include <consensus/params.h>
      10             : #include <kernel/messagestartchars.h>
      11             : #include <primitives/block.h>
      12             : #include <uint256.h>
      13             : #include <util/chaintype.h>
      14             : #include <util/hash_type.h>
      15             : 
      16             : #include <cstdint>
      17             : #include <iterator>
      18             : #include <map>
      19             : #include <memory>
      20             : #include <optional>
      21             : #include <string>
      22             : #include <unordered_map>
      23             : #include <utility>
      24             : #include <vector>
      25             : 
      26             : typedef std::map<int, uint256> MapCheckpoints;
      27             : 
      28             : struct CCheckpointData {
      29             :     MapCheckpoints mapCheckpoints;
      30             : 
      31           1 :     int GetHeight() const {
      32           1 :         const auto& final_checkpoint = mapCheckpoints.rbegin();
      33           1 :         return final_checkpoint->first /* height */;
      34             :     }
      35             : };
      36             : 
      37             : struct AssumeutxoHash : public BaseHash<uint256> {
      38           4 :     explicit AssumeutxoHash(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             :     //! Used to populate the nChainTx value, which is used during BlockManager::LoadBlockIndex().
      51             :     //!
      52             :     //! We need to hardcode the value here because this is computed cumulatively using block data,
      53             :     //! which we do not necessarily have at the time of snapshot load.
      54             :     const unsigned int nChainTx;
      55             : };
      56             : 
      57             : using MapAssumeutxo = std::map<int, const AssumeutxoData>;
      58             : 
      59             : /**
      60             :  * Holds various statistics on transactions within a chain. Used to estimate
      61             :  * verification progress during chain sync.
      62             :  *
      63             :  * See also: CChainParams::TxData, GuessVerificationProgress.
      64             :  */
      65             : struct ChainTxData {
      66             :     int64_t nTime;    //!< UNIX timestamp of last known number of transactions
      67             :     int64_t nTxCount; //!< total number of transactions between genesis and that timestamp
      68             :     double dTxRate;   //!< estimated number of transactions per second after that timestamp
      69             : };
      70             : 
      71             : /**
      72             :  * CChainParams defines various tweakable parameters of a given instance of the
      73             :  * Bitcoin system.
      74             :  */
      75           5 : class CChainParams
      76             : {
      77             : public:
      78             :     enum Base58Type {
      79             :         PUBKEY_ADDRESS,
      80             :         SCRIPT_ADDRESS,
      81             :         SECRET_KEY,
      82             :         EXT_PUBLIC_KEY,
      83             :         EXT_SECRET_KEY,
      84             : 
      85             :         MAX_BASE58_TYPES
      86             :     };
      87             : 
      88      124098 :     const Consensus::Params& GetConsensus() const { return consensus; }
      89         401 :     const MessageStartChars& MessageStart() const { return pchMessageStart; }
      90           4 :     uint16_t GetDefaultPort() const { return nDefaultPort; }
      91             : 
      92           2 :     const CBlock& GenesisBlock() const { return genesis; }
      93             :     /** Default value for -checkmempool and -checkblockindex argument */
      94           4 :     bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
      95             :     /** If this chain is exclusively used for testing */
      96        4860 :     bool IsTestChain() const { return m_is_test_chain; }
      97             :     /** If this chain allows time to be mocked */
      98           0 :     bool IsMockableChain() const { return m_is_mockable_chain; }
      99           0 :     uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
     100             :     /** Minimum free space (in GB) needed for data directory */
     101           0 :     uint64_t AssumedBlockchainSize() const { return m_assumed_blockchain_size; }
     102             :     /** Minimum free space (in GB) needed for data directory when pruned; Does not include prune target*/
     103             :     uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; }
     104             :     /** Whether it is possible to mine blocks on demand (no retargeting) */
     105        5059 :     bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; }
     106             :     /** Return the chain type string */
     107           0 :     std::string GetChainTypeString() const { return ChainTypeToString(m_chain_type); }
     108             :     /** Return the chain type */
     109           0 :     ChainType GetChainType() const { return m_chain_type; }
     110             :     /** Return the list of hostnames to look up for DNS seeds */
     111           0 :     const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
     112           0 :     const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
     113           0 :     const std::string& Bech32HRP() const { return bech32_hrp; }
     114           0 :     const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
     115        5260 :     const CCheckpointData& Checkpoints() const { return checkpointData; }
     116             : 
     117             :     //! Get allowed assumeutxo configuration.
     118             :     //! @see ChainstateManager
     119           0 :     const MapAssumeutxo& Assumeutxo() const { return m_assumeutxo_data; }
     120             : 
     121         201 :     const ChainTxData& TxData() const { return chainTxData; }
     122             : 
     123             :     /**
     124             :      * SigNetOptions holds configurations for creating a signet CChainParams.
     125             :      */
     126             :     struct SigNetOptions {
     127             :         std::optional<std::vector<uint8_t>> challenge{};
     128             :         std::optional<std::vector<std::string>> seeds{};
     129             :     };
     130             : 
     131             :     /**
     132             :      * VersionBitsParameters holds activation parameters
     133             :      */
     134             :     struct VersionBitsParameters {
     135             :         int64_t start_time;
     136             :         int64_t timeout;
     137             :         int min_activation_height;
     138             :     };
     139             : 
     140             :     /**
     141             :      * RegTestOptions holds configurations for creating a regtest CChainParams.
     142             :      */
     143             :     struct RegTestOptions {
     144             :         std::unordered_map<Consensus::DeploymentPos, VersionBitsParameters> version_bits_parameters{};
     145             :         std::unordered_map<Consensus::BuriedDeployment, int> activation_heights{};
     146             :         bool fastprune{false};
     147             :     };
     148             : 
     149             :     static std::unique_ptr<const CChainParams> RegTest(const RegTestOptions& options);
     150             :     static std::unique_ptr<const CChainParams> SigNet(const SigNetOptions& options);
     151             :     static std::unique_ptr<const CChainParams> Main();
     152             :     static std::unique_ptr<const CChainParams> TestNet();
     153             : 
     154             : protected:
     155         368 :     CChainParams() {}
     156             : 
     157             :     Consensus::Params consensus;
     158             :     MessageStartChars pchMessageStart;
     159             :     uint16_t nDefaultPort;
     160             :     uint64_t nPruneAfterHeight;
     161             :     uint64_t m_assumed_blockchain_size;
     162             :     uint64_t m_assumed_chain_state_size;
     163             :     std::vector<std::string> vSeeds;
     164             :     std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
     165             :     std::string bech32_hrp;
     166             :     ChainType m_chain_type;
     167             :     CBlock genesis;
     168             :     std::vector<uint8_t> vFixedSeeds;
     169             :     bool fDefaultConsistencyChecks;
     170             :     bool m_is_test_chain;
     171             :     bool m_is_mockable_chain;
     172             :     CCheckpointData checkpointData;
     173             :     MapAssumeutxo m_assumeutxo_data;
     174             :     ChainTxData chainTxData;
     175             : };
     176             : 
     177             : #endif // BITCOIN_KERNEL_CHAINPARAMS_H

Generated by: LCOV version 1.14