LCOV - code coverage report
Current view: top level - src/kernel - chainparams.h (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 17 31 54.8 %
Date: 2023-11-10 23:46:46 Functions: 18 31 58.1 %
Branches: 1 2 50.0 %

           Branch data     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                 :            : #include <util/vector.h>
      16                 :            : 
      17                 :            : #include <cstdint>
      18                 :            : #include <iterator>
      19                 :            : #include <map>
      20                 :            : #include <memory>
      21                 :            : #include <optional>
      22                 :            : #include <string>
      23                 :            : #include <unordered_map>
      24                 :            : #include <utility>
      25                 :            : #include <vector>
      26                 :            : 
      27                 :            : typedef std::map<int, uint256> MapCheckpoints;
      28                 :            : 
      29                 :          0 : struct CCheckpointData {
      30                 :            :     MapCheckpoints mapCheckpoints;
      31                 :            : 
      32                 :          1 :     int GetHeight() const {
      33                 :          1 :         const auto& final_checkpoint = mapCheckpoints.rbegin();
      34                 :          1 :         return final_checkpoint->first /* height */;
      35                 :            :     }
      36                 :            : };
      37                 :            : 
      38                 :            : struct AssumeutxoHash : public BaseHash<uint256> {
      39                 :          6 :     explicit AssumeutxoHash(const uint256& hash) : BaseHash(hash) {}
      40                 :            : };
      41                 :            : 
      42                 :            : /**
      43                 :            :  * Holds configuration for use during UTXO snapshot load and validation. The contents
      44                 :            :  * here are security critical, since they dictate which UTXO snapshots are recognized
      45                 :            :  * as valid.
      46                 :            :  */
      47                 :            : struct AssumeutxoData {
      48                 :            :     int height;
      49                 :            : 
      50                 :            :     //! The expected hash of the deserialized UTXO set.
      51                 :            :     AssumeutxoHash hash_serialized;
      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                 :            :     unsigned int nChainTx;
      58                 :            : 
      59                 :            :     //! The hash of the base block for this snapshot. Used to refer to assumeutxo data
      60                 :            :     //! prior to having a loaded blockindex.
      61                 :            :     uint256 blockhash;
      62                 :            : };
      63                 :            : 
      64                 :            : /**
      65                 :            :  * Holds various statistics on transactions within a chain. Used to estimate
      66                 :            :  * verification progress during chain sync.
      67                 :            :  *
      68                 :            :  * See also: CChainParams::TxData, GuessVerificationProgress.
      69                 :            :  */
      70                 :            : struct ChainTxData {
      71                 :            :     int64_t nTime;    //!< UNIX timestamp of last known number of transactions
      72                 :            :     int64_t nTxCount; //!< total number of transactions between genesis and that timestamp
      73                 :            :     double dTxRate;   //!< estimated number of transactions per second after that timestamp
      74                 :            : };
      75                 :            : 
      76                 :            : /**
      77                 :            :  * CChainParams defines various tweakable parameters of a given instance of the
      78                 :            :  * Bitcoin system.
      79                 :            :  */
      80                 :          5 : class CChainParams
      81                 :            : {
      82                 :            : public:
      83                 :            :     enum Base58Type {
      84                 :            :         PUBKEY_ADDRESS,
      85                 :            :         SCRIPT_ADDRESS,
      86                 :            :         SECRET_KEY,
      87                 :            :         EXT_PUBLIC_KEY,
      88                 :            :         EXT_SECRET_KEY,
      89                 :            : 
      90                 :            :         MAX_BASE58_TYPES
      91                 :            :     };
      92                 :            : 
      93                 :      11703 :     const Consensus::Params& GetConsensus() const { return consensus; }
      94                 :        301 :     const MessageStartChars& MessageStart() const { return pchMessageStart; }
      95                 :          4 :     uint16_t GetDefaultPort() const { return nDefaultPort; }
      96                 :            : 
      97                 :          2 :     const CBlock& GenesisBlock() const { return genesis; }
      98                 :            :     /** Default value for -checkmempool and -checkblockindex argument */
      99                 :          4 :     bool DefaultConsistencyChecks() const { return fDefaultConsistencyChecks; }
     100                 :            :     /** If this chain is exclusively used for testing */
     101                 :          9 :     bool IsTestChain() const { return m_chain_type != ChainType::MAIN; }
     102                 :            :     /** If this chain allows time to be mocked */
     103                 :          0 :     bool IsMockableChain() const { return m_is_mockable_chain; }
     104                 :          0 :     uint64_t PruneAfterHeight() const { return nPruneAfterHeight; }
     105                 :            :     /** Minimum free space (in GB) needed for data directory */
     106                 :          0 :     uint64_t AssumedBlockchainSize() const { return m_assumed_blockchain_size; }
     107                 :            :     /** Minimum free space (in GB) needed for data directory when pruned; Does not include prune target*/
     108                 :            :     uint64_t AssumedChainStateSize() const { return m_assumed_chain_state_size; }
     109                 :            :     /** Whether it is possible to mine blocks on demand (no retargeting) */
     110                 :        150 :     bool MineBlocksOnDemand() const { return consensus.fPowNoRetargeting; }
     111                 :            :     /** Return the chain type string */
     112                 :          0 :     std::string GetChainTypeString() const { return ChainTypeToString(m_chain_type); }
     113                 :            :     /** Return the chain type */
     114                 :          0 :     ChainType GetChainType() const { return m_chain_type; }
     115                 :            :     /** Return the list of hostnames to look up for DNS seeds */
     116                 :          0 :     const std::vector<std::string>& DNSSeeds() const { return vSeeds; }
     117                 :      33402 :     const std::vector<unsigned char>& Base58Prefix(Base58Type type) const { return base58Prefixes[type]; }
     118                 :          2 :     const std::string& Bech32HRP() const { return bech32_hrp; }
     119                 :          0 :     const std::vector<uint8_t>& FixedSeeds() const { return vFixedSeeds; }
     120                 :        301 :     const CCheckpointData& Checkpoints() const { return checkpointData; }
     121                 :            : 
     122                 :          0 :     std::optional<AssumeutxoData> AssumeutxoForHeight(int height) const
     123                 :            :     {
     124                 :          0 :         return FindFirst(m_assumeutxo_data, [&](const auto& d) { return d.height == height; });
     125                 :            :     }
     126                 :          0 :     std::optional<AssumeutxoData> AssumeutxoForBlockhash(const uint256& blockhash) const
     127                 :            :     {
     128                 :          0 :         return FindFirst(m_assumeutxo_data, [&](const auto& d) { return d.blockhash == blockhash; });
     129                 :            :     }
     130                 :            : 
     131                 :        303 :     const ChainTxData& TxData() const { return chainTxData; }
     132                 :            : 
     133                 :            :     /**
     134                 :            :      * SigNetOptions holds configurations for creating a signet CChainParams.
     135                 :            :      */
     136                 :          0 :     struct SigNetOptions {
     137                 :            :         std::optional<std::vector<uint8_t>> challenge{};
     138                 :            :         std::optional<std::vector<std::string>> seeds{};
     139                 :            :     };
     140                 :            : 
     141                 :            :     /**
     142                 :            :      * VersionBitsParameters holds activation parameters
     143                 :            :      */
     144                 :            :     struct VersionBitsParameters {
     145                 :            :         int64_t start_time;
     146                 :            :         int64_t timeout;
     147                 :            :         int min_activation_height;
     148                 :            :     };
     149                 :            : 
     150                 :            :     /**
     151                 :            :      * RegTestOptions holds configurations for creating a regtest CChainParams.
     152                 :            :      */
     153                 :          0 :     struct RegTestOptions {
     154                 :            :         std::unordered_map<Consensus::DeploymentPos, VersionBitsParameters> version_bits_parameters{};
     155                 :            :         std::unordered_map<Consensus::BuriedDeployment, int> activation_heights{};
     156                 :            :         bool fastprune{false};
     157                 :            :     };
     158                 :            : 
     159                 :            :     static std::unique_ptr<const CChainParams> RegTest(const RegTestOptions& options);
     160                 :            :     static std::unique_ptr<const CChainParams> SigNet(const SigNetOptions& options);
     161                 :            :     static std::unique_ptr<const CChainParams> Main();
     162                 :            :     static std::unique_ptr<const CChainParams> TestNet();
     163                 :            : 
     164                 :            : protected:
     165         [ +  - ]:          5 :     CChainParams() {}
     166                 :            : 
     167                 :            :     Consensus::Params consensus;
     168                 :            :     MessageStartChars pchMessageStart;
     169                 :            :     uint16_t nDefaultPort;
     170                 :            :     uint64_t nPruneAfterHeight;
     171                 :            :     uint64_t m_assumed_blockchain_size;
     172                 :            :     uint64_t m_assumed_chain_state_size;
     173                 :            :     std::vector<std::string> vSeeds;
     174                 :            :     std::vector<unsigned char> base58Prefixes[MAX_BASE58_TYPES];
     175                 :            :     std::string bech32_hrp;
     176                 :            :     ChainType m_chain_type;
     177                 :            :     CBlock genesis;
     178                 :            :     std::vector<uint8_t> vFixedSeeds;
     179                 :            :     bool fDefaultConsistencyChecks;
     180                 :            :     bool m_is_mockable_chain;
     181                 :            :     CCheckpointData checkpointData;
     182                 :            :     std::vector<AssumeutxoData> m_assumeutxo_data;
     183                 :            :     ChainTxData chainTxData;
     184                 :            : };
     185                 :            : 
     186                 :            : #endif // BITCOIN_KERNEL_CHAINPARAMS_H

Generated by: LCOV version 1.14