LCOV - code coverage report
Current view: top level - src - chainparams.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 0.0 % 78 0
Test Date: 2024-11-22 13:43:01 Functions: 0.0 % 5 0
Branches: 0.0 % 142 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (c) 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                 :             : #include <chainparams.h>
       7                 :             : 
       8                 :             : #include <chainparamsbase.h>
       9                 :             : #include <common/args.h>
      10                 :             : #include <consensus/params.h>
      11                 :             : #include <deploymentinfo.h>
      12                 :             : #include <logging.h>
      13                 :             : #include <tinyformat.h>
      14                 :             : #include <util/chaintype.h>
      15                 :             : #include <util/strencodings.h>
      16                 :             : #include <util/string.h>
      17                 :             : 
      18                 :             : #include <cassert>
      19                 :             : #include <cstdint>
      20                 :             : #include <limits>
      21                 :             : #include <stdexcept>
      22                 :             : #include <vector>
      23                 :             : 
      24                 :             : using util::SplitString;
      25                 :             : 
      26                 :           0 : void ReadSigNetArgs(const ArgsManager& args, CChainParams::SigNetOptions& options)
      27                 :             : {
      28   [ #  #  #  # ]:           0 :     if (args.IsArgSet("-signetseednode")) {
      29         [ #  # ]:           0 :         options.seeds.emplace(args.GetArgs("-signetseednode"));
      30                 :             :     }
      31   [ #  #  #  # ]:           0 :     if (args.IsArgSet("-signetchallenge")) {
      32         [ #  # ]:           0 :         const auto signet_challenge = args.GetArgs("-signetchallenge");
      33         [ #  # ]:           0 :         if (signet_challenge.size() != 1) {
      34         [ #  # ]:           0 :             throw std::runtime_error("-signetchallenge cannot be multiple values.");
      35                 :             :         }
      36         [ #  # ]:           0 :         const auto val{TryParseHex<uint8_t>(signet_challenge[0])};
      37         [ #  # ]:           0 :         if (!val) {
      38   [ #  #  #  # ]:           0 :             throw std::runtime_error(strprintf("-signetchallenge must be hex, not '%s'.", signet_challenge[0]));
      39                 :             :         }
      40         [ #  # ]:           0 :         options.challenge.emplace(*val);
      41                 :           0 :     }
      42                 :           0 : }
      43                 :             : 
      44                 :           0 : void ReadRegTestArgs(const ArgsManager& args, CChainParams::RegTestOptions& options)
      45                 :             : {
      46   [ #  #  #  # ]:           0 :     if (auto value = args.GetBoolArg("-fastprune")) options.fastprune = *value;
      47   [ #  #  #  # ]:           0 :     if (HasTestOption(args, "bip94")) options.enforce_bip94 = true;
      48                 :             : 
      49   [ #  #  #  # ]:           0 :     for (const std::string& arg : args.GetArgs("-testactivationheight")) {
      50                 :           0 :         const auto found{arg.find('@')};
      51         [ #  # ]:           0 :         if (found == std::string::npos) {
      52   [ #  #  #  # ]:           0 :             throw std::runtime_error(strprintf("Invalid format (%s) for -testactivationheight=name@height.", arg));
      53                 :             :         }
      54                 :             : 
      55         [ #  # ]:           0 :         const auto value{arg.substr(found + 1)};
      56                 :           0 :         int32_t height;
      57   [ #  #  #  #  :           0 :         if (!ParseInt32(value, &height) || height < 0 || height >= std::numeric_limits<int>::max()) {
             #  #  #  # ]
      58   [ #  #  #  # ]:           0 :             throw std::runtime_error(strprintf("Invalid height value (%s) for -testactivationheight=name@height.", arg));
      59                 :             :         }
      60                 :             : 
      61         [ #  # ]:           0 :         const auto deployment_name{arg.substr(0, found)};
      62   [ #  #  #  # ]:           0 :         if (const auto buried_deployment = GetBuriedDeployment(deployment_name)) {
      63         [ #  # ]:           0 :             options.activation_heights[*buried_deployment] = height;
      64                 :             :         } else {
      65   [ #  #  #  # ]:           0 :             throw std::runtime_error(strprintf("Invalid name (%s) for -testactivationheight=name@height.", arg));
      66                 :             :         }
      67                 :           0 :     }
      68                 :             : 
      69   [ #  #  #  # ]:           0 :     if (!args.IsArgSet("-vbparams")) return;
      70                 :             : 
      71   [ #  #  #  # ]:           0 :     for (const std::string& strDeployment : args.GetArgs("-vbparams")) {
      72         [ #  # ]:           0 :         std::vector<std::string> vDeploymentParams = SplitString(strDeployment, ':');
      73   [ #  #  #  # ]:           0 :         if (vDeploymentParams.size() < 3 || 4 < vDeploymentParams.size()) {
      74         [ #  # ]:           0 :             throw std::runtime_error("Version bits parameters malformed, expecting deployment:start:end[:min_activation_height]");
      75                 :             :         }
      76                 :           0 :         CChainParams::VersionBitsParameters vbparams{};
      77   [ #  #  #  # ]:           0 :         if (!ParseInt64(vDeploymentParams[1], &vbparams.start_time)) {
      78   [ #  #  #  # ]:           0 :             throw std::runtime_error(strprintf("Invalid nStartTime (%s)", vDeploymentParams[1]));
      79                 :             :         }
      80   [ #  #  #  # ]:           0 :         if (!ParseInt64(vDeploymentParams[2], &vbparams.timeout)) {
      81   [ #  #  #  # ]:           0 :             throw std::runtime_error(strprintf("Invalid nTimeout (%s)", vDeploymentParams[2]));
      82                 :             :         }
      83         [ #  # ]:           0 :         if (vDeploymentParams.size() >= 4) {
      84   [ #  #  #  # ]:           0 :             if (!ParseInt32(vDeploymentParams[3], &vbparams.min_activation_height)) {
      85   [ #  #  #  # ]:           0 :                 throw std::runtime_error(strprintf("Invalid min_activation_height (%s)", vDeploymentParams[3]));
      86                 :             :             }
      87                 :             :         } else {
      88                 :           0 :             vbparams.min_activation_height = 0;
      89                 :             :         }
      90                 :           0 :         bool found = false;
      91         [ #  # ]:           0 :         for (int j=0; j < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; ++j) {
      92         [ #  # ]:           0 :             if (vDeploymentParams[0] == VersionBitsDeploymentInfo[j].name) {
      93         [ #  # ]:           0 :                 options.version_bits_parameters[Consensus::DeploymentPos(j)] = vbparams;
      94                 :           0 :                 found = true;
      95         [ #  # ]:           0 :                 LogPrintf("Setting version bits activation parameters for %s to start=%ld, timeout=%ld, min_activation_height=%d\n", vDeploymentParams[0], vbparams.start_time, vbparams.timeout, vbparams.min_activation_height);
      96                 :             :                 break;
      97                 :             :             }
      98                 :             :         }
      99                 :           0 :         if (!found) {
     100   [ #  #  #  # ]:           0 :             throw std::runtime_error(strprintf("Invalid deployment (%s)", vDeploymentParams[0]));
     101                 :             :         }
     102                 :           0 :     }
     103                 :             : }
     104                 :             : 
     105                 :             : static std::unique_ptr<const CChainParams> globalChainParams;
     106                 :             : 
     107                 :           0 : const CChainParams &Params() {
     108         [ #  # ]:           0 :     assert(globalChainParams);
     109                 :           0 :     return *globalChainParams;
     110                 :             : }
     111                 :             : 
     112                 :           0 : std::unique_ptr<const CChainParams> CreateChainParams(const ArgsManager& args, const ChainType chain)
     113                 :             : {
     114   [ #  #  #  #  :           0 :     switch (chain) {
                   #  # ]
     115                 :           0 :     case ChainType::MAIN:
     116                 :           0 :         return CChainParams::Main();
     117                 :           0 :     case ChainType::TESTNET:
     118                 :           0 :         return CChainParams::TestNet();
     119                 :           0 :     case ChainType::TESTNET4:
     120                 :           0 :         return CChainParams::TestNet4();
     121                 :           0 :     case ChainType::SIGNET: {
     122                 :           0 :         auto opts = CChainParams::SigNetOptions{};
     123         [ #  # ]:           0 :         ReadSigNetArgs(args, opts);
     124         [ #  # ]:           0 :         return CChainParams::SigNet(opts);
     125                 :           0 :     }
     126                 :           0 :     case ChainType::REGTEST: {
     127         [ #  # ]:           0 :         auto opts = CChainParams::RegTestOptions{};
     128         [ #  # ]:           0 :         ReadRegTestArgs(args, opts);
     129         [ #  # ]:           0 :         return CChainParams::RegTest(opts);
     130                 :           0 :     }
     131                 :             :     }
     132                 :           0 :     assert(false);
     133                 :             : }
     134                 :             : 
     135                 :           0 : void SelectParams(const ChainType chain)
     136                 :             : {
     137                 :           0 :     SelectBaseParams(chain);
     138                 :           0 :     globalChainParams = CreateChainParams(gArgs, chain);
     139                 :           0 : }
        

Generated by: LCOV version 2.0-1