71
71
Expect: no response.
72
72
73
73
Part 5: Test handling of headers that don't connect.
74
- a. Repeat 10 times:
74
+ a. Repeat 100 times:
75
75
1. Announce a header that doesn't connect.
76
76
Expect: getheaders message
77
77
2. Send headers chain.
78
78
Expect: getdata for the missing blocks, tip update.
79
- b. Then send 9 more headers that don't connect.
79
+ b. Then send 99 more headers that don't connect.
80
80
Expect: getheaders message each time.
81
- c. Announce a header that does connect.
82
- Expect: no response.
83
- d. Announce 49 headers that don't connect.
84
- Expect: getheaders message each time.
85
- e. Announce one more that doesn't connect.
86
- Expect: disconnect.
87
81
"""
88
82
from test_framework .blocktools import create_block , create_coinbase
89
83
from test_framework .messages import CInv
@@ -526,7 +520,8 @@ def test_nonnull_locators(self, test_node, inv_node):
526
520
# First we test that receipt of an unconnecting header doesn't prevent
527
521
# chain sync.
528
522
expected_hash = tip
529
- for i in range (10 ):
523
+ NUM_HEADERS = 100
524
+ for i in range (NUM_HEADERS ):
530
525
self .log .debug ("Part 5.{}: starting..." .format (i ))
531
526
test_node .last_message .pop ("getdata" , None )
532
527
blocks = []
@@ -550,41 +545,24 @@ def test_nonnull_locators(self, test_node, inv_node):
550
545
blocks = []
551
546
# Now we test that if we repeatedly don't send connecting headers, we
552
547
# don't go into an infinite loop trying to get them to connect.
553
- MAX_NUM_UNCONNECTING_HEADERS_MSGS = 10
554
- for _ in range (MAX_NUM_UNCONNECTING_HEADERS_MSGS + 1 ):
548
+ for _ in range (NUM_HEADERS + 1 ):
555
549
blocks .append (create_block (tip , create_coinbase (height ), block_time ))
556
550
blocks [- 1 ].solve ()
557
551
tip = blocks [- 1 ].sha256
558
552
block_time += 1
559
553
height += 1
560
554
561
- for i in range (1 , MAX_NUM_UNCONNECTING_HEADERS_MSGS ):
562
- # Send a header that doesn't connect, check that we get a getheaders.
555
+ for i in range (1 , NUM_HEADERS ):
556
+ with p2p_lock :
557
+ test_node .last_message .pop ("getheaders" , None )
558
+ # Send an empty header as a failed response to the received getheaders
559
+ # (from the previous iteration). Otherwise, the new headers will be
560
+ # treated as a response instead of as an announcement.
561
+ test_node .send_header_for_blocks ([])
562
+ # Send the actual unconnecting header, which should trigger a new getheaders.
563
563
test_node .send_header_for_blocks ([blocks [i ]])
564
564
test_node .wait_for_getheaders (block_hash = expected_hash )
565
565
566
- # Next header will connect, should re-set our count:
567
- test_node .send_header_for_blocks ([blocks [0 ]])
568
- expected_hash = blocks [0 ].sha256
569
-
570
- # Remove the first two entries (blocks[1] would connect):
571
- blocks = blocks [2 :]
572
-
573
- # Now try to see how many unconnecting headers we can send
574
- # before we get disconnected. Should be 5*MAX_NUM_UNCONNECTING_HEADERS_MSGS
575
- for i in range (5 * MAX_NUM_UNCONNECTING_HEADERS_MSGS - 1 ):
576
- # Send a header that doesn't connect, check that we get a getheaders.
577
- test_node .send_header_for_blocks ([blocks [i % len (blocks )]])
578
- test_node .wait_for_getheaders (block_hash = expected_hash )
579
-
580
- # Eventually this stops working.
581
- test_node .send_header_for_blocks ([blocks [- 1 ]])
582
-
583
- # Should get disconnected
584
- test_node .wait_for_disconnect ()
585
-
586
- self .log .info ("Part 5: success!" )
587
-
588
566
# Finally, check that the inv node never received a getdata request,
589
567
# throughout the test
590
568
assert "getdata" not in inv_node .last_message
0 commit comments