Skip to content

Commit 93eae27

Browse files
committed
Test large reorgs with headerssync logic
1 parent 3555473 commit 93eae27

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

test/functional/p2p_headers_sync_with_minchainwork.py

+30-3
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@ def set_test_params(self):
3030
self.setup_clean_chain = True
3131
self.num_nodes = 3
3232
# Node0 has no required chainwork; node1 requires 15 blocks on top of the genesis block; node2 requires 2047
33-
self.extra_args = [["-minimumchainwork=0x0"], ["-minimumchainwork=0x1f"], ["-minimumchainwork=0x1000"]]
33+
self.extra_args = [["-minimumchainwork=0x0", "-checkblockindex=0"], ["-minimumchainwork=0x1f", "-checkblockindex=0"], ["-minimumchainwork=0x1000", "-checkblockindex=0"]]
3434

3535
def setup_network(self):
3636
self.setup_nodes()
37-
self.connect_nodes(0, 1)
38-
self.connect_nodes(0, 2)
37+
self.reconnect_all()
3938
self.sync_all()
4039

4140
def disconnect_all(self):
4241
self.disconnect_nodes(0, 1)
4342
self.disconnect_nodes(0, 2)
4443

44+
def reconnect_all(self):
45+
self.connect_nodes(0, 1)
46+
self.connect_nodes(0, 2)
47+
4548
def test_chains_sync_when_long_enough(self):
4649
self.log.info("Generate blocks on the node with no required chainwork, and verify nodes 1 and 2 have no new headers in their headers tree")
4750
with self.nodes[1].assert_debug_log(expected_msgs=["[net] Ignoring low-work chain (height=14)"]), self.nodes[2].assert_debug_log(expected_msgs=["[net] Ignoring low-work chain (height=14)"]):
@@ -107,11 +110,35 @@ def test_peerinfo_includes_headers_presync_height(self):
107110
# getpeerinfo should show a sync in progress
108111
assert_equal(node.getpeerinfo()[0]['presynced_headers'], 2000)
109112

113+
def test_large_reorgs_can_succeed(self):
114+
self.log.info("Test that a 2000+ block reorg, starting from a point that is more than 2000 blocks before a locator entry, can succeed")
115+
116+
self.sync_all() # Ensure all nodes are synced.
117+
self.disconnect_all()
118+
119+
# locator(block at height T) will have heights:
120+
# [T, T-1, ..., T-10, T-12, T-16, T-24, T-40, T-72, T-136, T-264,
121+
# T-520, T-1032, T-2056, T-4104, ...]
122+
# So mine a number of blocks > 4104 to ensure that the first window of
123+
# received headers during a sync are fully between locator entries.
124+
BLOCKS_TO_MINE = 4110
125+
126+
self.generate(self.nodes[0], BLOCKS_TO_MINE, sync_fun=self.no_op)
127+
self.generate(self.nodes[1], BLOCKS_TO_MINE+2, sync_fun=self.no_op)
128+
129+
self.reconnect_all()
130+
131+
self.sync_blocks(timeout=300) # Ensure tips eventually agree
132+
133+
110134
def run_test(self):
111135
self.test_chains_sync_when_long_enough()
112136

137+
self.test_large_reorgs_can_succeed()
138+
113139
self.test_peerinfo_includes_headers_presync_height()
114140

115141

142+
116143
if __name__ == '__main__':
117144
RejectLowDifficultyHeadersTest().main()

0 commit comments

Comments
 (0)