Skip to content

Commit 8ee3e0b

Browse files
committed
[refactor] rpc/blockchain.cpp: SoftForkPushBack
Rename BIP9SoftForkPushBack and BuriedSoftForkPushBack to SoftForkPushBack and have the compiler figure out which one to use based on the deployment type. Avoids the need to update the file when burying a deployment.
1 parent 92f48f3 commit 8ee3e0b

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/rpc/blockchain.cpp

+18-15
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
#include <chain.h>
1111
#include <chainparams.h>
1212
#include <coins.h>
13+
#include <consensus/params.h>
1314
#include <consensus/validation.h>
1415
#include <core_io.h>
16+
#include <deploymentinfo.h>
1517
#include <deploymentstatus.h>
1618
#include <hash.h>
1719
#include <index/blockfilterindex.h>
@@ -38,6 +40,7 @@
3840
#include <util/translation.h>
3941
#include <validation.h>
4042
#include <validationinterface.h>
43+
#include <versionbits.h>
4144
#include <warnings.h>
4245

4346
#include <stdint.h>
@@ -1344,25 +1347,25 @@ static RPCHelpMan verifychain()
13441347
};
13451348
}
13461349

1347-
static void BuriedForkDescPushBack(UniValue& softforks, const std::string &name, int softfork_height, int tip_height) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1350+
static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& softforks, const Consensus::Params& params, Consensus::BuriedDeployment dep)
13481351
{
13491352
// For buried deployments.
13501353
// A buried deployment is one where the height of the activation has been hardcoded into
13511354
// the client implementation long after the consensus change has activated. See BIP 90.
13521355
// Buried deployments with activation height value of
13531356
// std::numeric_limits<int>::max() are disabled and thus hidden.
1354-
if (softfork_height == std::numeric_limits<int>::max()) return;
1357+
if (!DeploymentEnabled(params, dep)) return;
13551358

13561359
UniValue rv(UniValue::VOBJ);
13571360
rv.pushKV("type", "buried");
13581361
// getblockchaininfo reports the softfork as active from when the chain height is
13591362
// one below the activation height
1360-
rv.pushKV("active", tip_height + 1 >= softfork_height);
1361-
rv.pushKV("height", softfork_height);
1362-
softforks.pushKV(name, rv);
1363+
rv.pushKV("active", DeploymentActiveAfter(active_chain_tip, params, dep));
1364+
rv.pushKV("height", params.DeploymentHeight(dep));
1365+
softforks.pushKV(DeploymentName(dep), rv);
13631366
}
13641367

1365-
static void BIP9SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& softforks, const std::string &name, const Consensus::Params& consensusParams, Consensus::DeploymentPos id)
1368+
static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& softforks, const Consensus::Params& consensusParams, Consensus::DeploymentPos id)
13661369
{
13671370
// For BIP9 deployments.
13681371
// Deployments that are never active are hidden.
@@ -1406,7 +1409,7 @@ static void BIP9SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniVal
14061409
}
14071410
rv.pushKV("active", ThresholdState::ACTIVE == thresholdState);
14081411

1409-
softforks.pushKV(name, rv);
1412+
softforks.pushKV(DeploymentName(id), rv);
14101413
}
14111414

14121415
RPCHelpMan getblockchaininfo()
@@ -1503,14 +1506,14 @@ RPCHelpMan getblockchaininfo()
15031506

15041507
const Consensus::Params& consensusParams = Params().GetConsensus();
15051508
UniValue softforks(UniValue::VOBJ);
1506-
BuriedForkDescPushBack(softforks, "bip34", consensusParams.BIP34Height, height);
1507-
BuriedForkDescPushBack(softforks, "bip66", consensusParams.BIP66Height, height);
1508-
BuriedForkDescPushBack(softforks, "bip65", consensusParams.BIP65Height, height);
1509-
BuriedForkDescPushBack(softforks, "csv", consensusParams.CSVHeight, height);
1510-
BuriedForkDescPushBack(softforks, "segwit", consensusParams.SegwitHeight, height);
1511-
BIP9SoftForkDescPushBack(tip, softforks, "testdummy", consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
1512-
BIP9SoftForkDescPushBack(tip, softforks, "taproot", consensusParams, Consensus::DEPLOYMENT_TAPROOT);
1513-
obj.pushKV("softforks", softforks);
1509+
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_HEIGHTINCB);
1510+
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_DERSIG);
1511+
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_CLTV);
1512+
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_CSV);
1513+
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_SEGWIT);
1514+
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
1515+
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_TAPROOT);
1516+
obj.pushKV("softforks", softforks);
15141517

15151518
obj.pushKV("warnings", GetWarnings(false).original);
15161519
return obj;

0 commit comments

Comments
 (0)