Skip to content

Commit 0493c92

Browse files
committed
Fix functional/p2p_sendheaders.py file
1 parent b2cc9be commit 0493c92

File tree

1 file changed

+13
-35
lines changed

1 file changed

+13
-35
lines changed

test/functional/p2p_sendheaders.py

+13-35
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,13 @@
7171
Expect: no response.
7272
7373
Part 5: Test handling of headers that don't connect.
74-
a. Repeat 10 times:
74+
a. Repeat 100 times:
7575
1. Announce a header that doesn't connect.
7676
Expect: getheaders message
7777
2. Send headers chain.
7878
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.
8080
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.
8781
"""
8882
from test_framework.blocktools import create_block, create_coinbase
8983
from test_framework.messages import CInv
@@ -526,7 +520,8 @@ def test_nonnull_locators(self, test_node, inv_node):
526520
# First we test that receipt of an unconnecting header doesn't prevent
527521
# chain sync.
528522
expected_hash = tip
529-
for i in range(10):
523+
NUM_HEADERS = 100
524+
for i in range(NUM_HEADERS):
530525
self.log.debug("Part 5.{}: starting...".format(i))
531526
test_node.last_message.pop("getdata", None)
532527
blocks = []
@@ -550,41 +545,24 @@ def test_nonnull_locators(self, test_node, inv_node):
550545
blocks = []
551546
# Now we test that if we repeatedly don't send connecting headers, we
552547
# 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):
555549
blocks.append(create_block(tip, create_coinbase(height), block_time))
556550
blocks[-1].solve()
557551
tip = blocks[-1].sha256
558552
block_time += 1
559553
height += 1
560554

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.
563563
test_node.send_header_for_blocks([blocks[i]])
564564
test_node.wait_for_getheaders(block_hash=expected_hash)
565565

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-
588566
# Finally, check that the inv node never received a getdata request,
589567
# throughout the test
590568
assert "getdata" not in inv_node.last_message

0 commit comments

Comments
 (0)