Merge #21230: test: Fix NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection

fa24247d0f test: Fix NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection (MarcoFalke)
fab6995629 test: Make test actually test something (MarcoFalke)
fae8f35df8 test: pep8 touched test (MarcoFalke)

Pull request description:

  Fix several bugs. Also, fix #21227

ACKs for top commit:
  jonasschnelli:
    utACK fa24247d0f - thanks for fixing.
  ryanofsky:
    Code review ACK fa24247d0f with caveat above that I don't really understand the problem or fix. But the cleanups look good and the fix does seem perfectly safe. More description would be welcome!

Tree-SHA512: 67f6ec92f6493aa822ae3fa8a7426a5acdc684044b8bafc0c65b652f63ccce969d0a6f1d1f099d6a91d05f478724869345b70335f2cfcfd00df46aef05cc4f9e
This commit is contained in:
Jonas Schnelli
2021-02-19 08:37:57 +01:00

View File

@@ -9,6 +9,7 @@ from test_framework.util import (
assert_greater_than, assert_greater_than,
) )
class FeatureBlockfilterindexPruneTest(BitcoinTestFramework): class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.num_nodes = 2 self.num_nodes = 2
@@ -17,33 +18,37 @@ class FeatureBlockfilterindexPruneTest(BitcoinTestFramework):
def run_test(self): def run_test(self):
# test basic pruning compatibility & filter access of pruned blocks # test basic pruning compatibility & filter access of pruned blocks
self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned") self.log.info("check if we can access a blockfilter when pruning is enabled but no blocks are actually pruned")
assert(len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0) assert len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0
self.nodes[1].generate(500) # Mine two batches of blocks to avoid hitting NODE_NETWORK_LIMITED_MIN_BLOCKS disconnection
self.nodes[1].generate(250)
self.sync_all()
self.nodes[1].generate(250)
self.sync_all() self.sync_all()
self.log.info("prune some blocks") self.log.info("prune some blocks")
pruneheight = self.nodes[1].pruneblockchain(400) pruneheight = self.nodes[1].pruneblockchain(400)
assert(pruneheight != 0) assert pruneheight != 0
self.log.info("check if we can access the tips blockfilter when we have pruned some blocks") self.log.info("check if we can access the tips blockfilter when we have pruned some blocks")
assert(len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0) assert len(self.nodes[1].getblockfilter(self.nodes[1].getbestblockhash())['filter']) > 0
self.log.info("check if we can access the blockfilter of a pruned block") self.log.info("check if we can access the blockfilter of a pruned block")
assert(len(self.nodes[1].getblockfilter(self.nodes[1].getblockhash(2))['filter']) > 0) assert len(self.nodes[1].getblockfilter(self.nodes[1].getblockhash(2))['filter']) > 0
self.log.info("start node without blockfilterindex") self.log.info("start node without blockfilterindex")
self.stop_node(1) self.stop_node(1)
self.start_node(1, extra_args=self.extra_args[0]) self.start_node(1, extra_args=self.extra_args[0])
self.log.info("make sure accessing the blockfilters throws an error") self.log.info("make sure accessing the blockfilters throws an error")
assert_raises_rpc_error(-1,"Index is not enabled for filtertype basic", self.nodes[1].getblockfilter, self.nodes[1].getblockhash(2)) assert_raises_rpc_error(-1, "Index is not enabled for filtertype basic", self.nodes[1].getblockfilter, self.nodes[1].getblockhash(2))
self.nodes[1].generate(1000) self.nodes[1].generate(1000)
self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled") self.log.info("prune below the blockfilterindexes best block while blockfilters are disabled")
pruneheight_new = self.nodes[1].pruneblockchain(1000) pruneheight_new = self.nodes[1].pruneblockchain(1000)
assert_greater_than(pruneheight_new, pruneheight) assert_greater_than(pruneheight_new, pruneheight)
self.stop_node(1) self.stop_node(1)
self.log.info("make sure we get an init error when starting the node again with block filters") self.log.info("make sure we get an init error when starting the node again with block filters")
self.nodes[1].assert_start_raises_init_error(extra_args=self.extra_args[1]) with self.nodes[1].assert_debug_log(["basic block filter index best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)"]):
self.nodes[1].assert_debug_log(["basic block filter index best block of the index goes beyond pruned data. Please disable the index or reindex (which will download the whole blockchain again)"]) self.nodes[1].assert_start_raises_init_error(extra_args=self.extra_args[1])
self.log.info("make sure the node starts again with the -reindex arg") self.log.info("make sure the node starts again with the -reindex arg")
reindex_args = self.extra_args[1] reindex_args = self.extra_args[1]
reindex_args.append("-reindex") reindex_args.append("-reindex")
self.start_node(1, extra_args=reindex_args) self.start_node(1, extra_args=reindex_args)
if __name__ == '__main__': if __name__ == '__main__':
FeatureBlockfilterindexPruneTest().main() FeatureBlockfilterindexPruneTest().main()