Merge pull request #99 from ch4ot1c/fixup/network-difficulty-merge

Fix segfaults by using chain tip header
This commit is contained in:
Jon Layton 2018-10-24 18:48:07 -05:00 committed by GitHub
commit 9d72497c27
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 5 additions and 4 deletions

View File

@ -71,8 +71,9 @@ double GetDifficultyINTERNAL(const CBlockIndex* blockindex, bool networkDifficul
}
uint32_t bits;
auto tipblock = chainActive.Tip()->GetBlockHeader();
if (networkDifficulty) {
bits = GetNextWorkRequired(blockindex, nullptr, Params());
bits = GetNextWorkRequired(blockindex, &tipblock, Params());
} else {
bits = blockindex->nBits;
}
@ -1281,7 +1282,7 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
obj.pushKV("blocks", (int)chainActive.Height());
obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1);
obj.pushKV("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex());
obj.pushKV("difficulty", (double)GetNetworkDifficulty());
obj.pushKV("difficulty", (double)GetDifficulty(chainActive.Tip()));
obj.pushKV("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast());
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), chainActive.Tip()));
obj.pushKV("initialblockdownload", IsInitialBlockDownload());

View File

@ -23,7 +23,7 @@ static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
*/
double GetDifficulty(const CBlockIndex* blockindex = nullptr);
double GetNetworkDifficulty(const CBlockIndex* blockindex = nullptr);
double GetNetworkDifficulty(const CBlockIndex* blockindex);
/** Callback for when block tip changed. */
void RPCNotifyBlockChange(bool ibd, const CBlockIndex *);

View File

@ -254,7 +254,7 @@ static UniValue getmininginfo(const JSONRPCRequest& request)
obj.pushKV("blocks", (int)chainActive.Height());
obj.pushKV("currentblockweight", (uint64_t)nLastBlockWeight);
obj.pushKV("currentblocktx", (uint64_t)nLastBlockTx);
obj.pushKV("difficulty", (double)GetNetworkDifficulty());
obj.pushKV("difficulty", (double)GetNetworkDifficulty(chainActive.Tip()));
obj.pushKV("networkhashps", getnetworkhashps(request));
obj.pushKV("pooledtx", (uint64_t)mempool.size());
obj.pushKV("chain", Params().NetworkIDString());