Inside Bitcoin
Opening the selected file…
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2009-2010 Satoshi Nakamoto2// Copyright (c) 2009-present The Bitcoin Core developers3// Distributed under the MIT software license, see the accompanying4// file COPYING or http://www.opensource.org/licenses/mit-license.php.6#ifndef BITCOIN_CONSENSUS_PARAMS_H7#define BITCOIN_CONSENSUS_PARAMS_H9#include <script/verify_flags.h>10#include <uint256.h>12#include <array>13#include <chrono>14#include <cstdint>15#include <limits>16#include <map>17#include <vector>19namespace Consensus {21/**22* A buried deployment is one where the height of the activation has been hardcoded into23* the client implementation long after the consensus change has activated. See BIP 90.24* Consensus changes for which the new rules are enforced from genesis are not listed here.25*/26enum BuriedDeployment : int16_t {27// buried deployments get negative values to avoid overlap with DeploymentPos28DEPLOYMENT_HEIGHTINCB = std::numeric_limits<int16_t>::min(),29DEPLOYMENT_CLTV,30DEPLOYMENT_DERSIG,31DEPLOYMENT_CSV,32// SCRIPT_VERIFY_WITNESS is enforced from genesis, but the check for downloading33// missing witness data is not. BIP 147 also relies on hardcoded activation height.34DEPLOYMENT_SEGWIT,35};36constexpr bool ValidDeployment(BuriedDeployment dep) { return dep <= DEPLOYMENT_SEGWIT; }38enum DeploymentPos : uint16_t {39DEPLOYMENT_TESTDUMMY,40// NOTE: Also add new deployments to VersionBitsDeploymentInfo in deploymentinfo.cpp41// Removing an entry may require bumping MinBIP9WarningHeight.42MAX_VERSION_BITS_DEPLOYMENTS43};44constexpr bool ValidDeployment(DeploymentPos dep) { return dep < MAX_VERSION_BITS_DEPLOYMENTS; }46/**47* Struct for each individual consensus rule change using BIP9.48*/49struct BIP9Deployment {50/** Bit position to select the particular bit in nVersion. */51int bit{28};52/** Start MedianTime for version bits miner confirmation. Can be a date in the past */53int64_t nStartTime{NEVER_ACTIVE};54/** Timeout/expiry MedianTime for the deployment attempt. */55int64_t nTimeout{NEVER_ACTIVE};56/** If lock in occurs, delay activation until at least this block57* height. Note that activation will only occur on a retarget58* boundary.59*/60int min_activation_height{0};61/** Period of blocks to check signalling in (usually retarget period, ie params.DifficultyAdjustmentInterval()) */62uint32_t period{2016};63/**64* Minimum blocks including miner confirmation of the total of 2016 blocks in a retargeting period,65* which is also used for BIP9 deployments.66* Examples: 1916 for 95%, 1512 for testchains.67*/68uint32_t threshold{1916};70/** Constant for nTimeout very far in the future. */71static constexpr int64_t NO_TIMEOUT = std::numeric_limits<int64_t>::max();73/** Special value for nStartTime indicating that the deployment is always active.74* This is useful for testing, as it means tests don't need to deal with the activation75* process (which takes at least 3 BIP9 intervals). Only tests that specifically test the76* behaviour during activation cannot use this. */77static constexpr int64_t ALWAYS_ACTIVE = -1;79/** Special value for nStartTime indicating that the deployment is never active.80* This is useful for integrating the code changes for a new feature81* prior to deploying it on some or all networks. */82static constexpr int64_t NEVER_ACTIVE = -2;83};85/**86* Parameters that influence chain consensus.87*/88struct Params {89uint256 hashGenesisBlock;90int nSubsidyHalvingInterval;91/**92* Hashes of blocks that93* - are known to be consensus valid, and94* - buried in the chain, and95* - fail if the default script verify flags are applied.96*/97std::map<uint256, script_verify_flags> script_flag_exceptions;98/** Block height and hash at which BIP34 becomes active */99int BIP34Height;100uint256 BIP34Hash;101/** Block height at which BIP65 becomes active */102int BIP65Height;103/** Block height at which BIP66 becomes active */104int BIP66Height;105/** Block height at which CSV (BIP68, BIP112 and BIP113) becomes active */106int CSVHeight;107/** Block height at which Segwit (BIP141, BIP143 and BIP147) becomes active.108* Note that segwit v0 script rules are enforced on all blocks except the109* BIP 16 exception blocks. */110int SegwitHeight;111/** Don't warn about unknown BIP 9 activations below this height.112* This prevents us from warning about the CSV, segwit and taproot activations. */113int MinBIP9WarningHeight;114std::array<BIP9Deployment,MAX_VERSION_BITS_DEPLOYMENTS> vDeployments;115/** Proof of work parameters */116uint256 powLimit;117bool fPowAllowMinDifficultyBlocks;118/**119* Enforce BIP94 timewarp attack mitigation. On testnet4 this also enforces120* the block storm mitigation.121*/122bool enforce_BIP94;123bool fPowNoRetargeting;124int64_t nPowTargetSpacing;125int64_t nPowTargetTimespan;126std::chrono::seconds PowTargetSpacing() const127{128return std::chrono::seconds{nPowTargetSpacing};129}130int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; }131/** The best chain should have at least this much work */132uint256 nMinimumChainWork;133/** By default assume that the signatures in ancestors of this block are valid */134uint256 defaultAssumeValid;136/**137* If true, witness commitments contain a payload equal to a Bitcoin Script solution138* to the signet challenge. See BIP325.139*/140bool signet_blocks{false};141std::vector<uint8_t> signet_challenge;143int DeploymentHeight(BuriedDeployment dep) const144{145switch (dep) {146case DEPLOYMENT_HEIGHTINCB:147return BIP34Height;148case DEPLOYMENT_CLTV:149return BIP65Height;150case DEPLOYMENT_DERSIG:151return BIP66Height;152case DEPLOYMENT_CSV:153return CSVHeight;154case DEPLOYMENT_SEGWIT:155return SegwitHeight;156} // no default case, so the compiler can warn about missing cases157return std::numeric_limits<int>::max();158}159};161} // namespace Consensus163#endif // BITCOIN_CONSENSUS_PARAMS_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.