@@ -122,10 +122,21 @@ def run_test(self):
122
122
pruned_node = self .nodes [2 ]
123
123
self .generate (self .nodes [0 ], 400 , sync_fun = self .no_op )
124
124
self .sync_blocks ([self .nodes [0 ], pruned_node ])
125
- pruneheight = pruned_node .pruneblockchain (300 )
126
- assert_equal (pruneheight , 248 )
125
+
126
+ # The goal now will be to mimic the automatic pruning process and verify what happens when we fetch an historic
127
+ # block at any point of time.
128
+ #
129
+ # Starting with three blocks files. The pruning process will prune them one by one. And, at the second pruning
130
+ # event, the test will fetch the past block. Which will be stored at the latest block file. Which can only be
131
+ # pruned when the latest block file is full (in this case, the third one), and a new one is created.
132
+
133
+ # First prune event, prune first block file
134
+ highest_pruned_block_num = pruned_node .getblockfileinfo (0 )["highest_block" ]
135
+ pruneheight = pruned_node .pruneblockchain (highest_pruned_block_num + 1 )
136
+ assert_equal (pruneheight , highest_pruned_block_num )
127
137
# Ensure the block is actually pruned
128
- pruned_block = self .nodes [0 ].getblockhash (2 )
138
+ fetch_block_num = 2
139
+ pruned_block = self .nodes [0 ].getblockhash (fetch_block_num )
129
140
assert_raises_rpc_error (- 1 , "Block not available (pruned data)" , pruned_node .getblock , pruned_block )
130
141
131
142
self .log .info ("Fetch pruned block" )
@@ -136,18 +147,29 @@ def run_test(self):
136
147
self .wait_until (lambda : self .check_for_block (node = 2 , hash = pruned_block ), timeout = 1 )
137
148
assert_equal (result , {})
138
149
150
+ # Validate that the re-fetched block was stored at the last, current, block file
151
+ assert_equal (fetch_block_num , pruned_node .getblockfileinfo (2 )["lowest_block" ])
152
+
139
153
self .log .info ("Fetched block persists after next pruning event" )
140
154
self .generate (self .nodes [0 ], 250 , sync_fun = self .no_op )
141
155
self .sync_blocks ([self .nodes [0 ], pruned_node ])
142
- pruneheight += 251
143
- assert_equal (pruned_node .pruneblockchain (700 ), pruneheight )
156
+
157
+ # Second prune event, prune second block file
158
+ highest_pruned_block_num = pruned_node .getblockfileinfo (1 )["highest_block" ]
159
+ pruneheight = pruned_node .pruneblockchain (highest_pruned_block_num + 1 )
160
+ assert_equal (pruneheight , highest_pruned_block_num )
161
+ # As the re-fetched block is in the third file, and we just pruned the second one, 'getblock' must work.
144
162
assert_equal (pruned_node .getblock (pruned_block )["hash" ], "36c56c5b5ebbaf90d76b0d1a074dcb32d42abab75b7ec6fa0ffd9b4fbce8f0f7" )
145
163
146
- self .log .info ("Fetched block can be pruned again when prune height exceeds the height of the tip at the time when the block was fetched " )
164
+ self .log .info ("Re-fetched block can be pruned again when a new block file is created " )
147
165
self .generate (self .nodes [0 ], 250 , sync_fun = self .no_op )
148
166
self .sync_blocks ([self .nodes [0 ], pruned_node ])
149
- pruneheight += 250
150
- assert_equal (pruned_node .pruneblockchain (1000 ), pruneheight )
167
+
168
+ # Third prune event, prune third block file
169
+ highest_pruned_block_num = pruned_node .getblockfileinfo (2 )["highest_block" ]
170
+ pruneheight = pruned_node .pruneblockchain (highest_pruned_block_num + 1 )
171
+ assert_equal (pruneheight , highest_pruned_block_num )
172
+ # and check that the re-fetched block file is now pruned
151
173
assert_raises_rpc_error (- 1 , "Block not available (pruned data)" , pruned_node .getblock , pruned_block )
152
174
153
175
0 commit comments