The split_network()
and join_network()
functions in bitcoin test framework are problematic:
- They make assumptions about the network topology (4 nodes, either connected linearly A-B-C-D or split A-B // C-D), and force these assumptions on all test cases. The
setup_network()
andsync_all()
functions useis_network_split
, which means that many test cases have to set this variable for no other reason than to make those functions work. Removing the requirement to setis_network_split
means many test cases don’t need to override thesetup_network()
method, which removes some 200 loc.split_network()
andjoin_network()
are only used by 2 test cases - that’s a lot of redundant code for the benefit of two test cases. - They’re horribly inefficient. They both stop all 4 nodes, then restart. That takes ~10 seconds on my pc.
- They may have unexpected side-effects. stop-starting removes ephemeral state on the node, and that behaviour may change between releases (eg mempool persistence).
This PR:
- removes the
is_network_split
variable - makes
setup_network()
andsync_all()
more generic by making fewer assumptions about the test network topology - uses a new
disconnect_nodes()
helper function insplit_network()
andjoin_network()
This requires #10143, which isn’t yet merged
benefits:
- removes ~200 lines of unnecessary test setup code
- getchaintips and listsinceblock now run faster:
before:
0 ./listsinceblock.py && ./getchaintips.py
12017-04-12 15:43:53.949000 TestFramework (INFO): Initializing test directory /tmp/user/1000/test58b95puo/15463
22017-04-12 15:44:05.686000 TestFramework (INFO): lastblockhash=798a876d18cb546c59e76d7d0f62611b588dd6046ba989e5800cc8a981e025db
32017-04-12 15:44:15.959000 TestFramework (INFO): Stopping nodes
42017-04-12 15:44:24.526000 TestFramework (INFO): Cleaning up
52017-04-12 15:44:24.529000 TestFramework (INFO): Tests successful
62017-04-12 15:44:24.590000 TestFramework (INFO): Initializing test directory /tmp/user/1000/testk_xibf92/15632
72017-04-12 15:44:46.263000 TestFramework (INFO): Stopping nodes
82017-04-12 15:44:54.658000 TestFramework (INFO): Cleaning up
92017-04-12 15:44:54.667000 TestFramework (INFO): Tests successful
after:
02017-04-12 15:43:12.662000 TestFramework (INFO): Initializing test directory /tmp/user/1000/testqi2c2skb/15342
12017-04-12 15:43:14.616000 TestFramework (INFO): lastblockhash=7c70eee0979069504d6059c3cd9658fc8c57d8ae30a3872716c1f9a244a53ae1
22017-04-12 15:43:14.834000 TestFramework (INFO): Stopping nodes
32017-04-12 15:43:23.205000 TestFramework (INFO): Cleaning up
42017-04-12 15:43:23.207000 TestFramework (INFO): Tests successful
52017-04-12 15:43:23.270000 TestFramework (INFO): Initializing test directory /tmp/user/1000/testmxve6ryf/15399
62017-04-12 15:43:25.363000 TestFramework (INFO): Stopping nodes
72017-04-12 15:43:33.648000 TestFramework (INFO): Cleaning up
82017-04-12 15:43:33.658000 TestFramework (INFO): Tests successful
excluding the test shutdown time (which will be improved by #10082), the change is from 44s to 4.2s (10x speedup).
- bitcoin test framework is now more generic, and can be extended later to automatically spin up different test network topologies.