rpc/blockchain: rename getdeploymentinfo tip/active_chain_tip to blockindex

This commit is contained in:
Anthony Towns committed 2022-02-04 13:43:52 +10:00
1 parent fbab43f169
commit e5f0356e3f
1 file changed
+25 -25
+25 -25
View File
@@ -1430,7 +1430,7 @@ static RPCHelpMan verifychain()
}; };
} }
static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& softforks, const Consensus::Params& params, Consensus::BuriedDeployment dep) static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softforks, const Consensus::Params& params, Consensus::BuriedDeployment dep)
{ {
// For buried deployments. // For buried deployments.
@@ -1440,17 +1440,17 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue&
rv.pushKV("type", "buried"); rv.pushKV("type", "buried");
// getdeploymentinfo reports the softfork as active from when the chain height is // getdeploymentinfo reports the softfork as active from when the chain height is
// one below the activation height // one below the activation height
rv.pushKV("active", DeploymentActiveAfter(active_chain_tip, params, dep)); rv.pushKV("active", DeploymentActiveAfter(blockindex, params, dep));
rv.pushKV("height", params.DeploymentHeight(dep)); rv.pushKV("height", params.DeploymentHeight(dep));
softforks.pushKV(DeploymentName(dep), rv); softforks.pushKV(DeploymentName(dep), rv);
} }
static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& softforks, const Consensus::Params& consensusParams, Consensus::DeploymentPos id) static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softforks, const Consensus::Params& consensusParams, Consensus::DeploymentPos id)
{ {
// For BIP9 deployments. // For BIP9 deployments.
if (!DeploymentEnabled(consensusParams, id)) return; if (!DeploymentEnabled(consensusParams, id)) return;
if (active_chain_tip == nullptr) return; if (blockindex == nullptr) return;
auto get_state_name = [](const ThresholdState state) -> std::string { auto get_state_name = [](const ThresholdState state) -> std::string {
switch (state) { switch (state) {
@@ -1465,8 +1465,8 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue&
UniValue bip9(UniValue::VOBJ); UniValue bip9(UniValue::VOBJ);
const ThresholdState next_state = g_versionbitscache.State(active_chain_tip, consensusParams, id); const ThresholdState next_state = g_versionbitscache.State(blockindex, consensusParams, id);
const ThresholdState current_state = g_versionbitscache.State(active_chain_tip->pprev, consensusParams, id); const ThresholdState current_state = g_versionbitscache.State(blockindex->pprev, consensusParams, id);
const bool has_signal = (ThresholdState::STARTED == current_state || ThresholdState::LOCKED_IN == current_state); const bool has_signal = (ThresholdState::STARTED == current_state || ThresholdState::LOCKED_IN == current_state);
@@ -1480,14 +1480,14 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue&
// BIP9 status // BIP9 status
bip9.pushKV("status", get_state_name(current_state)); bip9.pushKV("status", get_state_name(current_state));
bip9.pushKV("since", g_versionbitscache.StateSinceHeight(active_chain_tip->pprev, consensusParams, id)); bip9.pushKV("since", g_versionbitscache.StateSinceHeight(blockindex->pprev, consensusParams, id));
bip9.pushKV("status-next", get_state_name(next_state)); bip9.pushKV("status-next", get_state_name(next_state));
// BIP9 signalling status, if applicable // BIP9 signalling status, if applicable
if (has_signal) { if (has_signal) {
UniValue statsUV(UniValue::VOBJ); UniValue statsUV(UniValue::VOBJ);
std::vector<bool> signals; std::vector<bool> signals;
BIP9Stats statsStruct = g_versionbitscache.Statistics(active_chain_tip, consensusParams, id, &signals); BIP9Stats statsStruct = g_versionbitscache.Statistics(blockindex, consensusParams, id, &signals);
statsUV.pushKV("period", statsStruct.period); statsUV.pushKV("period", statsStruct.period);
statsUV.pushKV("elapsed", statsStruct.elapsed); statsUV.pushKV("elapsed", statsStruct.elapsed);
statsUV.pushKV("count", statsStruct.count); statsUV.pushKV("count", statsStruct.count);
@@ -1508,7 +1508,7 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue&
UniValue rv(UniValue::VOBJ); UniValue rv(UniValue::VOBJ);
rv.pushKV("type", "bip9"); rv.pushKV("type", "bip9");
if (ThresholdState::ACTIVE == next_state) { if (ThresholdState::ACTIVE == next_state) {
rv.pushKV("height", g_versionbitscache.StateSinceHeight(active_chain_tip, consensusParams, id)); rv.pushKV("height", g_versionbitscache.StateSinceHeight(blockindex, consensusParams, id));
} }
rv.pushKV("active", ThresholdState::ACTIVE == next_state); rv.pushKV("active", ThresholdState::ACTIVE == next_state);
rv.pushKV("bip9", bip9); rv.pushKV("bip9", bip9);
@@ -1636,16 +1636,16 @@ const std::vector<RPCResult> RPCHelpForDeployment{
}}, }},
}; };
UniValue DeploymentInfo(const CBlockIndex* tip, const Consensus::Params& consensusParams) UniValue DeploymentInfo(const CBlockIndex* blockindex, const Consensus::Params& consensusParams)
{ {
UniValue softforks(UniValue::VOBJ); UniValue softforks(UniValue::VOBJ);
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_HEIGHTINCB); SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_HEIGHTINCB);
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_DERSIG); SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_DERSIG);
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_CLTV); SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_CLTV);
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_CSV); SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_CSV);
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_SEGWIT); SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_SEGWIT);
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY); SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY);
SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_TAPROOT); SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_TAPROOT);
return softforks; return softforks;
} }
} // anon namespace } // anon namespace
@@ -1673,14 +1673,14 @@ static RPCHelpMan getdeploymentinfo()
LOCK(cs_main); LOCK(cs_main);
const CChainState& active_chainstate = chainman.ActiveChainstate(); const CChainState& active_chainstate = chainman.ActiveChainstate();
const CBlockIndex* tip; const CBlockIndex* blockindex;
if (request.params[0].isNull()) { if (request.params[0].isNull()) {
tip = active_chainstate.m_chain.Tip(); blockindex = active_chainstate.m_chain.Tip();
CHECK_NONFATAL(tip); CHECK_NONFATAL(blockindex);
} else { } else {
const uint256 hash(ParseHashV(request.params[0], "blockhash")); const uint256 hash(ParseHashV(request.params[0], "blockhash"));
tip = chainman.m_blockman.LookupBlockIndex(hash); blockindex = chainman.m_blockman.LookupBlockIndex(hash);
if (!tip) { if (!blockindex) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
} }
} }
@@ -1688,9 +1688,9 @@ static RPCHelpMan getdeploymentinfo()
const Consensus::Params& consensusParams = Params().GetConsensus(); const Consensus::Params& consensusParams = Params().GetConsensus();
UniValue deploymentinfo(UniValue::VOBJ); UniValue deploymentinfo(UniValue::VOBJ);
deploymentinfo.pushKV("hash", tip->GetBlockHash().ToString()); deploymentinfo.pushKV("hash", blockindex->GetBlockHash().ToString());
deploymentinfo.pushKV("height", tip->nHeight); deploymentinfo.pushKV("height", blockindex->nHeight);
deploymentinfo.pushKV("deployments", DeploymentInfo(tip, consensusParams)); deploymentinfo.pushKV("deployments", DeploymentInfo(blockindex, consensusParams));
return deploymentinfo; return deploymentinfo;
}, },
}; };