Skip to content

Commit 85123be

Browse files
committed
Merge #12317: Document method for reviewers to verify chainTxData
7444149 Document method for reviewers to verify chainTxData (John Newbery) Pull request description: This commit adds the final block hash of the window to getchaintxstats and documents how reviewers can verify changes to chainTxData. Tree-SHA512: d16abb5f47d058e52660f4d495f1e453205b1b83716d7c810ff62a70338db721386c1808ec1fc8468f514e4d80cc58e3c96eeb3184cbbcb1d07830fa5e53f342
2 parents 4cad916 + 7444149 commit 85123be

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

doc/release-process.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Before every major release:
2424
* Update hardcoded [seeds](/contrib/seeds/README.md), see [this pull request](https://github.com/bitcoin/bitcoin/pull/7415) for an example.
2525
* Update [`BLOCK_CHAIN_SIZE`](/src/qt/intro.cpp) to the current size plus some overhead.
2626
* Update `src/chainparams.cpp` chainTxData with statistics about the transaction count and rate. Use the output of the RPC `getchaintxstats`, see
27-
[this pull request](https://github.com/bitcoin/bitcoin/pull/12270) for an example.
27+
[this pull request](https://github.com/bitcoin/bitcoin/pull/12270) for an example. Reviewers can verify the results by running `getchaintxstats <window_block_count> <window_last_block_hash>` with the `window_block_count` and `window_last_block_hash` from your output.
2828
* Update version of `contrib/gitian-descriptors/*.yml`: usually one'd want to do this on master after branching off the release - but be sure to at least do it before a new major release
2929

3030
### First time / New builders

src/rpc/blockchain.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1526,12 +1526,13 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
15261526
"2. \"blockhash\" (string, optional) The hash of the block that ends the window.\n"
15271527
"\nResult:\n"
15281528
"{\n"
1529-
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n"
1530-
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n"
1531-
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n"
1532-
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n"
1533-
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n"
1534-
" \"txrate\": x.xx, (numeric) The average rate of transactions per second in the window. Only returned if \"window_interval\" is > 0.\n"
1529+
" \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n"
1530+
" \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n"
1531+
" \"window_final_block_hash\": \"...\", (string) The hash of the final block in the window.\n"
1532+
" \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n"
1533+
" \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n"
1534+
" \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n"
1535+
" \"txrate\": x.xx, (numeric) The average rate of transactions per second in the window. Only returned if \"window_interval\" is > 0.\n"
15351536
"}\n"
15361537
"\nExamples:\n"
15371538
+ HelpExampleCli("getchaintxstats", "")
@@ -1582,6 +1583,7 @@ UniValue getchaintxstats(const JSONRPCRequest& request)
15821583
UniValue ret(UniValue::VOBJ);
15831584
ret.push_back(Pair("time", (int64_t)pindex->nTime));
15841585
ret.push_back(Pair("txcount", (int64_t)pindex->nChainTx));
1586+
ret.push_back(Pair("window_final_block_hash", pindex->GetBlockHash().GetHex()));
15851587
ret.push_back(Pair("window_block_count", blockcount));
15861588
if (blockcount > 0) {
15871589
ret.push_back(Pair("window_tx_count", nTxDiff));

test/functional/rpc_blockchain.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,28 +100,34 @@ def _test_getblockchaininfo(self):
100100
assert_greater_than(res['size_on_disk'], 0)
101101

102102
def _test_getchaintxstats(self):
103+
self.log.info("Test getchaintxstats")
104+
103105
chaintxstats = self.nodes[0].getchaintxstats(1)
104106
# 200 txs plus genesis tx
105107
assert_equal(chaintxstats['txcount'], 201)
106108
# tx rate should be 1 per 10 minutes, or 1/600
107109
# we have to round because of binary math
108110
assert_equal(round(chaintxstats['txrate'] * 600, 10), Decimal(1))
109111

110-
b1 = self.nodes[0].getblock(self.nodes[0].getblockhash(1))
111-
b200 = self.nodes[0].getblock(self.nodes[0].getblockhash(200))
112+
b1_hash = self.nodes[0].getblockhash(1)
113+
b1 = self.nodes[0].getblock(b1_hash)
114+
b200_hash = self.nodes[0].getblockhash(200)
115+
b200 = self.nodes[0].getblock(b200_hash)
112116
time_diff = b200['mediantime'] - b1['mediantime']
113117

114118
chaintxstats = self.nodes[0].getchaintxstats()
115119
assert_equal(chaintxstats['time'], b200['time'])
116120
assert_equal(chaintxstats['txcount'], 201)
121+
assert_equal(chaintxstats['window_final_block_hash'], b200_hash)
117122
assert_equal(chaintxstats['window_block_count'], 199)
118123
assert_equal(chaintxstats['window_tx_count'], 199)
119124
assert_equal(chaintxstats['window_interval'], time_diff)
120125
assert_equal(round(chaintxstats['txrate'] * time_diff, 10), Decimal(199))
121126

122-
chaintxstats = self.nodes[0].getchaintxstats(blockhash=b1['hash'])
127+
chaintxstats = self.nodes[0].getchaintxstats(blockhash=b1_hash)
123128
assert_equal(chaintxstats['time'], b1['time'])
124129
assert_equal(chaintxstats['txcount'], 2)
130+
assert_equal(chaintxstats['window_final_block_hash'], b1_hash)
125131
assert_equal(chaintxstats['window_block_count'], 0)
126132
assert('window_tx_count' not in chaintxstats)
127133
assert('window_interval' not in chaintxstats)
@@ -173,8 +179,7 @@ def _test_gettxoutsetinfo(self):
173179
def _test_getblockheader(self):
174180
node = self.nodes[0]
175181

176-
assert_raises_rpc_error(-5, "Block not found",
177-
node.getblockheader, "nonsense")
182+
assert_raises_rpc_error(-5, "Block not found", node.getblockheader, "nonsense")
178183

179184
besthash = node.getbestblockhash()
180185
secondbesthash = node.getblockhash(199)

0 commit comments

Comments
 (0)