|
1 | | -#!/usr/bin/env python3 |
2 | | -# Copyright (c) 2020-2021 The DigiByte 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 DigiByteTestFramework |
7 | | -from test_framework import test_node |
8 | | -from test_framework.util import ( |
9 | | - assert_equal, |
10 | | - assert_greater_than, |
11 | | - assert_raises_rpc_error, |
12 | | -) |
13 | | - |
14 | | -import time |
15 | | - |
16 | | - |
17 | | -class FeatureBlockfilterindexPruneTest(DigiByteTestFramework): |
18 | | - def set_test_params(self): |
19 | | - self.num_nodes = 1 |
20 | | - self.extra_args = [["-fastprune", "-prune=1", "-blockfilterindex=1"]] |
21 | | - |
22 | | - def sync_index(self, height): |
23 | | - expected = {'basic block filter index': {'synced': True, 'best_block_height': height}} |
24 | | - self.wait_until(lambda: self.nodes[0].getindexinfo() == expected) |
25 | | - |
26 | | - def run_test(self): |
27 | | - self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned") |
28 | | - self.sync_index(height=200) |
29 | | - assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0) |
30 | | - self.generate(self.nodes[0], 500) |
31 | | - self.sync_index(height=700) |
32 | | - |
33 | | - self.log.info("prune some blocks") |
34 | | - pruneheight = self.nodes[0].pruneblockchain(400) |
35 | | - # the prune heights used here and below are magic numbers that are determined by the |
36 | | - # thresholds at which block files wrap, so they depend on disk serialization and default block file size. |
37 | | - assert_equal(pruneheight, 249) |
38 | | - |
39 | | - self.log.info("check if we can access the tips blockfilter when we have pruned some blocks") |
40 | | - assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0) |
41 | | - |
42 | | - self.log.info("check if we can access the blockfilter of a pruned block") |
43 | | - assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getblockhash(2))['filter']), 0) |
44 | | - |
45 | | - # mine and sync index up to a height that will later be the pruneheight |
46 | | - self.generate(self.nodes[0], 298) |
47 | | - |
48 | | - self.sync_index(height=998) |
49 | | - |
50 | | - self.log.info("start node without blockfilterindex") |
51 | | - self.restart_node(0, extra_args=["-fastprune", "-prune=1"]) |
52 | | - |
53 | | - self.log.info("make sure accessing the blockfilters throws an error") |
54 | | - assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[0].getblockfilter, self.nodes[0].getblockhash(2)) |
55 | | - |
56 | | - # Generate 502 blocks |
57 | | - self.generate(self.nodes[0], 287) |
58 | | - |
59 | | - self.log.info("prune exactly up to the blockfilterindexes best block while blockfilters are disabled") |
60 | | - pruneheight_2 = self.nodes[0].pruneblockchain(1000) |
61 | | - assert_equal(pruneheight_2, 751) |
62 | | - |
63 | | - self.restart_node(0, extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1"]) |
64 | | - self.log.info("make sure that we can continue with the partially synced index after having pruned up to the index height") |
65 | | - self.sync_index(height=1285) |
66 | | - |
67 | | - self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled") |
68 | | - self.restart_node(0, extra_args=["-fastprune", "-prune=1"]) |
69 | | - self.generate(self.nodes[0], 1000) |
70 | | - pruneheight_3 = self.nodes[0].pruneblockchain(2000) |
71 | | - assert_greater_than(pruneheight_3, pruneheight_2) |
72 | | - self.stop_node(0) |
73 | | - |
74 | | - self.log.info("make sure we get an init error when starting the node again with block filters") |
75 | | - self.nodes[0].assert_start_raises_init_error( |
76 | | - extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1"], |
77 | | - expected_msg="Error: 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\\)", |
78 | | - match=test_node.ErrorMatch.PARTIAL_REGEX, |
79 | | - ) |
80 | | - |
81 | | - self.log.info("make sure the node starts again with the -reindex arg") |
82 | | - self.start_node(0, extra_args=["-fastprune", "-prune=1", "-blockfilterindex", "-reindex"]) |
83 | | - |
84 | | - |
85 | | -if __name__ == '__main__': |
86 | | - FeatureBlockfilterindexPruneTest().main() |
| 1 | +#!/usr/bin/env python3 |
| 2 | +# Copyright (c) 2020-2021 The DigiByte 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 DigiByteTestFramework |
| 7 | +from test_framework import test_node |
| 8 | +from test_framework.util import ( |
| 9 | + assert_equal, |
| 10 | + assert_greater_than, |
| 11 | + assert_raises_rpc_error, |
| 12 | +) |
| 13 | + |
| 14 | +import time |
| 15 | + |
| 16 | + |
| 17 | +class FeatureBlockfilterindexPruneTest(DigiByteTestFramework): |
| 18 | + def set_test_params(self): |
| 19 | + self.num_nodes = 1 |
| 20 | + self.extra_args = [["-fastprune", "-prune=1", "-blockfilterindex=1", "-mintxfee=0.1"]] |
| 21 | + |
| 22 | + def sync_index(self, height): |
| 23 | + expected = {'basic block filter index': {'synced': True, 'best_block_height': height}} |
| 24 | + self.wait_until(lambda: self.nodes[0].getindexinfo() == expected) |
| 25 | + |
| 26 | + def run_test(self): |
| 27 | + self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned") |
| 28 | + self.sync_index(height=200) |
| 29 | + assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0) |
| 30 | + self.generate(self.nodes[0], 500) |
| 31 | + self.sync_index(height=700) |
| 32 | + |
| 33 | + self.log.info("prune some blocks") |
| 34 | + pruneheight = self.nodes[0].pruneblockchain(400) |
| 35 | + # the prune heights used here and below are magic numbers that are determined by the |
| 36 | + # thresholds at which block files wrap, so they depend on disk serialization and default block file size. |
| 37 | + assert_equal(pruneheight, 249) |
| 38 | + |
| 39 | + self.log.info("check if we can access the tips blockfilter when we have pruned some blocks") |
| 40 | + assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getbestblockhash())['filter']), 0) |
| 41 | + |
| 42 | + self.log.info("check if we can access the blockfilter of a pruned block") |
| 43 | + assert_greater_than(len(self.nodes[0].getblockfilter(self.nodes[0].getblockhash(2))['filter']), 0) |
| 44 | + |
| 45 | + # mine and sync index up to a height that will later be the pruneheight |
| 46 | + self.generate(self.nodes[0], 298) |
| 47 | + |
| 48 | + self.sync_index(height=998) |
| 49 | + |
| 50 | + self.log.info("start node without blockfilterindex") |
| 51 | + self.restart_node(0, extra_args=["-fastprune", "-prune=1", "-mintxfee=0.1"]) |
| 52 | + |
| 53 | + self.log.info("make sure accessing the blockfilters throws an error") |
| 54 | + assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[0].getblockfilter, self.nodes[0].getblockhash(2)) |
| 55 | + |
| 56 | + # Generate 502 blocks |
| 57 | + self.generate(self.nodes[0], 287) |
| 58 | + |
| 59 | + self.log.info("prune exactly up to the blockfilterindexes best block while blockfilters are disabled") |
| 60 | + pruneheight_2 = self.nodes[0].pruneblockchain(1000) |
| 61 | + assert_equal(pruneheight_2, 751) |
| 62 | + |
| 63 | + self.restart_node(0, extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1", "-mintxfee=0.1"]) |
| 64 | + self.log.info("make sure that we can continue with the partially synced index after having pruned up to the index height") |
| 65 | + self.sync_index(height=1285) |
| 66 | + |
| 67 | + self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled") |
| 68 | + self.restart_node(0, extra_args=["-fastprune", "-prune=1", "-mintxfee=0.1"]) |
| 69 | + self.generate(self.nodes[0], 1000) |
| 70 | + pruneheight_3 = self.nodes[0].pruneblockchain(2000) |
| 71 | + assert_greater_than(pruneheight_3, pruneheight_2) |
| 72 | + self.stop_node(0) |
| 73 | + |
| 74 | + self.log.info("make sure we get an init error when starting the node again with block filters") |
| 75 | + self.nodes[0].assert_start_raises_init_error( |
| 76 | + extra_args=["-fastprune", "-prune=1", "-blockfilterindex=1", "-mintxfee=0.1"], |
| 77 | + expected_msg="Error: 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\\)", |
| 78 | + match=test_node.ErrorMatch.PARTIAL_REGEX, |
| 79 | + ) |
| 80 | + |
| 81 | + self.log.info("make sure the node starts again with the -reindex arg") |
| 82 | + self.start_node(0, extra_args=["-fastprune", "-prune=1", "-blockfilterindex", "-reindex", "-mintxfee=0.1"]) |
| 83 | + |
| 84 | + |
| 85 | +if __name__ == '__main__': |
| 86 | + FeatureBlockfilterindexPruneTest().main() |
0 commit comments