From ed9aa2b62a9c65d152f7560368d407794caa6d72 Mon Sep 17 00:00:00 2001 From: Jack Grigg Date: Wed, 21 Feb 2018 21:02:09 +0000 Subject: [PATCH] Add branch IDs for current and next block to getblockchaininfo Closes #2974. --- qa/rpc-tests/wallet_overwintertx.py | 8 ++++++++ src/rpcblockchain.cpp | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/qa/rpc-tests/wallet_overwintertx.py b/qa/rpc-tests/wallet_overwintertx.py index 84215eb6b..91bdb7764 100755 --- a/qa/rpc-tests/wallet_overwintertx.py +++ b/qa/rpc-tests/wallet_overwintertx.py @@ -38,6 +38,9 @@ class WalletOverwinterTxTest (BitcoinTestFramework): # # Currently at block 198. The next block to be mined 199 is a Sprout block # + assert_equal(self.nodes[0].getblockchaininfo()['consensus']['chaintip'], '00000000') + assert_equal(self.nodes[0].getblockchaininfo()['consensus']['nextblock'], '00000000') + taddr0 = self.nodes[0].getnewaddress() taddr2 = self.nodes[2].getnewaddress() zaddr2 = self.nodes[2].z_getnewaddress() @@ -76,6 +79,8 @@ class WalletOverwinterTxTest (BitcoinTestFramework): # # Currently at block 199. The next block to be mined 200 is an Overwinter block # + assert_equal(self.nodes[0].getblockchaininfo()['consensus']['chaintip'], '00000000') + assert_equal(self.nodes[0].getblockchaininfo()['consensus']['nextblock'], '5ba81b19') # Send taddr to taddr tsendamount = Decimal('4.56') @@ -88,9 +93,12 @@ class WalletOverwinterTxTest (BitcoinTestFramework): myopid = self.nodes[0].z_sendmany(taddr0, recipients) txid_shielded = wait_and_assert_operationid_status(self.nodes[0], myopid) + # Mine the first Overwinter block self.sync_all() self.nodes[0].generate(1) self.sync_all() + assert_equal(self.nodes[0].getblockchaininfo()['consensus']['chaintip'], '5ba81b19') + assert_equal(self.nodes[0].getblockchaininfo()['consensus']['nextblock'], '5ba81b19') # Verify balance assert_equal(self.nodes[3].getbalance(), tsendamount) diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index ebd4a733a..32f3f0fee 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -726,6 +726,10 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) " \"status\": \"xxxx\", (string) status of upgrade\n" " \"info\": \"xxxx\", (string) additional information about upgrade\n" " }, ...\n" + " },\n" + " \"consensus\": { (object) branch IDs of the current and upcoming consensus rules\n" + " \"chaintip\": \"xxxxxxxx\", (string) branch ID used to validate the current chain tip\n" + " \"nextblock\": \"xxxxxxxx\" (string) branch ID that the next block will be validated under\n" " }\n" "}\n" "\nExamples:\n" @@ -767,6 +771,11 @@ UniValue getblockchaininfo(const UniValue& params, bool fHelp) } obj.push_back(Pair("upgrades", upgrades)); + UniValue consensus(UniValue::VOBJ); + consensus.push_back(Pair("chaintip", HexInt(CurrentEpochBranchId(tip->nHeight, consensusParams)))); + consensus.push_back(Pair("nextblock", HexInt(CurrentEpochBranchId(tip->nHeight + 1, consensusParams)))); + obj.push_back(Pair("consensus", consensus)); + if (fPruneMode) { CBlockIndex *block = chainActive.Tip();