Skip to content

Commit fd82613

Browse files
committed
rpc: move softfork info from getblockchaininfo to getdeploymentinfo
1 parent 7908772 commit fd82613

File tree

7 files changed

+95
-36
lines changed

7 files changed

+95
-36
lines changed

src/rpc/blockchain.cpp

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,7 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue&
14001400

14011401
UniValue rv(UniValue::VOBJ);
14021402
rv.pushKV("type", "buried");
1403-
// getblockchaininfo reports the softfork as active from when the chain height is
1403+
// getdeploymentinfo reports the softfork as active from when the chain height is
14041404
// one below the activation height
14051405
rv.pushKV("active", DeploymentActiveAfter(active_chain_tip, params, dep));
14061406
rv.pushKV("height", params.DeploymentHeight(dep));
@@ -1455,8 +1455,16 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue&
14551455
softforks.pushKV(DeploymentName(id), rv);
14561456
}
14571457

1458+
namespace {
1459+
/* TODO: when -dprecatedrpc=softforks is removed, drop these */
1460+
UniValue DeploymentInfo(const CBlockIndex* tip, const Consensus::Params& consensusParams);
1461+
extern const std::vector<RPCResult> RPCHelpForDeployment;
1462+
}
1463+
1464+
// used by rest.cpp:rest_chaininfo, so cannot be static
14581465
RPCHelpMan getblockchaininfo()
14591466
{
1467+
/* TODO: from v24, remove -deprecatedrpc=softforks */
14601468
return RPCHelpMan{"getblockchaininfo",
14611469
"Returns an object containing various state info regarding blockchain processing.\n",
14621470
{},
@@ -1478,31 +1486,11 @@ RPCHelpMan getblockchaininfo()
14781486
{RPCResult::Type::NUM, "pruneheight", /*optional=*/true, "lowest-height complete block stored (only present if pruning is enabled)"},
14791487
{RPCResult::Type::BOOL, "automatic_pruning", /*optional=*/true, "whether automatic pruning is enabled (only present if pruning is enabled)"},
14801488
{RPCResult::Type::NUM, "prune_target_size", /*optional=*/true, "the target size used by pruning (only present if automatic pruning is enabled)"},
1481-
{RPCResult::Type::OBJ_DYN, "softforks", "status of softforks",
1489+
{RPCResult::Type::OBJ_DYN, "softforks", "(DEPRECATED, returned only if config option -deprecatedrpc=softforks is passed) status of softforks",
14821490
{
14831491
{RPCResult::Type::OBJ, "xxxx", "name of the softfork",
1484-
{
1485-
{RPCResult::Type::STR, "type", "one of \"buried\", \"bip9\""},
1486-
{RPCResult::Type::OBJ, "bip9", /*optional=*/true, "status of bip9 softforks (only for \"bip9\" type)",
1487-
{
1488-
{RPCResult::Type::STR, "status", "one of \"defined\", \"started\", \"locked_in\", \"active\", \"failed\""},
1489-
{RPCResult::Type::NUM, "bit", /*optional=*/true, "the bit (0-28) in the block version field used to signal this softfork (only for \"started\" and \"locked_in\" status)"},
1490-
{RPCResult::Type::NUM_TIME, "start_time", "the minimum median time past of a block at which the bit gains its meaning"},
1491-
{RPCResult::Type::NUM_TIME, "timeout", "the median time past of a block at which the deployment is considered failed if not yet locked in"},
1492-
{RPCResult::Type::NUM, "since", "height of the first block to which the status applies"},
1493-
{RPCResult::Type::NUM, "min_activation_height", "minimum height of blocks for which the rules may be enforced"},
1494-
{RPCResult::Type::OBJ, "statistics", /*optional=*/true, "numeric statistics about signalling for a softfork (only for \"started\" and \"locked_in\" status)",
1495-
{
1496-
{RPCResult::Type::NUM, "period", "the length in blocks of the signalling period"},
1497-
{RPCResult::Type::NUM, "threshold", /*optional=*/true, "the number of blocks with the version bit set required to activate the feature (only for \"started\" status)"},
1498-
{RPCResult::Type::NUM, "elapsed", "the number of blocks elapsed since the beginning of the current period"},
1499-
{RPCResult::Type::NUM, "count", "the number of blocks with the version bit set in the current period"},
1500-
{RPCResult::Type::BOOL, "possible", /*optional=*/true, "returns false if there are not enough blocks left in this period to pass activation threshold (only for \"started\" status)"},
1501-
}},
1502-
}},
1503-
{RPCResult::Type::NUM, "height", /*optional=*/true, "height of the first block which the rules are or will be enforced (only for \"buried\" type, or \"bip9\" type with \"active\" status)"},
1504-
{RPCResult::Type::BOOL, "active", "true if the rules are enforced for the mempool and the next block"},
1505-
}},
1492+
RPCHelpForDeployment
1493+
},
15061494
}},
15071495
{RPCResult::Type::STR, "warnings", "any network and blockchain warnings"},
15081496
}},
@@ -1549,7 +1537,43 @@ RPCHelpMan getblockchaininfo()
15491537
}
15501538
}
15511539

1552-
const Consensus::Params& consensusParams = Params().GetConsensus();
1540+
if (IsDeprecatedRPCEnabled("softforks")) {
1541+
const Consensus::Params& consensusParams = Params().GetConsensus();
1542+
obj.pushKV("softforks", DeploymentInfo(tip, consensusParams));
1543+
}
1544+
1545+
obj.pushKV("warnings", GetWarnings(false).original);
1546+
return obj;
1547+
},
1548+
};
1549+
}
1550+
1551+
namespace {
1552+
const std::vector<RPCResult> RPCHelpForDeployment{
1553+
{RPCResult::Type::STR, "type", "one of \"buried\", \"bip9\""},
1554+
{RPCResult::Type::OBJ, "bip9", /*optional=*/true, "status of bip9 softforks (only for \"bip9\" type)",
1555+
{
1556+
{RPCResult::Type::STR, "status", "one of \"defined\", \"started\", \"locked_in\", \"active\", \"failed\""},
1557+
{RPCResult::Type::NUM, "bit", /*optional=*/true, "the bit (0-28) in the block version field used to signal this softfork (only for \"started\" and \"locked_in\" status)"},
1558+
{RPCResult::Type::NUM_TIME, "start_time", "the minimum median time past of a block at which the bit gains its meaning"},
1559+
{RPCResult::Type::NUM_TIME, "timeout", "the median time past of a block at which the deployment is considered failed if not yet locked in"},
1560+
{RPCResult::Type::NUM, "since", "height of the first block to which the status applies"},
1561+
{RPCResult::Type::NUM, "min_activation_height", "minimum height of blocks for which the rules may be enforced"},
1562+
{RPCResult::Type::OBJ, "statistics", /*optional=*/true, "numeric statistics about signalling for a softfork (only for \"started\" and \"locked_in\" status)",
1563+
{
1564+
{RPCResult::Type::NUM, "period", "the length in blocks of the signalling period"},
1565+
{RPCResult::Type::NUM, "threshold", /*optional=*/true, "the number of blocks with the version bit set required to activate the feature (only for \"started\" status)"},
1566+
{RPCResult::Type::NUM, "elapsed", "the number of blocks elapsed since the beginning of the current period"},
1567+
{RPCResult::Type::NUM, "count", "the number of blocks with the version bit set in the current period"},
1568+
{RPCResult::Type::BOOL, "possible", /*optional=*/true, "returns false if there are not enough blocks left in this period to pass activation threshold (only for \"started\" status)"},
1569+
}},
1570+
}},
1571+
{RPCResult::Type::NUM, "height", /*optional=*/true, "height of the first block which the rules are or will be enforced (only for \"buried\" type, or \"bip9\" type with \"active\" status)"},
1572+
{RPCResult::Type::BOOL, "active", "true if the rules are enforced for the mempool and the next block"},
1573+
};
1574+
1575+
UniValue DeploymentInfo(const CBlockIndex* tip, const Consensus::Params& consensusParams)
1576+
{
15531577
UniValue softforks(UniValue::VOBJ);
15541578
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_HEIGHTINCB);
15551579
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_DERSIG);
@@ -1558,11 +1582,37 @@ RPCHelpMan getblockchaininfo()
15581582
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_SEGWIT);
15591583
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
15601584
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_TAPROOT);
1561-
obj.pushKV("softforks", softforks);
1585+
return softforks;
1586+
}
1587+
} // anon namespace
15621588

1563-
obj.pushKV("warnings", GetWarnings(false).original);
1564-
return obj;
1565-
},
1589+
static RPCHelpMan getdeploymentinfo()
1590+
{
1591+
return RPCHelpMan{"getdeploymentinfo",
1592+
"Returns an object containing various state info regarding soft-forks.",
1593+
{},
1594+
RPCResult{
1595+
RPCResult::Type::OBJ, "", "", {
1596+
{RPCResult::Type::OBJ, "deployments", "", {
1597+
{RPCResult::Type::OBJ, "xxxx", "name of the deployment", RPCHelpForDeployment}
1598+
}},
1599+
}
1600+
},
1601+
RPCExamples{ HelpExampleCli("getdeploymentinfo", "") + HelpExampleRpc("getdeploymentinfo", "") },
1602+
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1603+
{
1604+
ChainstateManager& chainman = EnsureAnyChainman(request.context);
1605+
LOCK(cs_main);
1606+
CChainState& active_chainstate = chainman.ActiveChainstate();
1607+
1608+
const CBlockIndex* tip = active_chainstate.m_chain.Tip();
1609+
CHECK_NONFATAL(tip);
1610+
const Consensus::Params& consensusParams = Params().GetConsensus();
1611+
1612+
UniValue deploymentinfo(UniValue::VOBJ);
1613+
deploymentinfo.pushKV("deployments", DeploymentInfo(tip, consensusParams));
1614+
return deploymentinfo;
1615+
},
15661616
};
15671617
}
15681618

@@ -2716,6 +2766,7 @@ static const CRPCCommand commands[] =
27162766
{ "blockchain", &getblockheader, },
27172767
{ "blockchain", &getchaintips, },
27182768
{ "blockchain", &getdifficulty, },
2769+
{ "blockchain", &getdeploymentinfo, },
27192770
{ "blockchain", &getmempoolancestors, },
27202771
{ "blockchain", &getmempooldescendants, },
27212772
{ "blockchain", &getmempoolentry, },

src/test/fuzz/rpc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
120120
"getchaintips",
121121
"getchaintxstats",
122122
"getconnectioncount",
123+
"getdeploymentinfo",
123124
"getdescriptorinfo",
124125
"getdifficulty",
125126
"getindexinfo",

test/functional/feature_cltv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def set_test_params(self):
9191
self.rpc_timeout = 480
9292

9393
def test_cltv_info(self, *, is_active):
94-
assert_equal(self.nodes[0].getblockchaininfo()['softforks']['bip65'], {
94+
assert_equal(self.nodes[0].getdeploymentinfo()['deployments']['bip65'], {
9595
"active": is_active,
9696
"height": CLTV_HEIGHT,
9797
"type": "buried",

test/functional/feature_dersig.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def create_tx(self, input_txid):
6060
return self.miniwallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_to_spend)['tx']
6161

6262
def test_dersig_info(self, *, is_active):
63-
assert_equal(self.nodes[0].getblockchaininfo()['softforks']['bip66'],
63+
assert_equal(self.nodes[0].getdeploymentinfo()['deployments']['bip66'],
6464
{
6565
"active": is_active,
6666
"height": DERSIG_HEIGHT,

test/functional/rpc_blockchain.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
Test the following RPCs:
88
- getblockchaininfo
9+
- getdeploymentinfo
910
- getchaintxstats
1011
- gettxoutsetinfo
1112
- getblockheader
@@ -71,6 +72,7 @@ def run_test(self):
7172
self.restart_node(0, extra_args=['-stopatheight=207', '-prune=1']) # Set extra args with pruning after rescan is complete
7273

7374
self._test_getblockchaininfo()
75+
self._test_getdeploymentinfo()
7476
self._test_getchaintxstats()
7577
self._test_gettxoutsetinfo()
7678
self._test_getblockheader()
@@ -115,7 +117,6 @@ def _test_getblockchaininfo(self):
115117
'mediantime',
116118
'pruned',
117119
'size_on_disk',
118-
'softforks',
119120
'time',
120121
'verificationprogress',
121122
'warnings',
@@ -177,7 +178,12 @@ def _test_getblockchaininfo(self):
177178
assert_equal(res['prune_target_size'], 576716800)
178179
assert_greater_than(res['size_on_disk'], 0)
179180

180-
assert_equal(res['softforks'], {
181+
def _test_getdeploymentinfo(self):
182+
self.log.info("Test getdeploymentinfo")
183+
184+
res = self.nodes[0].getdeploymentinfo()
185+
assert_equal(res, {
186+
"deployments": {
181187
'bip34': {'type': 'buried', 'active': True, 'height': 2},
182188
'bip66': {'type': 'buried', 'active': True, 'height': 3},
183189
'bip65': {'type': 'buried', 'active': True, 'height': 4},
@@ -214,6 +220,7 @@ def _test_getblockchaininfo(self):
214220
'height': 0,
215221
'active': True
216222
}
223+
}
217224
})
218225

219226
def _test_getchaintxstats(self):

test/functional/rpc_signrawtransaction.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def test_signing_with_csv(self):
270270
getcontext().prec = 8
271271

272272
# Make sure CSV is active
273-
assert self.nodes[0].getblockchaininfo()['softforks']['csv']['active']
273+
assert self.nodes[0].getdeploymentinfo()['deployments']['csv']['active']
274274

275275
# Create a P2WSH script with CSV
276276
script = CScript([1, OP_CHECKSEQUENCEVERIFY, OP_DROP])
@@ -305,7 +305,7 @@ def test_signing_with_cltv(self):
305305
getcontext().prec = 8
306306

307307
# Make sure CLTV is active
308-
assert self.nodes[0].getblockchaininfo()['softforks']['bip65']['active']
308+
assert self.nodes[0].getdeploymentinfo()['deployments']['bip65']['active']
309309

310310
# Create a P2WSH script with CLTV
311311
script = CScript([100, OP_CHECKLOCKTIMEVERIFY, OP_DROP])

test/functional/test_framework/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ def delete_cookie_file(datadir, chain):
438438

439439
def softfork_active(node, key):
440440
"""Return whether a softfork is active."""
441-
return node.getblockchaininfo()['softforks'][key]['active']
441+
return node.getdeploymentinfo()['deployments'][key]['active']
442442

443443

444444
def set_node_times(nodes, t):

0 commit comments

Comments
 (0)