Auto merge of #4242 - oxarbitrage:issue3726, r=str4d

Add estimatedheight to rpc getblockchaininfo response

Fixes https://github.com/zcash/zcash/issues/3726

Ported from https://github.com/zcash/zcash/pull/3727 with comments addressed.
This commit is contained in:
Homu 2020-05-28 00:49:49 +00:00
commit 4907a31302
2 changed files with 13 additions and 0 deletions

View File

@ -36,6 +36,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()
@ -55,6 +58,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

@ -11,6 +11,7 @@
#include "experimental_features.h"
#include "key_io.h"
#include "main.h"
#include "metrics.h"
#include "primitives/transaction.h"
#include "rpc/server.h"
#include "streams.h"
@ -997,6 +998,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"
@ -1044,6 +1046,11 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp)
obj.pushKV("pruned", fPruneMode);
obj.pushKV("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.pushKV("commitments", static_cast<uint64_t>(tree.size()));