Skip to content

Commit ab3a0a2

Browse files
committed
Add functional test for blockfilterindex in prune-mode
1 parent c286a22 commit ab3a0a2

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2020 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
"""Test blockfilterindex in conjunction with prune."""
6+
from test_framework.test_framework import BitcoinTestFramework
7+
from test_framework.util import (
8+
assert_raises_rpc_error,
9+
assert_greater_than,
10+
)
11+
12+
class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
13+
def set_test_params(self):
14+
self.num_nodes = 2
15+
self.extra_args = [["-fastprune", "-prune=1"], ["-fastprune", "-prune=1", "-blockfilterindex=1"]]
16+
17+
def run_test(self):
18+
# test basic pruning compatibility & filter access of pruned blocks
19+
self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned")
20+
assert(len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0)
21+
self.nodes[1].generate(500)
22+
self.sync_all()
23+
self.log.info("prune some blocks")
24+
pruneheight = self.nodes[1].pruneblockchain(400)
25+
assert(pruneheight != 0)
26+
self.log.info("check if we can access the tips blockfilter when we have pruned some blocks")
27+
assert(len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0)
28+
self.log.info("check if we can access the blockfilter of a pruned block")
29+
assert(len(self.nodes[1].getblockfilter(self.nodes[1].getblockhash(2))['filter']) > 0)
30+
self.log.info("start node without blockfilterindex")
31+
self.stop_node(1)
32+
self.start_node(1, extra_args=self.extra_args[0])
33+
self.log.info("make sure accessing the blockfilters throws an error")
34+
assert_raises_rpc_error(-1,"Index is not enabled for filtertype basic", self.nodes[1].getblockfilter, self.nodes[1].getblockhash(2))
35+
self.nodes[1].generate(1000)
36+
self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled")
37+
pruneheight_new = self.nodes[1].pruneblockchain(1000)
38+
assert_greater_than(pruneheight_new, pruneheight)
39+
self.stop_node(1)
40+
self.log.info("make sure we get an init error when starting the node again with block filters")
41+
self.nodes[1].assert_start_raises_init_error(extra_args=self.extra_args[1])
42+
self.nodes[1].assert_debug_log(["basic block filter index best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)"])
43+
self.log.info("make sure the node starts again with the -reindex arg")
44+
reindex_args = self.extra_args[1]
45+
reindex_args.append("-reindex")
46+
self.start_node(1, extra_args=reindex_args)
47+
48+
if __name__ == '__main__':
49+
FeatureBlockfilterindexPruneTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@
288288
'feature_help.py',
289289
'feature_shutdown.py',
290290
'p2p_ibd_txrelay.py',
291+
'feature_blockfilterindex_prune.py'
291292
# Don't append tests at the end to avoid merge conflicts
292293
# Put them in a random line within the section that fits their approximate run-time
293294
]

0 commit comments

Comments
 (0)