diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -1734,20 +1734,22 @@ "ends the window.\n" "\nResult:\n" "{\n" - " \"time\": xxxxx, (numeric) The timestamp for the " - "final block in the window in UNIX format.\n" - " \"txcount\": xxxxx, (numeric) The total number of " - "transactions in the chain up to that point.\n" - " \"window_block_count\": xxxxx, (numeric) Size of the window in " - "number of blocks.\n" - " \"window_tx_count\": xxxxx, (numeric) The number of " - "transactions in the window. Only returned if " + " \"time\": xxxxx, (numeric) The " + "timestamp for the final block in the window in UNIX format.\n" + " \"txcount\": xxxxx, (numeric) The total " + "number of transactions in the chain up to that point.\n" + " \"window_final_block_hash\": \"...\", (string) The hash of " + "the final block in the window.\n" + " \"window_block_count\": xxxxx, (numeric) Size of " + "the window in number of blocks.\n" + " \"window_tx_count\": xxxxx, (numeric) The number " + "of transactions in the window. Only returned if " "\"window_block_count\" is > 0.\n" - " \"window_interval\": xxxxx, (numeric) The elapsed time in " - "the window in seconds. Only returned if \"window_block_count\" is " - "> 0.\n" - " \"txrate\": x.xx, (numeric) The average rate of " - "transactions per second in the window. Only returned if " + " \"window_interval\": xxxxx, (numeric) The elapsed " + "time in the window in seconds. Only returned if " + "\"window_block_count\" is > 0.\n" + " \"txrate\": x.xx, (numeric) The average " + "rate of transactions per second in the window. Only returned if " "\"window_interval\" is > 0.\n" "}\n" "\nExamples:\n" + @@ -1809,6 +1811,7 @@ UniValue ret(UniValue::VOBJ); ret.pushKV("time", int64_t(pindex->nTime)); ret.pushKV("txcount", int64_t(pindex->nChainTx)); + ret.pushKV("window_final_block_hash", pindex->GetBlockHash().GetHex()); ret.pushKV("window_block_count", blockcount); if (blockcount > 0) { ret.pushKV("window_tx_count", nTxDiff); diff --git a/test/functional/rpc_blockchain.py b/test/functional/rpc_blockchain.py --- a/test/functional/rpc_blockchain.py +++ b/test/functional/rpc_blockchain.py @@ -77,6 +77,8 @@ assert_equal(sorted(res.keys()), keys) def _test_getchaintxstats(self): + self.log.info("Test getchaintxstats") + chaintxstats = self.nodes[0].getchaintxstats(1) # 200 txs plus genesis tx assert_equal(chaintxstats['txcount'], 201) @@ -84,22 +86,26 @@ # we have to round because of binary math assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1)) - b1 = self.nodes[0].getblock(self.nodes[0].getblockhash(1)) - b200 = self.nodes[0].getblock(self.nodes[0].getblockhash(200)) + b1_hash = self.nodes[0].getblockhash(1) + b1 = self.nodes[0].getblock(b1_hash) + b200_hash = self.nodes[0].getblockhash(200) + b200 = self.nodes[0].getblock(b200_hash) time_diff = b200['mediantime'] - b1['mediantime'] chaintxstats = self.nodes[0].getchaintxstats() assert_equal(chaintxstats['time'], b200['time']) assert_equal(chaintxstats['txcount'], 201) + assert_equal(chaintxstats['window_final_block_hash'], b200_hash) assert_equal(chaintxstats['window_block_count'], 199) assert_equal(chaintxstats['window_tx_count'], 199) assert_equal(chaintxstats['window_interval'], time_diff) assert_equal( round(chaintxstats['txrate'] * time_diff, 10), Decimal(199)) - chaintxstats = self.nodes[0].getchaintxstats(blockhash=b1['hash']) + chaintxstats = self.nodes[0].getchaintxstats(blockhash=b1_hash) assert_equal(chaintxstats['time'], b1['time']) assert_equal(chaintxstats['txcount'], 2) + assert_equal(chaintxstats['window_final_block_hash'], b1_hash) assert_equal(chaintxstats['window_block_count'], 0) assert('window_tx_count' not in chaintxstats) assert('window_interval' not in chaintxstats)