@@ -51,10 +51,11 @@ double GetDifficulty(const CBlockIndex* blockindex)
5151 // Floating point number that is a multiple of the minimum difficulty,
5252 // minimum difficulty = 1.0.
5353 if (blockindex == NULL ) {
54- if (chainActive.Tip () == NULL )
54+ const CBlockIndex* pChainTip = GetChainTip ();
55+ if (!pChainTip)
5556 return 1.0 ;
5657 else
57- blockindex = chainActive. Tip () ;
58+ blockindex = pChainTip ;
5859 }
5960
6061 int nShift = (blockindex->nBits >> 24 ) & 0xff ;
@@ -796,7 +797,7 @@ UniValue verifychain(const JSONRPCRequest& request)
796797}
797798
798799/* * Implementation of IsSuperMajority with better feedback */
799- static UniValue SoftForkMajorityDesc (int version, CBlockIndex* pindex, const Consensus::Params& consensusParams)
800+ static UniValue SoftForkMajorityDesc (int version, const CBlockIndex* pindex, const Consensus::Params& consensusParams)
800801{
801802 UniValue rv (UniValue::VOBJ);
802803 Consensus::UpgradeIndex idx;
@@ -825,7 +826,8 @@ static UniValue SoftForkMajorityDesc(int version, CBlockIndex* pindex, const Con
825826 rv.push_back (Pair (" status" , consensusParams.NetworkUpgradeActive (pindex->nHeight , idx)));
826827 return rv;
827828}
828- static UniValue SoftForkDesc (const std::string &name, int version, CBlockIndex* pindex)
829+
830+ static UniValue SoftForkDesc (const std::string &name, int version, const CBlockIndex* pindex)
829831{
830832 const Consensus::Params& consensus = Params ().GetConsensus ();
831833 UniValue rv (UniValue::VOBJ);
@@ -906,22 +908,23 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
906908 LOCK (cs_main);
907909
908910 const Consensus::Params& consensusParams = Params ().GetConsensus ();
911+ const CBlockIndex* pChainTip = chainActive.Tip ();
912+ int nTipHeight = pChainTip ? pChainTip->nHeight : -1 ;
909913
910914 UniValue obj (UniValue::VOBJ);
911915 obj.push_back (Pair (" chain" , Params ().NetworkIDString ()));
912- obj.push_back (Pair (" blocks" , ( int )chainActive. Height () ));
916+ obj.push_back (Pair (" blocks" , nTipHeight ));
913917 obj.push_back (Pair (" headers" , pindexBestHeader ? pindexBestHeader->nHeight : -1 ));
914- obj.push_back (Pair (" bestblockhash" , chainActive. Tip () ->GetBlockHash ().GetHex ()));
918+ obj.push_back (Pair (" bestblockhash" , pChainTip ? pChainTip ->GetBlockHash ().GetHex () : " " ));
915919 obj.push_back (Pair (" difficulty" , (double )GetDifficulty ()));
916- obj.push_back (Pair (" verificationprogress" , Checkpoints::GuessVerificationProgress (chainActive.Tip ())));
917- obj.push_back (Pair (" chainwork" , chainActive.Tip ()->nChainWork .GetHex ()));
918- CBlockIndex* tip = chainActive.Tip ();
920+ obj.push_back (Pair (" verificationprogress" , Checkpoints::GuessVerificationProgress (pChainTip)));
921+ obj.push_back (Pair (" chainwork" , pChainTip ? pChainTip->nChainWork .GetHex () : " " ));
919922 UniValue softforks (UniValue::VARR);
920- softforks.push_back (SoftForkDesc (" bip65" , 5 , tip ));
923+ softforks.push_back (SoftForkDesc (" bip65" , 5 , pChainTip ));
921924 obj.push_back (Pair (" softforks" , softforks));
922925 UniValue upgrades (UniValue::VOBJ);
923926 for (int i = Consensus::BASE_NETWORK + 1 ; i < (int ) Consensus::MAX_NETWORK_UPGRADES; i++) {
924- NetworkUpgradeDescPushBack (upgrades, consensusParams, Consensus::UpgradeIndex (i), tip-> nHeight );
927+ NetworkUpgradeDescPushBack (upgrades, consensusParams, Consensus::UpgradeIndex (i), nTipHeight );
925928 }
926929 obj.push_back (Pair (" upgrades" , upgrades));
927930
0 commit comments