Skip to content

Commit fab34d3

Browse files
author
MarcoFalke
committed
Call CHECK_NONFATAL only once where needed
1 parent f58c1f1 commit fab34d3

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)