add estimatedheight to getblockchaininfo

Co-authored-by: Aditya Kulkarni <adityapk@gmail.com>
This commit is contained in:
Alfredo Garcia 2019-11-26 19:42:29 -03:00
parent f859ae0067
commit 0f5ef52d2e
2 changed files with 13 additions and 0 deletions

View File

@ -37,6 +37,9 @@ class WalletTest (BitcoinTestFramework):
assert_equal(walletinfo['immature_balance'], 40)
assert_equal(walletinfo['balance'], 0)
blockchaininfo = self.nodes[0].getblockchaininfo()
assert_equal(blockchaininfo['estimatedheight'], 4)
self.sync_all()
self.nodes[1].generate(101)
self.sync_all()
@ -56,6 +59,9 @@ class WalletTest (BitcoinTestFramework):
walletinfo = self.nodes[0].getwalletinfo()
assert_equal(walletinfo['immature_balance'], 0)
blockchaininfo = self.nodes[0].getblockchaininfo()
assert_equal(blockchaininfo['estimatedheight'], 105)
# Have node0 mine a block, thus it will collect its own fee.
self.sync_all()
self.nodes[0].generate(1)

View File

@ -10,6 +10,7 @@
#include "consensus/validation.h"
#include "key_io.h"
#include "main.h"
#include "metrics.h"
#include "primitives/transaction.h"
#include "rpc/server.h"
#include "streams.h"
@ -987,6 +988,7 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
" \"bestblockhash\": \"...\", (string) the hash of the currently best block\n"
" \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
" \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
" \"estimatedheight\": xxxx, (numeric) if syncing, the estimated height of the chain, else the current best height\n"
" \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
" \"size_on_disk\": xxxxxx, (numeric) the estimated size of the block and undo files on disk\n"
" \"commitments\": xxxxxx, (numeric) the current number of note commitments in the commitment tree\n"
@ -1034,6 +1036,11 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("pruned", fPruneMode));
obj.push_back(Pair("size_on_disk", CalculateCurrentUsage()));
if (IsInitialBlockDownload(Params()))
obj.push_back(Pair("estimatedheight", EstimateNetHeight(Params().GetConsensus(), (int)chainActive.Height(), chainActive.Tip()->GetMedianTimePast())));
else
obj.push_back(Pair("estimatedheight", (int)chainActive.Height()));
SproutMerkleTree tree;
pcoinsTip->GetSproutAnchorAt(pcoinsTip->GetBestAnchor(SPROUT), tree);
obj.push_back(Pair("commitments", static_cast<uint64_t>(tree.size())));