@@ -55,7 +55,7 @@ def test_outbound_eviction_unprotected(self):
55
55
self .log .info ("Test that the peer gets evicted" )
56
56
peer .wait_for_disconnect ()
57
57
58
- self .log .info ("Create an outbound connection and send header but never catch up" )
58
+ self .log .info ("Create an outbound connection and send header but the peer never catches up" )
59
59
# Mimic a node that just falls behind for long enough
60
60
# This should also apply for a node doing IBD that does not catch up in time
61
61
# Connect a peer and make it send us headers ending in our tip's parent
@@ -75,15 +75,15 @@ def test_outbound_eviction_unprotected(self):
75
75
self .log .info ("Create an outbound connection and keep lagging behind, but not too much" )
76
76
# Test that if the peer never catches up with our current tip, but it does with the
77
77
# expected work that we set when setting the timer (that is, our tip at the time)
78
- # we do not disconnect the peer
78
+ # the node does not disconnect the peer
79
79
peer = node .add_outbound_p2p_connection (P2PInterface (), p2p_idx = 0 , connection_type = "outbound-full-relay" )
80
80
81
81
self .log .info ("Mine a block so our peer starts lagging" )
82
82
prev_prev_hash = tip_header .hashPrevBlock
83
83
best_block_hash = self .generateblock (node , output = "raw(42)" , transactions = [])["hash" ]
84
84
peer .sync_with_ping ()
85
85
86
- self .log .info ("Keep catching up with the old tip and check that we are not evicted " )
86
+ self .log .info ("The peer keeps catching up with the old tip; check that the node does not evict the peer " )
87
87
for i in range (10 ):
88
88
# Generate an additional block so the peers is 2 blocks behind
89
89
prev_header = from_hex (CBlockHeader (), node .getblockheader (best_block_hash , False ))
@@ -96,21 +96,21 @@ def test_outbound_eviction_unprotected(self):
96
96
node .setmocktime (cur_mock_time )
97
97
peer .sync_with_ping ()
98
98
99
- # Wait until we get out last call (by receiving a getheaders)
99
+ # Make the peer wait until it gets node's last call (by receiving a getheaders)
100
100
peer .wait_for_getheaders (block_hash = prev_prev_hash )
101
101
102
- # Send a header with the previous tip (so we go back to 1 block behind)
102
+ # The peer sends a header with the previous tip (so the peer goes back to 1 block behind)
103
103
peer .send_and_ping (msg_headers ([prev_header ]))
104
104
prev_prev_hash = tip_header .hashPrevBlock
105
105
106
106
self .log .info ("Create an outbound connection and take some time to catch up, but do it in time" )
107
107
# Check that if the peer manages to catch up within time, the timeouts are removed (and the peer is not disconnected)
108
- # We are reusing the peer from the previous case which already sent us a valid (but old) block and whose timer is ticking
108
+ # We are reusing the peer from the previous case which already sent the node a valid (but old) block and whose timer is ticking
109
109
110
- # Send an updated headers message matching our tip
110
+ # Make the peer send an updated headers message matching our tip
111
111
peer .send_and_ping (msg_headers ([from_hex (CBlockHeader (), node .getblockheader (best_block_hash , False ))]))
112
112
113
- # Wait for long enough for the timeouts to have triggered and check that we are still connected
113
+ # Wait for long enough for the timeouts to have triggered and check that the peer is still connected
114
114
cur_mock_time += (CHAIN_SYNC_TIMEOUT + 1 )
115
115
node .setmocktime (cur_mock_time )
116
116
peer .sync_with_ping ()
@@ -123,8 +123,10 @@ def test_outbound_eviction_unprotected(self):
123
123
124
124
def test_outbound_eviction_protected (self ):
125
125
# This tests the eviction logic for **protected** outbound peers (that is, PeerManagerImpl::ConsiderEviction)
126
- # Outbound connections are flagged as protected as long as they have sent us a connecting block with at least as
127
- # much work as our current tip and we have enough empty protected_peers slots.
126
+ # Outbound connections are flagged as protected if:
127
+ # - The peer sends a connecting block with at least as much work as our current tip.
128
+ # - There are still available slots in the node's protected_peers list.
129
+ # This test ensures that such protected outbound peers are not disconnected even after chain sync and headers timeouts.
128
130
node = self .nodes [0 ]
129
131
cur_mock_time = node .mocktime
130
132
tip_header = from_hex (CBlockHeader (), node .getblockheader (node .getbestblockhash (), False ))
@@ -145,7 +147,7 @@ def test_outbound_eviction_protected(self):
145
147
peer .wait_for_getheaders (block_hash = tip_header .hashPrevBlock )
146
148
cur_mock_time += (HEADERS_RESPONSE_TIME + 1 )
147
149
node .setmocktime (cur_mock_time )
148
- self .log .info ("Test that the node does not get evicted" )
150
+ self .log .info ("Test that the peer does not get evicted" )
149
151
peer .sync_with_ping ()
150
152
151
153
node .disconnect_p2ps ()
@@ -205,7 +207,7 @@ def test_outbound_eviction_mixed(self):
205
207
206
208
cur_mock_time += (HEADERS_RESPONSE_TIME + 1 )
207
209
node .setmocktime (cur_mock_time )
208
- self .log .info ("Check how none of the honest nor protected peers was evicted but all the misbehaving unprotected were" )
210
+ self .log .info ("Check that none of the honest or protected peers were evicted, but all misbehaving unprotected peers were" )
209
211
for peer in protected_peers + honest_unprotected_peers :
210
212
peer .sync_with_ping ()
211
213
for peer in misbehaving_unprotected_peers :
0 commit comments