mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-23 07:15:29 +01:00
Call CHECK_NONFATAL only once where needed
This commit is contained in:
parent
f58c1f1a44
commit
fab34d392c
1 changed files with 10 additions and 11 deletions
|
@ -1199,24 +1199,23 @@ RPCHelpMan getblockchaininfo()
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
CChainState& active_chainstate = chainman.ActiveChainstate();
|
CChainState& active_chainstate = chainman.ActiveChainstate();
|
||||||
|
|
||||||
const CBlockIndex* tip = CHECK_NONFATAL(active_chainstate.m_chain.Tip());
|
const CBlockIndex& tip{*CHECK_NONFATAL(active_chainstate.m_chain.Tip())};
|
||||||
const int height = tip->nHeight;
|
const int height{tip.nHeight};
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.pushKV("chain", Params().NetworkIDString());
|
obj.pushKV("chain", Params().NetworkIDString());
|
||||||
obj.pushKV("blocks", height);
|
obj.pushKV("blocks", height);
|
||||||
obj.pushKV("headers", chainman.m_best_header ? chainman.m_best_header->nHeight : -1);
|
obj.pushKV("headers", chainman.m_best_header ? chainman.m_best_header->nHeight : -1);
|
||||||
obj.pushKV("bestblockhash", tip->GetBlockHash().GetHex());
|
obj.pushKV("bestblockhash", tip.GetBlockHash().GetHex());
|
||||||
obj.pushKV("difficulty", (double)GetDifficulty(tip));
|
obj.pushKV("difficulty", GetDifficulty(&tip));
|
||||||
obj.pushKV("time", (int64_t)tip->nTime);
|
obj.pushKV("time", int64_t{tip.nTime});
|
||||||
obj.pushKV("mediantime", (int64_t)tip->GetMedianTimePast());
|
obj.pushKV("mediantime", tip.GetMedianTimePast());
|
||||||
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), tip));
|
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), &tip));
|
||||||
obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload());
|
obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload());
|
||||||
obj.pushKV("chainwork", tip->nChainWork.GetHex());
|
obj.pushKV("chainwork", tip.nChainWork.GetHex());
|
||||||
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
|
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
|
||||||
obj.pushKV("pruned", node::fPruneMode);
|
obj.pushKV("pruned", node::fPruneMode);
|
||||||
if (node::fPruneMode) {
|
if (node::fPruneMode) {
|
||||||
const CBlockIndex* block = CHECK_NONFATAL(tip);
|
obj.pushKV("pruneheight", node::GetFirstStoredBlock(&tip)->nHeight);
|
||||||
obj.pushKV("pruneheight", node::GetFirstStoredBlock(block)->nHeight);
|
|
||||||
|
|
||||||
// if 0, execution bypasses the whole if block.
|
// if 0, execution bypasses the whole if block.
|
||||||
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};
|
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};
|
||||||
|
@ -1228,7 +1227,7 @@ RPCHelpMan getblockchaininfo()
|
||||||
|
|
||||||
if (IsDeprecatedRPCEnabled("softforks")) {
|
if (IsDeprecatedRPCEnabled("softforks")) {
|
||||||
const Consensus::Params& consensusParams = Params().GetConsensus();
|
const Consensus::Params& consensusParams = Params().GetConsensus();
|
||||||
obj.pushKV("softforks", DeploymentInfo(tip, consensusParams));
|
obj.pushKV("softforks", DeploymentInfo(&tip, consensusParams));
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.pushKV("warnings", GetWarnings(false).original);
|
obj.pushKV("warnings", GetWarnings(false).original);
|
||||||
|
|
Loading…
Add table
Reference in a new issue