Skip to content

Commit 9d45415

Browse files
committed
Merge #14518: rpc: Always throw in getblockstats if -txindex is required
3be209d rpc: Always throw in getblockstats if -txindex is required (João Barbosa) Pull request description: Previously blocks with only the coinbase transaction didn't cause the RPC error even if the requested stats required -txindex and it wasn't enabled. Fixes #14499. Tree-SHA512: d3a6402889e3ce7199632e79eba66d7d471ff7de5c564d35312e2340cc6d84ef544a8172548fbc2eedf5e637b56dc57bbf7a9815ab798c7f226755f897fd8f3e
2 parents 754a00d + 3be209d commit 9d45415

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

src/rpc/blockchain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,10 @@ static UniValue getblockstats(const JSONRPCRequest& request)
17981798
const bool do_calculate_weight = do_all || SetHasKeys(stats, "total_weight", "avgfeerate", "swtotal_weight", "avgfeerate", "feerate_percentiles", "minfeerate", "maxfeerate");
17991799
const bool do_calculate_sw = do_all || SetHasKeys(stats, "swtxs", "swtotal_size", "swtotal_weight");
18001800

1801+
if (loop_inputs && !g_txindex) {
1802+
throw JSONRPCError(RPC_INVALID_PARAMETER, "One or more of the selected stats requires -txindex enabled");
1803+
}
1804+
18011805
CAmount maxfee = 0;
18021806
CAmount maxfeerate = 0;
18031807
CAmount minfee = MAX_MONEY;
@@ -1861,10 +1865,6 @@ static UniValue getblockstats(const JSONRPCRequest& request)
18611865
}
18621866

18631867
if (loop_inputs) {
1864-
1865-
if (!g_txindex) {
1866-
throw JSONRPCError(RPC_INVALID_PARAMETER, "One or more of the selected stats requires -txindex enabled");
1867-
}
18681868
CAmount tx_total_in = 0;
18691869
for (const CTxIn& in : tx->vin) {
18701870
CTransactionRef tx_in;

test/functional/rpc_getblockstats.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def run_test(self):
169169
assert_raises_rpc_error(-8, 'Invalid selected statistic aaa%s' % inv_sel_stat,
170170
self.nodes[0].getblockstats, hash_or_height=1, stats=['minfee' , 'aaa%s' % inv_sel_stat])
171171

172+
assert_raises_rpc_error(-8, 'One or more of the selected stats requires -txindex enabled',
173+
self.nodes[1].getblockstats, hash_or_height=1)
172174
assert_raises_rpc_error(-8, 'One or more of the selected stats requires -txindex enabled',
173175
self.nodes[1].getblockstats, hash_or_height=self.start_height + self.max_stat_pos)
174176

0 commit comments

Comments
 (0)