@@ -30,18 +30,21 @@ def set_test_params(self):
30
30
self .setup_clean_chain = True
31
31
self .num_nodes = 3
32
32
# 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 " ]]
34
34
35
35
def setup_network (self ):
36
36
self .setup_nodes ()
37
- self .connect_nodes (0 , 1 )
38
- self .connect_nodes (0 , 2 )
37
+ self .reconnect_all ()
39
38
self .sync_all ()
40
39
41
40
def disconnect_all (self ):
42
41
self .disconnect_nodes (0 , 1 )
43
42
self .disconnect_nodes (0 , 2 )
44
43
44
+ def reconnect_all (self ):
45
+ self .connect_nodes (0 , 1 )
46
+ self .connect_nodes (0 , 2 )
47
+
45
48
def test_chains_sync_when_long_enough (self ):
46
49
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" )
47
50
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):
107
110
# getpeerinfo should show a sync in progress
108
111
assert_equal (node .getpeerinfo ()[0 ]['presynced_headers' ], 2000 )
109
112
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
+
110
134
def run_test (self ):
111
135
self .test_chains_sync_when_long_enough ()
112
136
137
+ self .test_large_reorgs_can_succeed ()
138
+
113
139
self .test_peerinfo_includes_headers_presync_height ()
114
140
115
141
142
+
116
143
if __name__ == '__main__' :
117
144
RejectLowDifficultyHeadersTest ().main ()
0 commit comments