Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_pruning.py
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | def reorg_test(self): | ||||
# So invalidate that fork as well, until we're on the same chain as | # So invalidate that fork as well, until we're on the same chain as | ||||
# node 0/2 (but at an ancestor 288 blocks ago) | # node 0/2 (but at an ancestor 288 blocks ago) | ||||
mainchainhash = self.nodes[0].getblockhash(invalidheight - 1) | mainchainhash = self.nodes[0].getblockhash(invalidheight - 1) | ||||
curhash = self.nodes[1].getblockhash(invalidheight - 1) | curhash = self.nodes[1].getblockhash(invalidheight - 1) | ||||
while curhash != mainchainhash: | while curhash != mainchainhash: | ||||
self.nodes[1].invalidateblock(curhash) | self.nodes[1].invalidateblock(curhash) | ||||
curhash = self.nodes[1].getblockhash(invalidheight - 1) | curhash = self.nodes[1].getblockhash(invalidheight - 1) | ||||
assert(self.nodes[1].getblockcount() == invalidheight - 1) | assert self.nodes[1].getblockcount() == invalidheight - 1 | ||||
self.log.info("New best height: {}".format( | self.log.info("New best height: {}".format( | ||||
self.nodes[1].getblockcount())) | self.nodes[1].getblockcount())) | ||||
# Reboot node1 to clear those giant tx's from mempool | # Reboot node1 to clear those giant tx's from mempool | ||||
self.stop_node(1) | self.stop_node(1) | ||||
self.start_node(1, extra_args=[ | self.start_node(1, extra_args=[ | ||||
"-maxreceivebuffer=20000", "-blockmaxsize=5000", "-checkblocks=5", | "-maxreceivebuffer=20000", "-blockmaxsize=5000", "-checkblocks=5", | ||||
"-noparkdeepreorg", "-maxreorgdepth=-1"]) | "-noparkdeepreorg", "-maxreorgdepth=-1"]) | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | def reorg_back(self): | ||||
# 288 blocks of the fork point so it will preserve its ability to | # 288 blocks of the fork point so it will preserve its ability to | ||||
# reorg. | # reorg. | ||||
if self.nodes[2].getblockcount() < self.mainchainheight: | if self.nodes[2].getblockcount() < self.mainchainheight: | ||||
blocks_to_mine = first_reorg_height + 1 - self.mainchainheight | blocks_to_mine = first_reorg_height + 1 - self.mainchainheight | ||||
self.log.info( | self.log.info( | ||||
"Rewind node 0 to prev main chain to mine longer chain to trigger redownload. Blocks needed: {}".format( | "Rewind node 0 to prev main chain to mine longer chain to trigger redownload. Blocks needed: {}".format( | ||||
blocks_to_mine)) | blocks_to_mine)) | ||||
self.nodes[0].invalidateblock(curchainhash) | self.nodes[0].invalidateblock(curchainhash) | ||||
assert(self.nodes[0].getblockcount() == self.mainchainheight) | assert self.nodes[0].getblockcount() == self.mainchainheight | ||||
assert(self.nodes[0].getbestblockhash() == self.mainchainhash2) | assert self.nodes[0].getbestblockhash() == self.mainchainhash2 | ||||
goalbesthash = self.nodes[0].generate(blocks_to_mine)[-1] | goalbesthash = self.nodes[0].generate(blocks_to_mine)[-1] | ||||
goalbestheight = first_reorg_height + 1 | goalbestheight = first_reorg_height + 1 | ||||
self.log.info( | self.log.info( | ||||
"Verify node 2 reorged back to the main chain, some blocks of which it had to redownload") | "Verify node 2 reorged back to the main chain, some blocks of which it had to redownload") | ||||
# Wait for Node 2 to reorg to proper height | # Wait for Node 2 to reorg to proper height | ||||
wait_until(lambda: self.nodes[2].getblockcount( | wait_until(lambda: self.nodes[2].getblockcount( | ||||
) >= goalbestheight, timeout=900) | ) >= goalbestheight, timeout=900) | ||||
assert(self.nodes[2].getbestblockhash() == goalbesthash) | assert self.nodes[2].getbestblockhash() == goalbesthash | ||||
# Verify we can now have the data for a block previously pruned | # Verify we can now have the data for a block previously pruned | ||||
assert(self.nodes[2].getblock( | assert self.nodes[2].getblock( | ||||
self.forkhash)["height"] == self.forkheight) | self.forkhash)["height"] == self.forkheight | ||||
def manual_test(self, node_number, use_timestamp): | def manual_test(self, node_number, use_timestamp): | ||||
# at this point, node has 995 blocks and has not yet run in prune mode | # at this point, node has 995 blocks and has not yet run in prune mode | ||||
self.start_node(node_number) | self.start_node(node_number) | ||||
node = self.nodes[node_number] | node = self.nodes[node_number] | ||||
assert_equal(node.getblockcount(), 995) | assert_equal(node.getblockcount(), 995) | ||||
assert_raises_rpc_error(-1, "not in prune mode", | assert_raises_rpc_error(-1, "not in prune mode", | ||||
node.pruneblockchain, 500) | node.pruneblockchain, 500) | ||||
▲ Show 20 Lines • Show All 240 Lines • Show Last 20 Lines |