Skip to content

Commit

Permalink
test: p2p: check limited peers desirability (depending on best block …
Browse files Browse the repository at this point in the history
…depth)

This adds coverage for the logic introduced in PR #28170
("p2p: adaptive connections services flags").
  • Loading branch information
theStack committed Mar 5, 2024
1 parent b6c7ae6 commit 49fbd57
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/functional/p2p_handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
Test P2P behaviour during the handshake phase (VERSION, VERACK messages).
"""
import itertools
import time

from test_framework.test_framework import BitcoinTestFramework
from test_framework.messages import (
NODE_NETWORK,
NODE_NETWORK_LIMITED,
NODE_NONE,
NODE_P2P_V2,
NODE_WITNESS,
Expand Down Expand Up @@ -60,6 +62,12 @@ def run_test(self):
self.test_desirable_service_flags(node, [NODE_NONE, NODE_NETWORK, NODE_WITNESS], expect_disconnect=True)
self.test_desirable_service_flags(node, [NODE_NETWORK | NODE_WITNESS], expect_disconnect=False)

self.log.info("Check that limited peers are only desired if the local chain is close to the tip (<24h)")
node.setmocktime(int(time.time()) + 25 * 3600) # tip outside the 24h window, should fail
self.test_desirable_service_flags(node, [NODE_NETWORK_LIMITED | NODE_WITNESS], expect_disconnect=True)
node.setmocktime(int(time.time()) + 23 * 3600) # tip inside the 24h window, should succeed
self.test_desirable_service_flags(node, [NODE_NETWORK_LIMITED | NODE_WITNESS], expect_disconnect=False)

self.log.info("Check that feeler connections get disconnected immediately")
with node.assert_debug_log([f"feeler connection completed"]):
self.add_outbound_connection(node, "feeler", NODE_NONE, wait_for_disconnect=True)
Expand Down

0 comments on commit 49fbd57

Please sign in to comment.