@@ -220,18 +220,20 @@ def setup_network(self):
220
220
221
221
# mine count blocks and return the new tip
222
222
def mine_blocks (self , count ):
223
+ # Clear out last block announcement from each p2p listener
224
+ [ x .clear_last_announcement () for x in self .p2p_connections ]
223
225
self .nodes [0 ].generate (count )
224
226
return int (self .nodes [0 ].getbestblockhash (), 16 )
225
227
226
228
# mine a reorg that invalidates length blocks (replacing them with
227
229
# length+1 blocks).
228
- # peers is the p2p nodes we're using; we clear their state after the
230
+ # Note: we clear the state of our p2p connections after the
229
231
# to-be-reorged-out blocks are mined, so that we don't break later tests.
230
232
# return the list of block hashes newly mined
231
- def mine_reorg (self , length , peers ):
233
+ def mine_reorg (self , length ):
232
234
self .nodes [0 ].generate (length ) # make sure all invalidated blocks are node0's
233
235
sync_blocks (self .nodes , wait = 0.1 )
234
- [x .clear_last_announcement () for x in peers ]
236
+ [x .clear_last_announcement () for x in self . p2p_connections ]
235
237
236
238
tip_height = self .nodes [1 ].getblockcount ()
237
239
hash_to_invalidate = self .nodes [1 ].getblockhash (tip_height - (length - 1 ))
@@ -245,6 +247,8 @@ def run_test(self):
245
247
inv_node = InvNode ()
246
248
test_node = TestNode ()
247
249
250
+ self .p2p_connections = [inv_node , test_node ]
251
+
248
252
connections = []
249
253
connections .append (NodeConn ('127.0.0.1' , p2p_port (0 ), self .nodes [0 ], inv_node ))
250
254
# Set nServices to 0 for test_node, so no block download will occur outside of
@@ -303,7 +307,6 @@ def run_test(self):
303
307
prev_tip = int (self .nodes [0 ].getbestblockhash (), 16 )
304
308
test_node .get_headers (locator = [prev_tip ], hashstop = 0L )
305
309
test_node .sync_with_ping ()
306
- test_node .clear_last_announcement () # Clear out empty headers response
307
310
308
311
# Now that we've synced headers, headers announcements should work
309
312
tip = self .mine_blocks (1 )
@@ -352,8 +355,6 @@ def run_test(self):
352
355
# broadcast it)
353
356
assert_equal (inv_node .last_inv , None )
354
357
assert_equal (inv_node .last_headers , None )
355
- inv_node .clear_last_announcement ()
356
- test_node .clear_last_announcement ()
357
358
tip = self .mine_blocks (1 )
358
359
assert_equal (inv_node .check_last_announcement (inv = [tip ]), True )
359
360
assert_equal (test_node .check_last_announcement (headers = [tip ]), True )
@@ -368,15 +369,15 @@ def run_test(self):
368
369
# getheaders or inv from peer.
369
370
for j in xrange (2 ):
370
371
# First try mining a reorg that can propagate with header announcement
371
- new_block_hashes = self .mine_reorg (length = 7 , peers = [ test_node , inv_node ] )
372
+ new_block_hashes = self .mine_reorg (length = 7 )
372
373
tip = new_block_hashes [- 1 ]
373
374
assert_equal (inv_node .check_last_announcement (inv = [tip ]), True )
374
375
assert_equal (test_node .check_last_announcement (headers = new_block_hashes ), True )
375
376
376
377
block_time += 8
377
378
378
379
# Mine a too-large reorg, which should be announced with a single inv
379
- new_block_hashes = self .mine_reorg (length = 8 , peers = [ test_node , inv_node ] )
380
+ new_block_hashes = self .mine_reorg (length = 8 )
380
381
tip = new_block_hashes [- 1 ]
381
382
assert_equal (inv_node .check_last_announcement (inv = [tip ]), True )
382
383
assert_equal (test_node .check_last_announcement (inv = [tip ]), True )
@@ -407,7 +408,6 @@ def run_test(self):
407
408
test_node .get_headers (locator = [fork_point ], hashstop = new_block_hashes [1 ])
408
409
test_node .get_data ([tip ])
409
410
test_node .wait_for_block (tip )
410
- test_node .clear_last_announcement ()
411
411
elif i == 2 :
412
412
test_node .get_data ([tip ])
413
413
test_node .wait_for_block (tip )
0 commit comments