diff --git a/src/deploymentinfo.h b/src/deploymentinfo.h --- a/src/deploymentinfo.h +++ b/src/deploymentinfo.h @@ -5,6 +5,10 @@ #ifndef BITCOIN_DEPLOYMENTINFO_H #define BITCOIN_DEPLOYMENTINFO_H +#include + +#include + struct VBDeploymentInfo { /** Deployment name */ const char *name; @@ -12,6 +16,14 @@ bool gbt_force; }; -extern const struct VBDeploymentInfo VersionBitsDeploymentInfo[]; +extern const VBDeploymentInfo + VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS]; + +[[maybe_unused]] std::string DeploymentName(Consensus::BuriedDeployment dep); + +inline std::string DeploymentName(Consensus::DeploymentPos pos) { + assert(Consensus::ValidDeployment(pos)); + return VersionBitsDeploymentInfo[pos].name; +} #endif // BITCOIN_DEPLOYMENTINFO_H diff --git a/src/deploymentinfo.cpp b/src/deploymentinfo.cpp --- a/src/deploymentinfo.cpp +++ b/src/deploymentinfo.cpp @@ -13,3 +13,20 @@ /*.gbt_force =*/true, }, }; + +[[maybe_unused]] std::string DeploymentName(Consensus::BuriedDeployment dep) { + assert(ValidDeployment(dep)); + switch (dep) { + case Consensus::DEPLOYMENT_P2SH: + return "bip22"; + case Consensus::DEPLOYMENT_HEIGHTINCB: + return "bip34"; + case Consensus::DEPLOYMENT_CLTV: + return "bip65"; + case Consensus::DEPLOYMENT_DERSIG: + return "bip66"; + case Consensus::DEPLOYMENT_CSV: + return "csv"; + } // no default case, so the compiler can warn about missing cases + return ""; +} diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -11,9 +11,10 @@ #include #include #include +#include #include #include -#include // For VersionBitsDeploymentInfo +#include #include #include #include @@ -36,6 +37,7 @@ #include #include #include +#include #include #include @@ -1635,10 +1637,32 @@ }; } -static void BIP9SoftForkDescPushBack(const CBlockIndex *active_chain_tip, - UniValue &softforks, - const Consensus::Params &consensusParams, - Consensus::DeploymentPos id) { +[[maybe_unused]] static void +SoftForkDescPushBack(const CBlockIndex *active_chain_tip, UniValue &softforks, + const Consensus::Params ¶ms, + Consensus::BuriedDeployment dep) { + // For buried deployments. + // A buried deployment is one where the height of the activation has been + // hardcoded into the client implementation long after the consensus change + // has activated. See BIP 90. Buried deployments with activation height + // value of std::numeric_limits::max() are disabled and thus hidden. + if (!DeploymentEnabled(params, dep)) { + return; + } + + UniValue rv(UniValue::VOBJ); + rv.pushKV("type", "buried"); + // getblockchaininfo reports the softfork as active from when the chain + // height is one below the activation height + rv.pushKV("active", DeploymentActiveAfter(active_chain_tip, params, dep)); + rv.pushKV("height", params.DeploymentHeight(dep)); + softforks.pushKV(DeploymentName(dep), rv); +} + +static void SoftForkDescPushBack(const CBlockIndex *active_chain_tip, + UniValue &softforks, + const Consensus::Params &consensusParams, + Consensus::DeploymentPos id) { // For BIP9 deployments. // Deployments (e.g. testdummy) with timeout value before Jan 1, 2009 are // hidden. A timeout value of 0 guarantees a softfork will never be @@ -1696,7 +1720,7 @@ } rv.pushKV("active", ThresholdState::ACTIVE == thresholdState); - softforks.pushKV(VersionBitsDeploymentInfo[id].name, rv); + softforks.pushKV(DeploymentName(id), rv); } RPCHelpMan getblockchaininfo() { @@ -1859,9 +1883,8 @@ UniValue softforks(UniValue::VOBJ); for (int i = 0; i < (int)Consensus::MAX_VERSION_BITS_DEPLOYMENTS; i++) { - BIP9SoftForkDescPushBack(tip, softforks, - chainparams.GetConsensus(), - Consensus::DeploymentPos(i)); + SoftForkDescPushBack(tip, softforks, chainparams.GetConsensus(), + Consensus::DeploymentPos(i)); } obj.pushKV("softforks", softforks);