Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_pruning.py
Show First 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | def reorg_test(self): | ||||
self.log.info("Current block height: {}".format(height)) | self.log.info("Current block height: {}".format(height)) | ||||
invalidheight = height - 287 | invalidheight = height - 287 | ||||
badhash = self.nodes[1].getblockhash(invalidheight) | badhash = self.nodes[1].getblockhash(invalidheight) | ||||
self.log.info("Invalidating block {} at height {}".format( | self.log.info("Invalidating block {} at height {}".format( | ||||
badhash, invalidheight)) | badhash, invalidheight)) | ||||
self.nodes[1].invalidateblock(badhash) | self.nodes[1].invalidateblock(badhash) | ||||
# We've now switched to our previously mined-24 block fork on node 1, but thats not what we want. | # We've now switched to our previously mined-24 block fork on node 1, but that's not what we want. | ||||
# 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) | ||||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | def reorg_back(self): | ||||
first_reorg_height = self.nodes[2].getblockcount() | first_reorg_height = self.nodes[2].getblockcount() | ||||
curchainhash = self.nodes[2].getblockhash(self.mainchainheight) | curchainhash = self.nodes[2].getblockhash(self.mainchainheight) | ||||
self.nodes[2].invalidateblock(curchainhash) | self.nodes[2].invalidateblock(curchainhash) | ||||
goalbestheight = self.mainchainheight | goalbestheight = self.mainchainheight | ||||
goalbesthash = self.mainchainhash2 | goalbesthash = self.mainchainhash2 | ||||
# As of 0.10 the current block download logic is not able to reorg to | # As of 0.10 the current block download logic is not able to reorg to | ||||
# the original chain created in create_chain_with_stale_blocks because | # the original chain created in create_chain_with_stale_blocks because | ||||
# it doesn't know of any peer thats on that chain from which to | # it doesn't know of any peer that's on that chain from which to | ||||
# redownload its missing blocks. Invalidate the reorg_test chain in | # redownload its missing blocks. Invalidate the reorg_test chain in | ||||
# node 0 as well, it can successfully switch to the original chain | # node 0 as well, it can successfully switch to the original chain | ||||
# because it has all the block data. However it must mine enough blocks | # because it has all the block data. However it must mine enough blocks | ||||
# to have a more work chain than the reorg_test chain in order to | # to have a more work chain than the reorg_test chain in order to | ||||
# trigger node 2's block download logic. At this point node 2 is within | # trigger node 2's block download logic. At this point node 2 is within | ||||
# 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: | ||||
▲ Show 20 Lines • Show All 269 Lines • Show Last 20 Lines |