From 2b0d291da8f479739ff394dd92801da8c40b9f8e Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Tue, 16 Jun 2020 18:58:56 +1000 Subject: [refactor] Add deploymentstatus.h Provides DeploymentEnabled, DeploymentActiveAt, and DeploymentActiveAfter helpers for checking the status of buried deployments. Can be overloaded so the same syntax works for non-buried deployments, allowing future soft forks to be changed from signalled to buried deployments without having to touch the implementation code. Replaces IsWitnessEnabled and IsScriptWitnessEnabled. --- src/consensus/params.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/consensus/params.h') diff --git a/src/consensus/params.h b/src/consensus/params.h index 28c95e0884..9b4139d76c 100644 --- a/src/consensus/params.h +++ b/src/consensus/params.h @@ -11,6 +11,17 @@ namespace Consensus { +enum BuriedDeployment : int16_t +{ + // buried deployments get negative values to avoid overlap with DeploymentPos + DEPLOYMENT_HEIGHTINCB = std::numeric_limits::min(), + DEPLOYMENT_CLTV, + DEPLOYMENT_DERSIG, + DEPLOYMENT_CSV, + DEPLOYMENT_SEGWIT, +}; +constexpr bool ValidDeployment(BuriedDeployment dep) { return DEPLOYMENT_HEIGHTINCB <= dep && dep <= DEPLOYMENT_SEGWIT; } + enum DeploymentPos { DEPLOYMENT_TESTDUMMY, @@ -100,7 +111,25 @@ struct Params { */ bool signet_blocks{false}; std::vector signet_challenge; + + int DeploymentHeight(BuriedDeployment dep) const + { + switch (dep) { + case DEPLOYMENT_HEIGHTINCB: + return BIP34Height; + case DEPLOYMENT_CLTV: + return BIP65Height; + case DEPLOYMENT_DERSIG: + return BIP66Height; + case DEPLOYMENT_CSV: + return CSVHeight; + case DEPLOYMENT_SEGWIT: + return SegwitHeight; + } // no default case, so the compiler can warn about missing cases + return std::numeric_limits::max(); + } }; + } // namespace Consensus #endif // BITCOIN_CONSENSUS_PARAMS_H -- cgit v1.2.3