@@ -58,10 +58,7 @@ static CUpdatedBlock latestblock;
5858 */
5959double GetDifficulty (const CBlockIndex* blockindex)
6060{
61- if (blockindex == nullptr )
62- {
63- return 1.0 ;
64- }
61+ assert (blockindex);
6562
6663 int nShift = (blockindex->nBits >> 24 ) & 0xff ;
6764 double dDiff =
@@ -1247,20 +1244,21 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
12471244
12481245 LOCK (cs_main);
12491246
1247+ const CBlockIndex* tip = chainActive.Tip ();
12501248 UniValue obj (UniValue::VOBJ);
12511249 obj.pushKV (" chain" , Params ().NetworkIDString ());
12521250 obj.pushKV (" blocks" , (int )chainActive.Height ());
12531251 obj.pushKV (" headers" , pindexBestHeader ? pindexBestHeader->nHeight : -1 );
1254- obj.pushKV (" bestblockhash" , chainActive. Tip () ->GetBlockHash ().GetHex ());
1255- obj.pushKV (" difficulty" , (double )GetDifficulty (chainActive. Tip () ));
1256- obj.pushKV (" mediantime" , (int64_t )chainActive. Tip () ->GetMedianTimePast ());
1257- obj.pushKV (" verificationprogress" , GuessVerificationProgress (Params ().TxData (), chainActive. Tip () ));
1252+ obj.pushKV (" bestblockhash" , tip ->GetBlockHash ().GetHex ());
1253+ obj.pushKV (" difficulty" , (double )GetDifficulty (tip ));
1254+ obj.pushKV (" mediantime" , (int64_t )tip ->GetMedianTimePast ());
1255+ obj.pushKV (" verificationprogress" , GuessVerificationProgress (Params ().TxData (), tip ));
12581256 obj.pushKV (" initialblockdownload" , IsInitialBlockDownload ());
1259- obj.pushKV (" chainwork" , chainActive. Tip () ->nChainWork .GetHex ());
1257+ obj.pushKV (" chainwork" , tip ->nChainWork .GetHex ());
12601258 obj.pushKV (" size_on_disk" , CalculateCurrentUsage ());
12611259 obj.pushKV (" pruned" , fPruneMode );
12621260 if (fPruneMode ) {
1263- CBlockIndex* block = chainActive. Tip () ;
1261+ const CBlockIndex* block = tip ;
12641262 assert (block);
12651263 while (block->pprev && (block->pprev ->nStatus & BLOCK_HAVE_DATA)) {
12661264 block = block->pprev ;
@@ -1277,7 +1275,6 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
12771275 }
12781276
12791277 const Consensus::Params& consensusParams = Params ().GetConsensus ();
1280- CBlockIndex* tip = chainActive.Tip ();
12811278 UniValue softforks (UniValue::VARR);
12821279 UniValue bip9_softforks (UniValue::VOBJ);
12831280 softforks.push_back (SoftForkDesc (" bip34" , 2 , tip, consensusParams));
0 commit comments