def reorg_test(self):
    height = self.nodes[1].getblockcount()
    self.log.info(f'Current block height: {height}')
    self.forkheight = (height - 287)
    self.forkhash = self.nodes[1].getblockhash(self.forkheight)
    self.log.info(f'Invalidating block {self.forkhash} at height {self.forkheight}')
    self.nodes[1].invalidateblock(self.forkhash)
    mainchainhash = self.nodes[0].getblockhash((self.forkheight - 1))
    curhash = self.nodes[1].getblockhash((self.forkheight - 1))
    while (curhash != mainchainhash):
        self.nodes[1].invalidateblock(curhash)
        curhash = self.nodes[1].getblockhash((self.forkheight - 1))
    assert (self.nodes[1].getblockcount() == (self.forkheight - 1))
    self.log.info(f'New best height: {self.nodes[1].getblockcount()}')
    self.disconnect_nodes(0, 1)
    self.disconnect_nodes(1, 2)
    self.log.info('Generating new longer chain of 300 more blocks')
    self.generate(self.nodes[1], 300)
    self.log.info('Reconnect nodes')
    self.connect_nodes(0, 1)
    self.connect_nodes(1, 2)
    self.sync_blocks(self.nodes[0:3], timeout=120)
    self.log.info(f'Verify height on node 2: {self.nodes[2].getblockcount()}')
    self.log.info(f'Usage possibly still high because of stale blocks in block files: {calc_usage(self.prunedir)}')
    self.log.info('Mine 220 more large blocks so we have requisite history')
    mine_large_blocks(self.nodes[0], 220)
    self.sync_blocks(self.nodes[0:3], timeout=120)
    usage = calc_usage(self.prunedir)
    self.log.info(f'Usage should be below target: {usage}')
    assert_greater_than(550, usage)
def reorg_test(self):
    height = self.nodes[1].getblockcount()
    self.log.info(f'Current block height: {height}')
    self.forkheight = (height - 287)
    self.forkhash = self.nodes[1].getblockhash(self.forkheight)
    self.log.info(f'Invalidating block {self.forkhash} at height {self.forkheight}')
    self.nodes[1].invalidateblock(self.forkhash)
    mainchainhash = self.nodes[0].getblockhash((self.forkheight - 1))
    curhash = self.nodes[1].getblockhash((self.forkheight - 1))
    while (curhash != mainchainhash):
        self.nodes[1].invalidateblock(curhash)
        curhash = self.nodes[1].getblockhash((self.forkheight - 1))
    assert (self.nodes[1].getblockcount() == (self.forkheight - 1))
    self.log.info(f'New best height: {self.nodes[1].getblockcount()}')
    self.disconnect_nodes(0, 1)
    self.disconnect_nodes(1, 2)
    self.log.info('Generating new longer chain of 300 more blocks')
    self.generate(self.nodes[1], 300)
    self.log.info('Reconnect nodes')
    self.connect_nodes(0, 1)
    self.connect_nodes(1, 2)
    self.sync_blocks(self.nodes[0:3], timeout=120)
    self.log.info(f'Verify height on node 2: {self.nodes[2].getblockcount()}')
    self.log.info(f'Usage possibly still high because of stale blocks in block files: {calc_usage(self.prunedir)}')
    self.log.info('Mine 220 more large blocks so we have requisite history')
    mine_large_blocks(self.nodes[0], 220)
    self.sync_blocks(self.nodes[0:3], timeout=120)
    usage = calc_usage(self.prunedir)
    self.log.info(f'Usage should be below target: {usage}')
    assert_greater_than(550, usage)