mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-14 05:42:36 -03:00
rpc: Specify chain tip instead of chain in GetDifficulty
This commit is contained in:
parent
54dc13b6a2
commit
343b98cbcd
2 changed files with 8 additions and 18 deletions
|
@ -58,10 +58,7 @@ static CUpdatedBlock latestblock;
|
||||||
*/
|
*/
|
||||||
double GetDifficulty(const CBlockIndex* blockindex)
|
double GetDifficulty(const CBlockIndex* blockindex)
|
||||||
{
|
{
|
||||||
if (blockindex == nullptr)
|
assert(blockindex);
|
||||||
{
|
|
||||||
return 1.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int nShift = (blockindex->nBits >> 24) & 0xff;
|
int nShift = (blockindex->nBits >> 24) & 0xff;
|
||||||
double dDiff =
|
double dDiff =
|
||||||
|
@ -1247,20 +1244,21 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
|
||||||
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
|
const CBlockIndex* tip = chainActive.Tip();
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
obj.pushKV("chain", Params().NetworkIDString());
|
obj.pushKV("chain", Params().NetworkIDString());
|
||||||
obj.pushKV("blocks", (int)chainActive.Height());
|
obj.pushKV("blocks", (int)chainActive.Height());
|
||||||
obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1);
|
obj.pushKV("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1);
|
||||||
obj.pushKV("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex());
|
obj.pushKV("bestblockhash", tip->GetBlockHash().GetHex());
|
||||||
obj.pushKV("difficulty", (double)GetDifficulty(chainActive.Tip()));
|
obj.pushKV("difficulty", (double)GetDifficulty(tip));
|
||||||
obj.pushKV("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast());
|
obj.pushKV("mediantime", (int64_t)tip->GetMedianTimePast());
|
||||||
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), chainActive.Tip()));
|
obj.pushKV("verificationprogress", GuessVerificationProgress(Params().TxData(), tip));
|
||||||
obj.pushKV("initialblockdownload", IsInitialBlockDownload());
|
obj.pushKV("initialblockdownload", IsInitialBlockDownload());
|
||||||
obj.pushKV("chainwork", chainActive.Tip()->nChainWork.GetHex());
|
obj.pushKV("chainwork", tip->nChainWork.GetHex());
|
||||||
obj.pushKV("size_on_disk", CalculateCurrentUsage());
|
obj.pushKV("size_on_disk", CalculateCurrentUsage());
|
||||||
obj.pushKV("pruned", fPruneMode);
|
obj.pushKV("pruned", fPruneMode);
|
||||||
if (fPruneMode) {
|
if (fPruneMode) {
|
||||||
CBlockIndex* block = chainActive.Tip();
|
const CBlockIndex* block = tip;
|
||||||
assert(block);
|
assert(block);
|
||||||
while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) {
|
while (block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA)) {
|
||||||
block = block->pprev;
|
block = block->pprev;
|
||||||
|
@ -1277,7 +1275,6 @@ UniValue getblockchaininfo(const JSONRPCRequest& request)
|
||||||
}
|
}
|
||||||
|
|
||||||
const Consensus::Params& consensusParams = Params().GetConsensus();
|
const Consensus::Params& consensusParams = Params().GetConsensus();
|
||||||
CBlockIndex* tip = chainActive.Tip();
|
|
||||||
UniValue softforks(UniValue::VARR);
|
UniValue softforks(UniValue::VARR);
|
||||||
UniValue bip9_softforks(UniValue::VOBJ);
|
UniValue bip9_softforks(UniValue::VOBJ);
|
||||||
softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams));
|
softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams));
|
||||||
|
|
|
@ -68,11 +68,4 @@ BOOST_AUTO_TEST_CASE(get_difficulty_for_very_high_target)
|
||||||
TestDifficulty(0x12345678, 5913134931067755359633408.0);
|
TestDifficulty(0x12345678, 5913134931067755359633408.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify that difficulty is 1.0 for an empty chain.
|
|
||||||
BOOST_AUTO_TEST_CASE(get_difficulty_for_null_tip)
|
|
||||||
{
|
|
||||||
double difficulty = GetDifficulty(nullptr);
|
|
||||||
RejectDifficultyMismatch(difficulty, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
Loading…
Reference in a new issue