Skip to content

Commit d53d848

Browse files
committed
test: adds outbound eviction tests for non outbound-full-relay peers
Peer protection is only given to outbound-full-relay peers. Add a negative test to check that other type of outbound peers are not given protection under the circumstances that outbound-full-relay would
1 parent a8d9a0e commit d53d848

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/functional/p2p_outbound_eviction.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,41 @@ def test_outbound_eviction_mixed(self):
212212

213213
node.disconnect_p2ps()
214214

215+
def test_outbound_eviction_blocks_relay_only(self):
216+
# The logic for outbound eviction protection only applies to outbound-full-relay peers
217+
# This tests that other types of peers (blocks-relay-only for instance) are not granted protection
218+
node = self.nodes[0]
219+
cur_mock_time = node.mocktime
220+
tip_header = from_hex(CBlockHeader(), node.getblockheader(node.getbestblockhash(), False))
221+
222+
self.log.info("Create an blocks-only outbound connection to a peer that shares our tip. This would usually grant protection")
223+
peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=0, connection_type="block-relay-only")
224+
peer.send_and_ping(msg_headers([tip_header]))
225+
226+
self.log.info("Mine a new block and sync with our peer")
227+
self.generateblock(node, output="raw(42)", transactions=[])
228+
peer.sync_with_ping()
229+
230+
self.log.info("Let enough time pass for the timeouts to go off")
231+
# Trigger the timeouts and check how the peer gets evicted, since protection is only given to outbound-full-relay peers
232+
cur_mock_time += (CHAIN_SYNC_TIMEOUT + 1)
233+
node.setmocktime(cur_mock_time)
234+
peer.sync_with_ping()
235+
peer.wait_for_getheaders(block_hash=tip_header.hash)
236+
cur_mock_time += (HEADERS_RESPONSE_TIME + 1)
237+
node.setmocktime(cur_mock_time)
238+
self.log.info("Test that the peer gets evicted")
239+
peer.wait_for_disconnect()
240+
241+
node.disconnect_p2ps()
242+
215243

216244
def run_test(self):
217245
self.nodes[0].setmocktime(int(time.time()))
218246
self.test_outbound_eviction_unprotected()
219247
self.test_outbound_eviction_protected()
220248
self.test_outbound_eviction_mixed()
249+
self.test_outbound_eviction_blocks_relay_only()
221250

222251

223252
if __name__ == '__main__':

0 commit comments

Comments
 (0)