MCPcopy Create free account
hub / github.com/ElementsProject/elements / reorg_test

Method reorg_test

test/functional/feature_pruning.py:183–228  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

181 self.log.info(f"Usage can be over target because of high stale rate: {calc_usage(self.prunedir)}")
182
183 def reorg_test(self):
184 # Node 1 will mine a 300 block chain starting 287 blocks back from Node 0 and Node 2's tip
185 # This will cause Node 2 to do a reorg requiring 288 blocks of undo data to the reorg_test chain
186
187 height = self.nodes[1].getblockcount()
188 self.log.info(f"Current block height: {height}")
189
190 self.forkheight = height - 287
191 self.forkhash = self.nodes[1].getblockhash(self.forkheight)
192 self.log.info(f"Invalidating block {self.forkhash} at height {self.forkheight}")
193 self.nodes[1].invalidateblock(self.forkhash)
194
195 # We've now switched to our previously mined-24 block fork on node 1, but that's not what we want
196 # So invalidate that fork as well, until we're on the same chain as node 0/2 (but at an ancestor 288 blocks ago)
197 mainchainhash = self.nodes[0].getblockhash(self.forkheight - 1)
198 curhash = self.nodes[1].getblockhash(self.forkheight - 1)
199 while curhash != mainchainhash:
200 self.nodes[1].invalidateblock(curhash)
201 curhash = self.nodes[1].getblockhash(self.forkheight - 1)
202
203 assert self.nodes[1].getblockcount() == self.forkheight - 1
204 self.log.info(f"New best height: {self.nodes[1].getblockcount()}")
205
206 # Disconnect node1 and generate the new chain
207 self.disconnect_nodes(0, 1)
208 self.disconnect_nodes(1, 2)
209
210 self.log.info("Generating new longer chain of 300 more blocks")
211 self.generate(self.nodes[1], 300, sync_fun=self.no_op)
212
213 self.log.info("Reconnect nodes")
214 self.connect_nodes(0, 1)
215 self.connect_nodes(1, 2)
216 self.sync_blocks(self.nodes[0:3], timeout=120)
217
218 self.log.info(f"Verify height on node 2: {self.nodes[2].getblockcount()}")
219 self.log.info(f"Usage possibly still high because of stale blocks in block files: {calc_usage(self.prunedir)}")
220
221 self.log.info("Mine 220 more large blocks so we have requisite history")
222
223 mine_large_blocks(self.nodes[0], 220)
224 self.sync_blocks(self.nodes[0:3], timeout=120)
225
226 usage = calc_usage(self.prunedir)
227 self.log.info(f"Usage should be below target: {usage}")
228 assert_greater_than(550, usage)
229
230 def reorg_back(self):
231 # Verify that a block on the old main chain fork has been pruned away

Callers 1

run_testMethod · 0.95

Calls 8

assert_greater_thanFunction · 0.90
mine_large_blocksFunction · 0.85
infoMethod · 0.80
disconnect_nodesMethod · 0.80
connect_nodesMethod · 0.80
calc_usageFunction · 0.70
generateMethod · 0.45
sync_blocksMethod · 0.45

Tested by

no test coverage detected