Skip to content

Commit d8fc997

Browse files
committed
Merge #16695: rpc: Add window final block height to getchaintxstats
d48c1e8 Add window final block height to getchaintxstats (Jonathan "Duke" Leto) Pull request description: This patch is motivated by the desire to make the output of `getchaintxstats` more useful and optimized for applications to consume and render the data. Firstly, this data is already available to the RPC, no additional work is done. Currently additional RPC calls will be needed to look up the height of the final block in the window or the block height that began the window. By adding the block height of the final block in the window, the JSON is "self-contained" and applications can calculate the exact block height range of the window with no additional RPC requests. For example, a web application which wants to render historical information for `getchaintxstats` RPC on various window sizes might call the RPC with various window lengths, once per day, and store the JSON results somewhere. Because the final block height of each dataset is included, it's no extra work to determine the exact block window range of each JSON response. ACKs for top commit: promag: ACK d48c1e8. Tree-SHA512: fd4952c125f81a4ad18f7c78498c6b3e265b93cb574832166ac25596321ce84957f971f3f78f37d7e42638dc65f2a5d4d760f289873c9c2f2a82eb00a0f87c3f
2 parents 75142ec + d48c1e8 commit d8fc997

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

doc/release-notes-16695.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Updated RPCs
2+
------------
3+
4+
- The `getchaintxstats` RPC now returns the additional key of
5+
`window_final_block_height`.

src/rpc/blockchain.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,6 +1569,7 @@ static UniValue getchaintxstats(const JSONRPCRequest& request)
15691569
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n"
15701570
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n"
15711571
" \"window_final_block_hash\": \"...\", (string) The hash of the final block in the window.\n"
1572+
" \"window_final_block_height\": xxxxx, (numeric) The height of the final block in the window.\n"
15721573
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n"
15731574
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n"
15741575
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n"
@@ -1619,6 +1620,7 @@ static UniValue getchaintxstats(const JSONRPCRequest& request)
16191620
ret.pushKV("time", (int64_t)pindex->nTime);
16201621
ret.pushKV("txcount", (int64_t)pindex->nChainTx);
16211622
ret.pushKV("window_final_block_hash", pindex->GetBlockHash().GetHex());
1623+
ret.pushKV("window_final_block_height", pindex->nHeight);
16221624
ret.pushKV("window_block_count", blockcount);
16231625
if (blockcount > 0) {
16241626
ret.pushKV("window_tx_count", nTxDiff);

test/functional/rpc_blockchain.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def _test_getchaintxstats(self):
186186
assert_equal(chaintxstats['time'], b200['time'])
187187
assert_equal(chaintxstats['txcount'], 201)
188188
assert_equal(chaintxstats['window_final_block_hash'], b200_hash)
189+
assert_equal(chaintxstats['window_final_block_height'], 200)
189190
assert_equal(chaintxstats['window_block_count'], 199)
190191
assert_equal(chaintxstats['window_tx_count'], 199)
191192
assert_equal(chaintxstats['window_interval'], time_diff)
@@ -195,6 +196,7 @@ def _test_getchaintxstats(self):
195196
assert_equal(chaintxstats['time'], b1['time'])
196197
assert_equal(chaintxstats['txcount'], 2)
197198
assert_equal(chaintxstats['window_final_block_hash'], b1_hash)
199+
assert_equal(chaintxstats['window_final_block_height'], 1)
198200
assert_equal(chaintxstats['window_block_count'], 0)
199201
assert 'window_tx_count' not in chaintxstats
200202
assert 'window_interval' not in chaintxstats

0 commit comments

Comments
 (0)