LCOV - code coverage report
Current view: top level - src/consensus - params.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 38 39 97.4 %
Date: 2026-06-25 07:23:43 Functions: 12 12 100.0 %

          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_CONSENSUS_PARAMS_H
       7             : #define BITCOIN_CONSENSUS_PARAMS_H
       8             : 
       9             : #include <uint256.h>
      10             : #include <llmq/params.h>
      11             : 
      12             : #include <limits>
      13             : #include <vector>
      14             : 
      15             : namespace Consensus {
      16             : 
      17             : /**
      18             :  * A buried deployment is one where the height of the activation has been hardcoded into
      19             :  * the client implementation long after the consensus change has activated. See BIP 90.
      20             :  */
      21             : enum BuriedDeployment : int16_t {
      22             :     // buried deployments get negative values to avoid overlap with DeploymentPos
      23             :     DEPLOYMENT_HEIGHTINCB = std::numeric_limits<int16_t>::min(),
      24             :     DEPLOYMENT_DERSIG,
      25             :     DEPLOYMENT_CLTV,
      26             :     DEPLOYMENT_BIP147,
      27             :     DEPLOYMENT_CSV,
      28             :     DEPLOYMENT_DIP0001,
      29             :     DEPLOYMENT_DIP0003,
      30             :     DEPLOYMENT_DIP0008,
      31             :     DEPLOYMENT_DIP0020,
      32             :     DEPLOYMENT_DIP0024,
      33             :     DEPLOYMENT_BRR,
      34             :     DEPLOYMENT_V19,
      35             :     DEPLOYMENT_V20,
      36             :     DEPLOYMENT_MN_RR,
      37             :     DEPLOYMENT_WITHDRAWALS,
      38             : };
      39    20835270 : constexpr bool ValidDeployment(BuriedDeployment dep) { return dep <= DEPLOYMENT_WITHDRAWALS; }
      40             : 
      41             : enum DeploymentPos : uint16_t {
      42             :     DEPLOYMENT_TESTDUMMY,
      43             :     DEPLOYMENT_V24,         // Deployment of doubling withdrawal limit, extended addresses
      44             :     // NOTE: Also add new deployments to VersionBitsDeploymentInfo in deploymentinfo.cpp
      45             :     MAX_VERSION_BITS_DEPLOYMENTS
      46             : };
      47     1173608 : constexpr bool ValidDeployment(DeploymentPos dep) { return dep < MAX_VERSION_BITS_DEPLOYMENTS; }
      48             : 
      49             : /**
      50             :  * Struct for each individual consensus rule change using BIP9.
      51             :  */
      52       40032 : struct BIP9Deployment {
      53             :     /** Bit position to select the particular bit in nVersion. */
      54       40032 :     int bit{28};
      55             :     /** Start MedianTime for version bits miner confirmation. Can be a date in the past */
      56       40032 :     int64_t nStartTime{NEVER_ACTIVE};
      57             :     /** Timeout/expiry MedianTime for the deployment attempt. */
      58       40032 :     int64_t nTimeout{NEVER_ACTIVE};
      59             :     /** If lock in occurs, delay activation until at least this block
      60             :      *  height.  Note that activation will only occur on a retarget
      61             :      *  boundary.
      62             :      */
      63       40032 :     int min_activation_height{0};
      64             :     /** The number of past blocks (including the block under consideration) to be taken into account for locking in a fork. */
      65       40032 :     int64_t nWindowSize{0};
      66             :     /** A starting number of blocks, in the range of 1..nWindowSize, which must signal for a fork in order to lock it in. */
      67       40032 :     int64_t nThresholdStart{0};
      68             :     /** A minimum number of blocks, in the range of 1..nWindowSize, which must signal for a fork in order to lock it in. */
      69       40032 :     int64_t nThresholdMin{0};
      70             :     /** A coefficient which adjusts the speed a required number of signaling blocks is decreasing from nThresholdStart to nThresholdMin at with each period. */
      71       40032 :     int64_t nFalloffCoeff{0};
      72             :     /** This value is used for forks activated by masternodes.
      73             :       * false means it is a regular fork, no masternodes confirmation is needed.
      74             :       * true means that a signalling of masternodes is expected first to determine a height when miners signals are matter.
      75             :       */
      76       40032 :     bool useEHF{false};
      77             : 
      78             :     /** Constant for nTimeout very far in the future. */
      79             :     static constexpr int64_t NO_TIMEOUT = std::numeric_limits<int64_t>::max();
      80             : 
      81             :     /** Special value for nStartTime indicating that the deployment is always active.
      82             :      *  This is useful for testing, as it means tests don't need to deal with the activation
      83             :      *  process (which takes at least 3 BIP9 intervals). Only tests that specifically test the
      84             :      *  behaviour during activation cannot use this. */
      85             :     static constexpr int64_t ALWAYS_ACTIVE = -1;
      86             : 
      87             :     /** Special value for nStartTime indicating that the deployment is never active.
      88             :      *  This is useful for integrating the code changes for a new feature
      89             :      *  prior to deploying it on some or all networks. */
      90             :     static constexpr int64_t NEVER_ACTIVE = -2;
      91             : };
      92             : 
      93             : /**
      94             :  * Parameters that influence chain consensus.
      95             :  */
      96       20016 : struct Params {
      97             :     uint256 hashGenesisBlock;
      98             :     uint256 hashDevnetGenesisBlock;
      99             :     int nSubsidyHalvingInterval;
     100             :     /** Block height at which BIP16 becomes active */
     101             :     int nMasternodePaymentsStartBlock;
     102             :     int nMasternodePaymentsIncreaseBlock;
     103             :     int nMasternodePaymentsIncreasePeriod; // in blocks
     104             :     int nInstantSendConfirmationsRequired; // in blocks
     105             :     int nInstantSendKeepLock; // in blocks
     106             :     int nBudgetPaymentsStartBlock;
     107             :     int nBudgetPaymentsCycleBlocks;
     108             :     int nBudgetPaymentsWindowBlocks;
     109             :     int nSuperblockStartBlock;
     110             :     uint256 nSuperblockStartHash;
     111             :     int nSuperblockCycle; // in blocks
     112             :     int nSuperblockMaturityWindow; // in blocks
     113             :     int nGovernanceMinQuorum; // Min absolute vote count to trigger an action
     114             :     int nGovernanceFilterElements;
     115             :     int nMasternodeMinimumConfirmations;
     116             :     /** Block height and hash at which BIP34 becomes active */
     117             :     int BIP34Height;
     118             :     uint256 BIP34Hash;
     119             :     /** Block height at which BIP65 becomes active */
     120             :     int BIP65Height;
     121             :     /** Block height at which BIP66 becomes active */
     122             :     int BIP66Height;
     123             :     // Deployment of BIP147 (NULLDUMMY)
     124             :     int BIP147Height;
     125             :     /** Block height at which CSV (BIP68, BIP112 and BIP113) becomes active */
     126             :     int CSVHeight;
     127             :     /** Block height at which DIP0001 becomes active */
     128             :     int DIP0001Height;
     129             :     /** Block height at which DIP0002 and DIP0003 (txv3 and deterministic MN lists) becomes active */
     130             :     int DIP0003Height;
     131             :     /** Block height at which DIP0003 becomes enforced */
     132             :     int DIP0003EnforcementHeight;
     133             :     uint256 DIP0003EnforcementHash;
     134             :     /** Block height at which DIP0008 becomes active */
     135             :     int DIP0008Height;
     136             :     /** Block height at which BRR (Block Reward Reallocation) becomes active */
     137             :     int BRRHeight;
     138             :     /** Block height at which DIP0020, DIP0021 and LLMQ_100_67 quorums become active */
     139             :     int DIP0020Height;
     140             :     /** Block height at which DIP0024 (Quorum Rotation) and decreased governance proposal fee becomes active */
     141             :     int DIP0024Height;
     142             :     /** Block height at which the first DIP0024 quorum was mined */
     143             :     int DIP0024QuorumsHeight;
     144             :     /** Block height at which V19 (Basic BLS and EvoNodes) becomes active */
     145             :     int V19Height;
     146             :     /** Block height at which V20 (Deployment of EHF, LLMQ Randomness Beacon) becomes active */
     147             :     int V20Height;
     148             :     /** Block height at which MN_RR (Deployment of Masternode Reward Location Reallocation) becomes active */
     149             :     int MN_RRHeight;
     150             :     /** Block height at which WITHDRAWALS (Deployment of quorum fix and higher limits for withdrawals) becomes active */
     151             :     int WithdrawalsHeight;
     152             :     /** Don't warn about unknown BIP 9 activations below this height.
     153             :      * This prevents us from warning about the CSV and DIP activations. */
     154             :     int MinBIP9WarningHeight;
     155             :     /**
     156             :      * Minimum blocks including miner confirmation of the total of nMinerConfirmationWindow blocks in a retargeting period,
     157             :      * (nPowTargetTimespan / nPowTargetSpacing) which is also used for BIP9 deployments.
     158             :      * Default BIP9Deployment::nThresholdStart value for deployments where it's not specified and for unknown deployments.
     159             :      * Examples: 1916 for 95%, 1512 for testchains.
     160             :      */
     161             :     uint32_t nRuleChangeActivationThreshold;
     162             :     // Default BIP9Deployment::nWindowSize value for deployments where it's not specified and for unknown deployments.
     163             :     uint32_t nMinerConfirmationWindow;
     164             :     BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS];
     165             :     /** Proof of work parameters */
     166             :     uint256 powLimit;
     167             :     bool fPowAllowMinDifficultyBlocks;
     168             :     bool fPowNoRetargeting;
     169             :     int64_t nPowTargetSpacing;
     170             :     int64_t nPowTargetTimespan;
     171             :     int nPowKGWHeight;
     172             :     int nPowDGWHeight;
     173    96622972 :     int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }
     174             :     /** The best chain should have at least this much work */
     175             :     uint256 nMinimumChainWork;
     176             :     /** By default assume that the signatures in ancestors of this block are valid */
     177             :     uint256 defaultAssumeValid;
     178             : 
     179             :     /** these parameters are only used on devnet and can be configured from the outside */
     180       20016 :     int nMinimumDifficultyBlocks{0};
     181       20016 :     int nHighSubsidyBlocks{0};
     182       20016 :     int nHighSubsidyFactor{1};
     183             : 
     184             :     std::vector<LLMQParams> llmqs;
     185             :     LLMQType llmqTypeChainLocks;
     186       20016 :     LLMQType llmqTypeDIP0024InstantSend{LLMQType::LLMQ_NONE};
     187       20016 :     LLMQType llmqTypePlatform{LLMQType::LLMQ_NONE};
     188       20016 :     LLMQType llmqTypeMnhf{LLMQType::LLMQ_NONE};
     189             : 
     190    20859194 :     int DeploymentHeight(BuriedDeployment dep) const
     191             :     {
     192    20859194 :         switch (dep) {
     193             :         case DEPLOYMENT_HEIGHTINCB:
     194      380604 :             return BIP34Height;
     195             :         case DEPLOYMENT_DERSIG:
     196      432062 :             return BIP66Height;
     197             :         case DEPLOYMENT_CLTV:
     198      432064 :             return BIP65Height;
     199             :         case DEPLOYMENT_BIP147:
     200      431550 :             return BIP147Height;
     201             :         case DEPLOYMENT_CSV:
     202     1108052 :             return CSVHeight;
     203             :         case DEPLOYMENT_DIP0001:
     204     1564189 :             return DIP0001Height;
     205             :         case DEPLOYMENT_DIP0003:
     206     5943381 :             return DIP0003Height;
     207             :         case DEPLOYMENT_DIP0008:
     208      468101 :             return DIP0008Height;
     209             :         case DEPLOYMENT_DIP0020:
     210       45412 :             return DIP0020Height;
     211             :         case DEPLOYMENT_DIP0024:
     212     4646982 :             return DIP0024Height;
     213             :         case DEPLOYMENT_BRR:
     214       45408 :             return BRRHeight;
     215             :         case DEPLOYMENT_V19:
     216      800599 :             return V19Height;
     217             :         case DEPLOYMENT_V20:
     218     3565791 :             return V20Height;
     219             :         case DEPLOYMENT_MN_RR:
     220      820373 :             return MN_RRHeight;
     221             :         case DEPLOYMENT_WITHDRAWALS:
     222      174626 :             return WithdrawalsHeight;
     223             :         } // no default case, so the compiler can warn about missing cases
     224           0 :         return std::numeric_limits<int>::max();
     225    20859194 :     }
     226             : };
     227             : 
     228             : } // namespace Consensus
     229             : 
     230             : #endif // BITCOIN_CONSENSUS_PARAMS_H

Generated by: LCOV version 1.16