|
13 | 13 |
|
14 | 14 | class FeatureBlockfilterindexPruneTest(BitcoinTestFramework): |
15 | 15 | def set_test_params(self): |
16 | | - self.num_nodes = 2 |
17 | | - self.extra_args = [["-fastprune", "-prune=1"], ["-fastprune", "-prune=1", "-blockfilterindex=1"]] |
| 16 | + self.num_nodes = 1 |
| 17 | + self.extra_args = [["-fastprune", "-prune=1", "-blockfilterindex=1"]] |
| 18 | + |
| 19 | + def sync_index(self, height): |
| 20 | + expected = {'basic block filter index': {'synced': True, 'best_block_height': height}} |
| 21 | + self.wait_until(lambda: self.nodes[0].getindexinfo() == expected) |
18 | 22 |
|
19 | 23 | def run_test(self): |
20 | 24 | self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned") |
21 | | - self.wait_until(lambda: self.nodes[1].getindexinfo() == {'basic block filter index': {'synced': True, 'best_block_height': 200}}) |
22 | | - assert len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0 |
| 25 | + self.sync_index(height=200) |
| 26 | + assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0) |
23 | 27 | # Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection |
24 | | - self.nodes[1].generate(250) |
| 28 | + self.nodes[0].generate(250) |
25 | 29 | self.sync_all() |
26 | | - self.nodes[1].generate(250) |
| 30 | + self.nodes[0].generate(250) |
27 | 31 | self.sync_all() |
28 | | - self.wait_until(lambda: self.nodes[1].getindexinfo() == {'basic block filter index': {'synced': True, 'best_block_height': 700}}) |
| 32 | + self.sync_index(height=700) |
| 33 | + |
29 | 34 | self.log.info("prune some blocks") |
30 | | - pruneheight = self.nodes[1].pruneblockchain(400) |
| 35 | + pruneheight = self.nodes[0].pruneblockchain(400) |
31 | 36 | assert_equal(pruneheight, 250) |
| 37 | + |
32 | 38 | self.log.info("check if we can access the tips blockfilter when we have pruned some blocks") |
33 | | - assert len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0 |
| 39 | + assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0) |
| 40 | + |
34 | 41 | self.log.info("check if we can access the blockfilter of a pruned block") |
35 | | - assert len(self.nodes[1].getblockfilter(self.nodes[1].getblockhash(2))['filter']) > 0 |
| 42 | + assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getblockhash(2))['filter']), 0) |
| 43 | + |
36 | 44 | self.log.info("start node without blockfilterindex") |
37 | | - self.stop_node(1) |
38 | | - self.start_node(1, extra_args=self.extra_args[0]) |
| 45 | + self.restart_node(0, extra_args=["-fastprune", "-prune=1"]) |
| 46 | + |
39 | 47 | self.log.info("make sure accessing the blockfilters throws an error") |
40 | | - assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[1].getblockfilter, self.nodes[1].getblockhash(2)) |
41 | | - self.nodes[1].generate(1000) |
| 48 | + assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[0].getblockfilter, self.nodes[0].getblockhash(2)) |
| 49 | + self.nodes[0].generate(1000) |
| 50 | + |
42 | 51 | self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled") |
43 | | - pruneheight_new = self.nodes[1].pruneblockchain(1000) |
| 52 | + pruneheight_new = self.nodes[0].pruneblockchain(1000) |
44 | 53 | assert_greater_than(pruneheight_new, pruneheight) |
45 | | - self.stop_node(1) |
| 54 | + self.stop_node(0) |
| 55 | + |
46 | 56 | self.log.info("make sure we get an init error when starting the node again with block filters") |
47 | | - with 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)"]): |
48 | | - self.nodes[1].assert_start_raises_init_error(extra_args=self.extra_args[1]) |
| 57 | + with self.nodes[0].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)"]): |
| 58 | + self.nodes[0].assert_start_raises_init_error(extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1"]) |
| 59 | + |
49 | 60 | self.log.info("make sure the node starts again with the -reindex arg") |
50 | | - reindex_args = self.extra_args[1] |
51 | | - reindex_args.append("-reindex") |
52 | | - self.start_node(1, extra_args=reindex_args) |
| 61 | + self.start_node(0, extra_args = ["-fastprune", "-prune=1", "-blockfilterindex", "-reindex"]) |
53 | 62 |
|
54 | 63 |
|
55 | 64 | if __name__ == '__main__': |
|
0 commit comments