Skip to content

Commit dabec99

Browse files
author
MacroFake
committed
Merge bitcoin/bitcoin#24956: Call CHECK_NONFATAL only once where needed
fab34d3 Call CHECK_NONFATAL only once where needed (MarcoFalke) Pull request description: Now that `CHECK_NONFATAL` is the identity function starting with commit b1c5991, it can be called less often in places where it was called more than once on the same value. ACKs for top commit: jonatack: Review ACK fab34d3 Tree-SHA512: ae221d7ee81f8d0be7ab21ce54d5d209e691df8a5c7f4a6f6db282453391904f87f533a2b7f85d6259827de8b85dacd9e0d9dbeecc4245a338247e0893ff3459
2 parents 8730bd3 + fab34d3 commit dabec99

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/rpc/blockchain.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,24 +1199,23 @@ RPCHelpMan getblockchaininfo()
11991199
LOCK(cs_main);
12001200
CChainState& active_chainstate = chainman.ActiveChainstate();
12011201

1202-
const CBlockIndex* tip = CHECK_NONFATAL(active_chainstate.m_chain.Tip());
1203-
const int height = tip->nHeight;
1202+
const CBlockIndex& tip{*CHECK_NONFATAL(active_chainstate.m_chain.Tip())};
1203+
const int height{tip.nHeight};
12041204
UniValue obj(UniValue::VOBJ);
12051205
obj.pushKV("chain", Params().NetworkIDString());
12061206
obj.pushKV("blocks", height);
12071207
obj.pushKV("headers", chainman.m_best_header ? chainman.m_best_header->nHeight : -1);
1208-
obj.pushKV("bestblockhash", tip->GetBlockHash().GetHex());
1209-
obj.pushKV("difficulty", (double)GetDifficulty(tip));
1210-
obj.pushKV("time", (int64_t)tip->nTime);
1211-
obj.pushKV("mediantime", (int64_t)tip->GetMedianTimePast());
1212-
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), tip));
1208+
obj.pushKV("bestblockhash", tip.GetBlockHash().GetHex());
1209+
obj.pushKV("difficulty", GetDifficulty(&tip));
1210+
obj.pushKV("time", int64_t{tip.nTime});
1211+
obj.pushKV("mediantime", tip.GetMedianTimePast());
1212+
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), &tip));
12131213
obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload());
1214-
obj.pushKV("chainwork", tip->nChainWork.GetHex());
1214+
obj.pushKV("chainwork", tip.nChainWork.GetHex());
12151215
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
12161216
obj.pushKV("pruned", node::fPruneMode);
12171217
if (node::fPruneMode) {
1218-
const CBlockIndex* block = CHECK_NONFATAL(tip);
1219-
obj.pushKV("pruneheight", node::GetFirstStoredBlock(block)->nHeight);
1218+
obj.pushKV("pruneheight", node::GetFirstStoredBlock(&tip)->nHeight);
12201219

12211220
// if 0, execution bypasses the whole if block.
12221221
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};
@@ -1228,7 +1227,7 @@ RPCHelpMan getblockchaininfo()
12281227

12291228
if (IsDeprecatedRPCEnabled("softforks")) {
12301229
const Consensus::Params& consensusParams = Params().GetConsensus();
1231-
obj.pushKV("softforks", DeploymentInfo(tip, consensusParams));
1230+
obj.pushKV("softforks", DeploymentInfo(&tip, consensusParams));
12321231
}
12331232

12341233
obj.pushKV("warnings", GetWarnings(false).original);

0 commit comments

Comments
 (0)