@@ -16,36 +16,48 @@ def set_test_params(self):
16
16
self .num_nodes = 2
17
17
self .extra_args = [["-fastprune" , "-prune=1" ], ["-fastprune" , "-prune=1" , "-blockfilterindex=1" ]]
18
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 [1 ].getindexinfo () == expected )
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 [1 ].getblockfilter (self .nodes [1 ].getbestblockhash ())['filter' ]), 0 )
23
27
# Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection
24
28
self .nodes [1 ].generate (250 )
25
29
self .sync_all ()
26
30
self .nodes [1 ].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
35
pruneheight = self .nodes [1 ].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 [1 ].getblockfilter (self .nodes [1 ].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 [1 ].getblockfilter (self .nodes [1 ].getblockhash (2 ))['filter' ]), 0 )
43
+
36
44
self .log .info ("start node without blockfilterindex" )
37
45
self .stop_node (1 )
38
46
self .start_node (1 , extra_args = self .extra_args [0 ])
47
+
39
48
self .log .info ("make sure accessing the blockfilters throws an error" )
40
49
assert_raises_rpc_error (- 1 , "Index is not enabled for filtertype basic" , self .nodes [1 ].getblockfilter , self .nodes [1 ].getblockhash (2 ))
41
50
self .nodes [1 ].generate (1000 )
51
+
42
52
self .log .info ("prune below the blockfilterindexes best block while blockfilters are disabled" )
43
53
pruneheight_new = self .nodes [1 ].pruneblockchain (1000 )
44
54
assert_greater_than (pruneheight_new , pruneheight )
45
55
self .stop_node (1 )
56
+
46
57
self .log .info ("make sure we get an init error when starting the node again with block filters" )
47
58
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
59
self .nodes [1 ].assert_start_raises_init_error (extra_args = self .extra_args [1 ])
60
+
49
61
self .log .info ("make sure the node starts again with the -reindex arg" )
50
62
reindex_args = self .extra_args [1 ]
51
63
reindex_args .append ("-reindex" )
0 commit comments