aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSergi Delgado Segura <sergi.delgado.s@gmail.com>2024-03-01 11:08:39 -0500
committerSergi Delgado Segura <sergi.delgado.s@gmail.com>2024-04-26 11:15:22 -0400
commitd53d84834747c37f4060a9ef379e0a6b50155246 (patch)
treefc61a2cae3f857ede33a4e342e4e57b67494e05e /test
parenta8d9a0edc7cef2c31a557ef53eb45520976b0d65 (diff)
downloadbitcoin-d53d84834747c37f4060a9ef379e0a6b50155246.tar.xz
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
Diffstat (limited to 'test')
-rwxr-xr-xtest/functional/p2p_outbound_eviction.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/functional/p2p_outbound_eviction.py b/test/functional/p2p_outbound_eviction.py
index 43dec4df83..8d89688999 100755
--- a/test/functional/p2p_outbound_eviction.py
+++ b/test/functional/p2p_outbound_eviction.py
@@ -212,12 +212,41 @@ class P2POutEvict(BitcoinTestFramework):
node.disconnect_p2ps()
+ def test_outbound_eviction_blocks_relay_only(self):
+ # The logic for outbound eviction protection only applies to outbound-full-relay peers
+ # This tests that other types of peers (blocks-relay-only for instance) are not granted protection
+ node = self.nodes[0]
+ cur_mock_time = node.mocktime
+ tip_header = from_hex(CBlockHeader(), node.getblockheader(node.getbestblockhash(), False))
+
+ self.log.info("Create an blocks-only outbound connection to a peer that shares our tip. This would usually grant protection")
+ peer = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=0, connection_type="block-relay-only")
+ peer.send_and_ping(msg_headers([tip_header]))
+
+ self.log.info("Mine a new block and sync with our peer")
+ self.generateblock(node, output="raw(42)", transactions=[])
+ peer.sync_with_ping()
+
+ self.log.info("Let enough time pass for the timeouts to go off")
+ # Trigger the timeouts and check how the peer gets evicted, since protection is only given to outbound-full-relay peers
+ cur_mock_time += (CHAIN_SYNC_TIMEOUT + 1)
+ node.setmocktime(cur_mock_time)
+ peer.sync_with_ping()
+ peer.wait_for_getheaders(block_hash=tip_header.hash)
+ cur_mock_time += (HEADERS_RESPONSE_TIME + 1)
+ node.setmocktime(cur_mock_time)
+ self.log.info("Test that the peer gets evicted")
+ peer.wait_for_disconnect()
+
+ node.disconnect_p2ps()
+
def run_test(self):
self.nodes[0].setmocktime(int(time.time()))
self.test_outbound_eviction_unprotected()
self.test_outbound_eviction_protected()
self.test_outbound_eviction_mixed()
+ self.test_outbound_eviction_blocks_relay_only()
if __name__ == '__main__':