From 555eafa7930a84d8ca594bea9fe39f63cfa75076 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 28 Jan 2022 17:13:29 +1000 Subject: [PATCH 1/5] doc: getdeploymentinfo release notes tweaks --- doc/release-notes-23508.md | 9 --------- doc/release-notes.md | 9 +++++++++ 2 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 doc/release-notes-23508.md diff --git a/doc/release-notes-23508.md b/doc/release-notes-23508.md deleted file mode 100644 index 098654e00b129..0000000000000 --- a/doc/release-notes-23508.md +++ /dev/null @@ -1,9 +0,0 @@ -Updated RPCs ------------- - -- Information on soft fork status has been moved from `getblockchaininfo` - to `getdeploymentinfo` which allows querying soft fork status at any - block, rather than just at the chain tip. Inclusion of soft fork - status in `getblockchaininfo` can currently be restored using the - configuration `-deprecatedrpc=softforks`, but this will be removed in - a future release. (#23508) diff --git a/doc/release-notes.md b/doc/release-notes.md index 7a47d76bba189..f50e5ce138992 100644 --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -115,6 +115,15 @@ Updated RPCs New RPCs -------- +- Information on soft fork status has been moved from `getblockchaininfo` + to the new `getdeploymentinfo` RPC which allows querying soft fork status at any + block, rather than just at the chain tip. Inclusion of soft fork + status in `getblockchaininfo` can currently be restored using the + configuration `-deprecatedrpc=softforks`, but this will be removed in + a future release. Note that in either case, the `status` field + now reflects the status of the current block rather than the next + block. (#23508) + Build System ------------ From 32f04e6da9845c218f9bbd8b8329f35ed3678a49 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 28 Jan 2022 17:14:02 +1000 Subject: [PATCH 2/5] rpc documentation improvements --- src/rpc/blockchain.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index f4930cd83967f..cd2c5e0b461e6 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1621,9 +1621,9 @@ const std::vector RPCHelpForDeployment{ {RPCResult::Type::NUM_TIME, "start_time", "the minimum median time past of a block at which the bit gains its meaning"}, {RPCResult::Type::NUM_TIME, "timeout", "the median time past of a block at which the deployment is considered failed if not yet locked in"}, {RPCResult::Type::NUM, "min_activation_height", "minimum height of blocks for which the rules may be enforced"}, - {RPCResult::Type::STR, "status", "bip9 status of specified block (one of \"defined\", \"started\", \"locked_in\", \"active\", \"failed\")"}, + {RPCResult::Type::STR, "status", "status of deployment at specified block (one of \"defined\", \"started\", \"locked_in\", \"active\", \"failed\")"}, {RPCResult::Type::NUM, "since", "height of the first block to which the status applies"}, - {RPCResult::Type::STR, "status-next", "bip9 status of next block"}, + {RPCResult::Type::STR, "status-next", "status of deployment at the next block"}, {RPCResult::Type::OBJ, "statistics", /*optional=*/true, "numeric statistics about signalling for a softfork (only for \"started\" and \"locked_in\" status)", { {RPCResult::Type::NUM, "period", "the length in blocks of the signalling period"}, @@ -1653,9 +1653,9 @@ UniValue DeploymentInfo(const CBlockIndex* tip, const Consensus::Params& consens static RPCHelpMan getdeploymentinfo() { return RPCHelpMan{"getdeploymentinfo", - "Returns an object containing various state info regarding soft-forks.", + "Returns an object containing various state info regarding deployments of consensus changes.", { - {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Default{"chain tip"}, "The block hash at which to query fork state"}, + {"blockhash", RPCArg::Type::STR_HEX, RPCArg::Default{"hash of current chain tip"}, "The block hash at which to query deployment state"}, }, RPCResult{ RPCResult::Type::OBJ, "", "", { From 5179656ef83a563133e32893f4acfd61d1aebdcb Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 28 Jan 2022 17:13:45 +1000 Subject: [PATCH 3/5] trivial: comment tweaks --- src/rpc/blockchain.cpp | 2 +- src/versionbits.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index cd2c5e0b461e6..f68a3d2277acb 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1517,7 +1517,7 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& } namespace { -/* TODO: when -dprecatedrpc=softforks is removed, drop these */ +/* TODO: when -deprecatedrpc=softforks is removed, drop these */ UniValue DeploymentInfo(const CBlockIndex* tip, const Consensus::Params& consensusParams); extern const std::vector RPCHelpForDeployment; } diff --git a/src/versionbits.cpp b/src/versionbits.cpp index 36815fba17899..7a297c2bbb63e 100644 --- a/src/versionbits.cpp +++ b/src/versionbits.cpp @@ -107,7 +107,7 @@ BIP9Stats AbstractThresholdConditionChecker::GetStateStatisticsFor(const CBlockI if (pindex == nullptr) return stats; - // Find beginning of period + // Find how many blocks are in the current period int blocks_in_period = 1 + (pindex->nHeight % stats.period); // Reset signalling_blocks From fbab43f169924c681ef085639b3e4de6c74a4958 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 28 Jan 2022 17:14:29 +1000 Subject: [PATCH 4/5] rpc/blockchain: a constant craving --- src/rpc/blockchain.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index f68a3d2277acb..163f59300f061 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1669,16 +1669,16 @@ static RPCHelpMan getdeploymentinfo() RPCExamples{ HelpExampleCli("getdeploymentinfo", "") + HelpExampleRpc("getdeploymentinfo", "") }, [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue { - ChainstateManager& chainman = EnsureAnyChainman(request.context); + const ChainstateManager& chainman = EnsureAnyChainman(request.context); LOCK(cs_main); - CChainState& active_chainstate = chainman.ActiveChainstate(); + const CChainState& active_chainstate = chainman.ActiveChainstate(); const CBlockIndex* tip; if (request.params[0].isNull()) { tip = active_chainstate.m_chain.Tip(); CHECK_NONFATAL(tip); } else { - uint256 hash(ParseHashV(request.params[0], "blockhash")); + const uint256 hash(ParseHashV(request.params[0], "blockhash")); tip = chainman.m_blockman.LookupBlockIndex(hash); if (!tip) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); From e5f0356e3ffea10f447998b7549a67e016446e81 Mon Sep 17 00:00:00 2001 From: Anthony Towns Date: Fri, 28 Jan 2022 18:04:07 +1000 Subject: [PATCH 5/5] rpc/blockchain: rename getdeploymentinfo tip/active_chain_tip to blockindex --- src/rpc/blockchain.cpp | 50 +++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 163f59300f061..c4894d84b4aa5 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -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. @@ -1440,17 +1440,17 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& rv.pushKV("type", "buried"); // getdeploymentinfo 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("active", DeploymentActiveAfter(blockindex, 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) +static void SoftForkDescPushBack(const CBlockIndex* blockindex, UniValue& softforks, const Consensus::Params& consensusParams, Consensus::DeploymentPos id) { // For BIP9 deployments. if (!DeploymentEnabled(consensusParams, id)) return; - if (active_chain_tip == nullptr) return; + if (blockindex == nullptr) return; auto get_state_name = [](const ThresholdState state) -> std::string { switch (state) { @@ -1465,8 +1465,8 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& UniValue bip9(UniValue::VOBJ); - const ThresholdState next_state = g_versionbitscache.State(active_chain_tip, consensusParams, id); - const ThresholdState current_state = g_versionbitscache.State(active_chain_tip->pprev, consensusParams, id); + const ThresholdState next_state = g_versionbitscache.State(blockindex, 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); @@ -1480,14 +1480,14 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& // BIP9 status 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 signalling status, if applicable if (has_signal) { UniValue statsUV(UniValue::VOBJ); std::vector 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("elapsed", statsStruct.elapsed); statsUV.pushKV("count", statsStruct.count); @@ -1508,7 +1508,7 @@ static void SoftForkDescPushBack(const CBlockIndex* active_chain_tip, UniValue& UniValue rv(UniValue::VOBJ); rv.pushKV("type", "bip9"); 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("bip9", bip9); @@ -1636,16 +1636,16 @@ const std::vector RPCHelpForDeployment{ }}, }; -UniValue DeploymentInfo(const CBlockIndex* tip, const Consensus::Params& consensusParams) +UniValue DeploymentInfo(const CBlockIndex* blockindex, const Consensus::Params& consensusParams) { UniValue softforks(UniValue::VOBJ); - SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_HEIGHTINCB); - SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_DERSIG); - SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_CLTV); - SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_CSV); - SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_SEGWIT); - SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY); - SoftForkDescPushBack(tip, softforks, consensusParams, Consensus::DEPLOYMENT_TAPROOT); + SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_HEIGHTINCB); + SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_DERSIG); + SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_CLTV); + SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_CSV); + SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_SEGWIT); + SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_TESTDUMMY); + SoftForkDescPushBack(blockindex, softforks, consensusParams, Consensus::DEPLOYMENT_TAPROOT); return softforks; } } // anon namespace @@ -1673,14 +1673,14 @@ static RPCHelpMan getdeploymentinfo() LOCK(cs_main); const CChainState& active_chainstate = chainman.ActiveChainstate(); - const CBlockIndex* tip; + const CBlockIndex* blockindex; if (request.params[0].isNull()) { - tip = active_chainstate.m_chain.Tip(); - CHECK_NONFATAL(tip); + blockindex = active_chainstate.m_chain.Tip(); + CHECK_NONFATAL(blockindex); } else { const uint256 hash(ParseHashV(request.params[0], "blockhash")); - tip = chainman.m_blockman.LookupBlockIndex(hash); - if (!tip) { + blockindex = chainman.m_blockman.LookupBlockIndex(hash); + if (!blockindex) { throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); } } @@ -1688,9 +1688,9 @@ static RPCHelpMan getdeploymentinfo() const Consensus::Params& consensusParams = Params().GetConsensus(); UniValue deploymentinfo(UniValue::VOBJ); - deploymentinfo.pushKV("hash", tip->GetBlockHash().ToString()); - deploymentinfo.pushKV("height", tip->nHeight); - deploymentinfo.pushKV("deployments", DeploymentInfo(tip, consensusParams)); + deploymentinfo.pushKV("hash", blockindex->GetBlockHash().ToString()); + deploymentinfo.pushKV("height", blockindex->nHeight); + deploymentinfo.pushKV("deployments", DeploymentInfo(blockindex, consensusParams)); return deploymentinfo; }, };