LCOV - code coverage report
Current view: top level - src/consensus - params.h (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 17 21 81.0 %
Date: 2023-11-06 23:13:05 Functions: 5 8 62.5 %
Branches: 8 12 66.7 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2009-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                 :            : #ifndef BITCOIN_CONSENSUS_PARAMS_H
       7                 :            : #define BITCOIN_CONSENSUS_PARAMS_H
       8                 :            : 
       9                 :            : #include <uint256.h>
      10                 :            : 
      11                 :            : #include <chrono>
      12                 :            : #include <limits>
      13                 :            : #include <map>
      14                 :            : #include <vector>
      15                 :            : 
      16                 :            : namespace Consensus {
      17                 :            : 
      18                 :            : /**
      19                 :            :  * A buried deployment is one where the height of the activation has been hardcoded into
      20                 :            :  * the client implementation long after the consensus change has activated. See BIP 90.
      21                 :            :  */
      22                 :            : enum BuriedDeployment : int16_t {
      23                 :            :     // buried deployments get negative values to avoid overlap with DeploymentPos
      24                 :            :     DEPLOYMENT_HEIGHTINCB = std::numeric_limits<int16_t>::min(),
      25                 :            :     DEPLOYMENT_CLTV,
      26                 :            :     DEPLOYMENT_DERSIG,
      27                 :            :     DEPLOYMENT_CSV,
      28                 :            :     DEPLOYMENT_SEGWIT,
      29                 :            : };
      30                 :       3601 : constexpr bool ValidDeployment(BuriedDeployment dep) { return dep <= DEPLOYMENT_SEGWIT; }
      31                 :            : 
      32                 :            : enum DeploymentPos : uint16_t {
      33                 :            :     DEPLOYMENT_TESTDUMMY,
      34                 :            :     DEPLOYMENT_TAPROOT, // Deployment of Schnorr/Taproot (BIPs 340-342)
      35                 :            :     // NOTE: Also add new deployments to VersionBitsDeploymentInfo in deploymentinfo.cpp
      36                 :            :     MAX_VERSION_BITS_DEPLOYMENTS
      37                 :            : };
      38                 :          0 : constexpr bool ValidDeployment(DeploymentPos dep) { return dep < MAX_VERSION_BITS_DEPLOYMENTS; }
      39                 :            : 
      40                 :            : /**
      41                 :            :  * Struct for each individual consensus rule change using BIP9.
      42                 :            :  */
      43                 :         10 : struct BIP9Deployment {
      44                 :            :     /** Bit position to select the particular bit in nVersion. */
      45                 :         10 :     int bit{28};
      46                 :            :     /** Start MedianTime for version bits miner confirmation. Can be a date in the past */
      47                 :         10 :     int64_t nStartTime{NEVER_ACTIVE};
      48                 :            :     /** Timeout/expiry MedianTime for the deployment attempt. */
      49                 :         10 :     int64_t nTimeout{NEVER_ACTIVE};
      50                 :            :     /** If lock in occurs, delay activation until at least this block
      51                 :            :      *  height.  Note that activation will only occur on a retarget
      52                 :            :      *  boundary.
      53                 :            :      */
      54                 :         10 :     int min_activation_height{0};
      55                 :            : 
      56                 :            :     /** Constant for nTimeout very far in the future. */
      57                 :            :     static constexpr int64_t NO_TIMEOUT = std::numeric_limits<int64_t>::max();
      58                 :            : 
      59                 :            :     /** Special value for nStartTime indicating that the deployment is always active.
      60                 :            :      *  This is useful for testing, as it means tests don't need to deal with the activation
      61                 :            :      *  process (which takes at least 3 BIP9 intervals). Only tests that specifically test the
      62                 :            :      *  behaviour during activation cannot use this. */
      63                 :            :     static constexpr int64_t ALWAYS_ACTIVE = -1;
      64                 :            : 
      65                 :            :     /** Special value for nStartTime indicating that the deployment is never active.
      66                 :            :      *  This is useful for integrating the code changes for a new feature
      67                 :            :      *  prior to deploying it on some or all networks. */
      68                 :            :     static constexpr int64_t NEVER_ACTIVE = -2;
      69                 :            : };
      70                 :            : 
      71                 :            : /**
      72                 :            :  * Parameters that influence chain consensus.
      73                 :            :  */
      74 [ +  - ][ +  - ]:          5 : struct Params {
                 [ +  - ]
      75                 :            :     uint256 hashGenesisBlock;
      76                 :            :     int nSubsidyHalvingInterval;
      77                 :            :     /**
      78                 :            :      * Hashes of blocks that
      79                 :            :      * - are known to be consensus valid, and
      80                 :            :      * - buried in the chain, and
      81                 :            :      * - fail if the default script verify flags are applied.
      82                 :            :      */
      83                 :            :     std::map<uint256, uint32_t> script_flag_exceptions;
      84                 :            :     /** Block height and hash at which BIP34 becomes active */
      85                 :            :     int BIP34Height;
      86                 :            :     uint256 BIP34Hash;
      87                 :            :     /** Block height at which BIP65 becomes active */
      88                 :            :     int BIP65Height;
      89                 :            :     /** Block height at which BIP66 becomes active */
      90                 :            :     int BIP66Height;
      91                 :            :     /** Block height at which CSV (BIP68, BIP112 and BIP113) becomes active */
      92                 :            :     int CSVHeight;
      93                 :            :     /** Block height at which Segwit (BIP141, BIP143 and BIP147) becomes active.
      94                 :            :      * Note that segwit v0 script rules are enforced on all blocks except the
      95                 :            :      * BIP 16 exception blocks. */
      96                 :            :     int SegwitHeight;
      97                 :            :     /** Don't warn about unknown BIP 9 activations below this height.
      98                 :            :      * This prevents us from warning about the CSV and segwit activations. */
      99                 :            :     int MinBIP9WarningHeight;
     100                 :            :     /**
     101                 :            :      * Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period,
     102                 :            :      * (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments.
     103                 :            :      * Examples: 1916 for 95%, 1512 for testchains.
     104                 :            :      */
     105                 :            :     uint32_t nRuleChangeActivationThreshold;
     106                 :            :     uint32_t nMinerConfirmationWindow;
     107                 :            :     BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS];
     108                 :            :     /** Proof of work parameters */
     109                 :            :     uint256 powLimit;
     110                 :            :     bool fPowAllowMinDifficultyBlocks;
     111                 :            :     bool fPowNoRetargeting;
     112                 :            :     int64_t nPowTargetSpacing;
     113                 :            :     int64_t nPowTargetTimespan;
     114                 :          0 :     std::chrono::seconds PowTargetSpacing() const
     115                 :            :     {
     116                 :          0 :         return std::chrono::seconds{nPowTargetSpacing};
     117                 :            :     }
     118                 :      20700 :     int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
     119                 :            :     /** The best chain should have at least this much work */
     120                 :            :     uint256 nMinimumChainWork;
     121                 :            :     /** By default assume that the signatures in ancestors of this block are valid */
     122                 :            :     uint256 defaultAssumeValid;
     123                 :            : 
     124                 :            :     /**
     125                 :            :      * If true, witness commitments contain a payload equal to a Bitcoin Script solution
     126                 :            :      * to the signet challenge. See BIP325.
     127                 :            :      */
     128                 :          5 :     bool signet_blocks{false};
     129                 :            :     std::vector<uint8_t> signet_challenge;
     130                 :            : 
     131                 :       3601 :     int DeploymentHeight(BuriedDeployment dep) const
     132                 :            :     {
     133   [ +  +  +  +  :       3601 :         switch (dep) {
                   +  - ]
     134                 :            :         case DEPLOYMENT_HEIGHTINCB:
     135                 :        400 :             return BIP34Height;
     136                 :            :         case DEPLOYMENT_CLTV:
     137                 :        400 :             return BIP65Height;
     138                 :            :         case DEPLOYMENT_DERSIG:
     139                 :        400 :             return BIP66Height;
     140                 :            :         case DEPLOYMENT_CSV:
     141                 :       1200 :             return CSVHeight;
     142                 :            :         case DEPLOYMENT_SEGWIT:
     143                 :       1201 :             return SegwitHeight;
     144                 :            :         } // no default case, so the compiler can warn about missing cases
     145                 :          0 :         return std::numeric_limits<int>::max();
     146                 :       3601 :     }
     147                 :            : };
     148                 :            : 
     149                 :            : } // namespace Consensus
     150                 :            : 
     151                 :            : #endif // BITCOIN_CONSENSUS_PARAMS_H

Generated by: LCOV version 1.14