diff options
author | MacroFake <falke.marco@gmail.com> | 2022-04-28 20:23:19 +0200 |
---|---|---|
committer | MacroFake <falke.marco@gmail.com> | 2022-04-28 20:23:22 +0200 |
commit | dabec990135cc32584e822126ec49f8b31350837 (patch) | |
tree | 364a15871969cb714951b4efe8f201c7c5bca2a4 /src | |
parent | 8730bd3fc87c8a7d44347267e1ff3c7a8674201b (diff) | |
parent | fab34d392ca415c27605040dc0fc738016c9a0ca (diff) | |
download | bitcoin-dabec990135cc32584e822126ec49f8b31350837.tar.xz |
Merge bitcoin/bitcoin#24956: Call CHECK_NONFATAL only once where needed
fab34d392ca415c27605040dc0fc738016c9a0ca Call CHECK_NONFATAL only once where needed (MarcoFalke)
Pull request description:
Now that `CHECK_NONFATAL` is the identity function starting with commit b1c5991eebb916755be188f355ad36fe01a3f529, 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 fab34d392ca415c27605040dc0fc738016c9a0ca
Tree-SHA512: ae221d7ee81f8d0be7ab21ce54d5d209e691df8a5c7f4a6f6db282453391904f87f533a2b7f85d6259827de8b85dacd9e0d9dbeecc4245a338247e0893ff3459
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/blockchain.cpp | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 398b948388..96e9efb288 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1199,24 +1199,23 @@ RPCHelpMan getblockchaininfo() LOCK(cs_main); CChainState& active_chainstate = chainman.ActiveChainstate(); - const CBlockIndex* tip = CHECK_NONFATAL(active_chainstate.m_chain.Tip()); - const int height = tip->nHeight; + const CBlockIndex& tip{*CHECK_NONFATAL(active_chainstate.m_chain.Tip())}; + const int height{tip.nHeight}; UniValue obj(UniValue::VOBJ); obj.pushKV("chain", Params().NetworkIDString()); obj.pushKV("blocks", height); obj.pushKV("headers", chainman.m_best_header ? chainman.m_best_header->nHeight : -1); - obj.pushKV("bestblockhash", tip->GetBlockHash().GetHex()); - obj.pushKV("difficulty", (double)GetDifficulty(tip)); - obj.pushKV("time", (int64_t)tip->nTime); - obj.pushKV("mediantime", (int64_t)tip->GetMedianTimePast()); - obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), tip)); + obj.pushKV("bestblockhash", tip.GetBlockHash().GetHex()); + obj.pushKV("difficulty", GetDifficulty(&tip)); + obj.pushKV("time", int64_t{tip.nTime}); + obj.pushKV("mediantime", tip.GetMedianTimePast()); + obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), &tip)); 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("pruned", node::fPruneMode); if (node::fPruneMode) { - const CBlockIndex* block = CHECK_NONFATAL(tip); - obj.pushKV("pruneheight", node::GetFirstStoredBlock(block)->nHeight); + obj.pushKV("pruneheight", node::GetFirstStoredBlock(&tip)->nHeight); // if 0, execution bypasses the whole if block. bool automatic_pruning{args.GetIntArg("-prune", 0) != 1}; @@ -1228,7 +1227,7 @@ RPCHelpMan getblockchaininfo() if (IsDeprecatedRPCEnabled("softforks")) { const Consensus::Params& consensusParams = Params().GetConsensus(); - obj.pushKV("softforks", DeploymentInfo(tip, consensusParams)); + obj.pushKV("softforks", DeploymentInfo(&tip, consensusParams)); } obj.pushKV("warnings", GetWarnings(false).original); |