diff --git a/src/consensus/params.h b/src/consensus/params.h index 6725bac40..e322fc28f 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -1,152 +1,152 @@ // Copyright (c) 2009-2010 Satoshi Nakamoto // Copyright (c) 2009-2016 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #ifndef BITCOIN_CONSENSUS_PARAMS_H #define BITCOIN_CONSENSUS_PARAMS_H #include #include #include namespace Consensus { enum BuriedDeployment : int16_t { // buried deployments get negative values to avoid overlap with // DeploymentPos DEPLOYMENT_P2SH = std::numeric_limits::min(), DEPLOYMENT_HEIGHTINCB, DEPLOYMENT_CLTV, DEPLOYMENT_DERSIG, DEPLOYMENT_CSV, }; constexpr bool ValidDeployment(BuriedDeployment dep) { - return DEPLOYMENT_P2SH <= dep && dep <= DEPLOYMENT_CSV; + return dep <= DEPLOYMENT_CSV; } enum DeploymentPos : uint16_t { DEPLOYMENT_TESTDUMMY, // NOTE: Also add new deployments to VersionBitsDeploymentInfo in // deploymentinfo.cpp MAX_VERSION_BITS_DEPLOYMENTS, }; constexpr bool ValidDeployment(DeploymentPos dep) { - return DEPLOYMENT_TESTDUMMY <= dep && dep < MAX_VERSION_BITS_DEPLOYMENTS; + return dep < MAX_VERSION_BITS_DEPLOYMENTS; } /** * Struct for each individual consensus rule change using BIP9. */ struct BIP9Deployment { /** Bit position to select the particular bit in nVersion. */ int bit; /** * Minimum number of blocks within an activation window that must signal to * activate the deployement. * Default to 75% of 2016. */ uint32_t nActivationThreshold = 1512; /** * Start MedianTime for version bits miner confirmation. Can be a date in * the past. */ int64_t nStartTime = 0; /** Timeout/expiry MedianTime for the deployment attempt. */ int64_t nTimeout = NO_TIMEOUT; /** Constant for nTimeout very far in the future. */ static constexpr int64_t NO_TIMEOUT = std::numeric_limits::max(); /** * Special value for nStartTime indicating that the deployment is always * active. This is useful for testing, as it means tests don't need to deal * with the activation process (which takes at least 3 BIP9 intervals). Only * tests that specifically test the behaviour during activation cannot use * this. */ static constexpr int64_t ALWAYS_ACTIVE = -1; }; /** * Parameters that influence chain consensus. */ struct Params { BlockHash hashGenesisBlock; int nSubsidyHalvingInterval; /** Block height at which BIP16 becomes active */ int BIP16Height; /** Block height and hash at which BIP34 becomes active */ int BIP34Height; BlockHash BIP34Hash; /** Block height at which BIP65 becomes active */ int BIP65Height; /** Block height at which BIP66 becomes active */ int BIP66Height; /** Block height at which CSV (BIP68, BIP112 and BIP113) becomes active */ int CSVHeight; /** Block height at which UAHF kicks in */ int uahfHeight; /** Block height at which the new DAA becomes active */ int daaHeight; /** Block height at which the magnetic anomaly activation becomes active */ int magneticAnomalyHeight; /** Block height at which the graviton activation becomes active */ int gravitonHeight; /** Block height at which the phonon activation becomes active */ int phononHeight; /** Block height at which the axion activation becomes active */ int axionHeight; /** Block height at which the gluon activation becomes active */ int gluonHeight; /** Unix time used for MTP activation of 15 Nov 2022 12:00:00 UTC upgrade */ int jeffersonActivationTime; /** Unix time used for MTP activation of 15 May 2023 12:00:00 UTC upgrade */ int wellingtonActivationTime; /** * Don't warn about unknown BIP 9 activations below this height. * This prevents us from warning about the CSV and segwit activations. */ int MinBIP9WarningHeight; uint32_t nMinerConfirmationWindow; BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]; /** Enable or disable the miner fund by default */ bool enableMinerFund; /** Proof of work parameters */ uint256 powLimit; bool fPowAllowMinDifficultyBlocks; bool fPowNoRetargeting; int64_t nDAAHalfLife; int64_t nPowTargetSpacing; int64_t nPowTargetTimespan; int64_t DifficultyAdjustmentInterval() const { return nPowTargetTimespan / nPowTargetSpacing; } uint256 nMinimumChainWork; BlockHash defaultAssumeValid; int DeploymentHeight(BuriedDeployment dep) const { switch (dep) { case DEPLOYMENT_P2SH: return BIP16Height; case DEPLOYMENT_HEIGHTINCB: return BIP34Height; case DEPLOYMENT_CLTV: return BIP65Height; case DEPLOYMENT_DERSIG: return BIP66Height; case DEPLOYMENT_CSV: return CSVHeight; } // no default case, so the compiler can warn about missing cases return std::numeric_limits::max(); } }; } // namespace Consensus #endif // BITCOIN_CONSENSUS_PARAMS_H diff --git a/src/deploymentstatus.cpp b/src/deploymentstatus.cpp index c1ce9c5db..2b173c359 100644 --- a/src/deploymentstatus.cpp +++ b/src/deploymentstatus.cpp @@ -1,25 +1,45 @@ // Copyright (c) 2020 The Bitcoin Core developers // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. #include #include #include +#include + VersionBitsCache g_versionbitscache; /** * Basic sanity checking for BuriedDeployment/DeploymentPos enums and * ValidDeployment check */ static_assert(ValidDeployment(Consensus::DEPLOYMENT_TESTDUMMY), "sanity check of DeploymentPos failed (TESTDUMMY not valid)"); static_assert( !ValidDeployment(Consensus::MAX_VERSION_BITS_DEPLOYMENTS), "sanity check of DeploymentPos failed (MAX value considered valid)"); static_assert( !ValidDeployment(static_cast( Consensus::DEPLOYMENT_TESTDUMMY)), "sanity check of BuriedDeployment failed (overlaps with DeploymentPos)"); + +/** + * ValidDeployment only checks upper bounds for ensuring validity. + * This checks that the lowest possible value or the type is also a + * (specific) valid deployment so that lower bounds don't need to be checked. + */ + +template static constexpr bool is_minimum() { + using U = typename std::underlying_type::type; + return x == std::numeric_limits::min(); +} + +static_assert( + is_minimum(), + "p2sh is not minimum value for BuriedDeployment"); +static_assert( + is_minimum(), + "testdummy is not minimum value for DeploymentPos");