@@ -58,10 +58,7 @@ static CUpdatedBlock latestblock;
58
58
*/
59
59
double GetDifficulty (const CBlockIndex* blockindex)
60
60
{
61
- if (blockindex == nullptr )
62
- {
63
- return 1.0 ;
64
- }
61
+ assert (blockindex);
65
62
66
63
int nShift = (blockindex->nBits >> 24 ) & 0xff ;
67
64
double dDiff =
@@ -1247,20 +1244,21 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
1247
1244
1248
1245
LOCK (cs_main);
1249
1246
1247
+ const CBlockIndex* tip = chainActive.Tip ();
1250
1248
UniValue obj (UniValue::VOBJ);
1251
1249
obj.pushKV (" chain" , Params ().NetworkIDString ());
1252
1250
obj.pushKV (" blocks" , (int )chainActive.Height ());
1253
1251
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 ));
1258
1256
obj.pushKV (" initialblockdownload" , IsInitialBlockDownload ());
1259
- obj.pushKV (" chainwork" , chainActive. Tip () ->nChainWork .GetHex ());
1257
+ obj.pushKV (" chainwork" , tip ->nChainWork .GetHex ());
1260
1258
obj.pushKV (" size_on_disk" , CalculateCurrentUsage ());
1261
1259
obj.pushKV (" pruned" , fPruneMode );
1262
1260
if (fPruneMode ) {
1263
- CBlockIndex* block = chainActive. Tip () ;
1261
+ const CBlockIndex* block = tip ;
1264
1262
assert (block);
1265
1263
while (block->pprev && (block->pprev ->nStatus & BLOCK_HAVE_DATA)) {
1266
1264
block = block->pprev ;
@@ -1277,7 +1275,6 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
1277
1275
}
1278
1276
1279
1277
const Consensus::Params& consensusParams = Params ().GetConsensus ();
1280
- CBlockIndex* tip = chainActive.Tip ();
1281
1278
UniValue softforks (UniValue::VARR);
1282
1279
UniValue bip9_softforks (UniValue::VOBJ);
1283
1280
softforks.push_back (SoftForkDesc (" bip34" , 2 , tip, consensusParams));
0 commit comments