Skip to content

Commit 032a597

Browse files
committed
test: make p2p_handshake robust against timeoffset warnings
The test requires that limited nodes are not peered with when the node's system time exceeds ~ 24h of the node's chaintip timestamp, as per PeerManagerImpl::GetDesirableServiceFlags. By patching this test to modify the timestamp of the chaintip as opposed to mocking the node's system time, we make it resilient to future commits where the node raises a warning if it detects its system time is too much out of sync with its outbound peers. See bitcoin/bitcoin#29623
1 parent 71b6319 commit 032a597

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

test/functional/p2p_handshake.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def test_desirable_service_flags(self, node, service_flag_tests, desirable_servi
6262
assert (services & desirable_service_flags) == desirable_service_flags
6363
self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)
6464

65+
def generate_at_mocktime(self, time):
66+
self.nodes[0].setmocktime(time)
67+
self.generate(self.nodes[0], 1)
68+
self.nodes[0].setmocktime(0)
69+
6570
def run_test(self):
6671
node = self.nodes[0]
6772
self.log.info("Check that lacking desired service flags leads to disconnect (non-pruned peers)")
@@ -71,10 +76,10 @@ def run_test(self):
7176
DESIRABLE_SERVICE_FLAGS_FULL, expect_disconnect=False)
7277

7378
self.log.info("Check that limited peers are only desired if the local chain is close to the tip (<24h)")
74-
node.setmocktime(int(time.time()) + 25 * 3600) # tip outside the 24h window, should fail
79+
self.generate_at_mocktime(int(time.time()) - 25 * 3600) # tip outside the 24h window, should fail
7580
self.test_desirable_service_flags(node, [NODE_NETWORK_LIMITED | NODE_WITNESS],
7681
DESIRABLE_SERVICE_FLAGS_FULL, expect_disconnect=True)
77-
node.setmocktime(int(time.time()) + 23 * 3600) # tip inside the 24h window, should succeed
82+
self.generate_at_mocktime(int(time.time()) - 23 * 3600) # tip inside the 24h window, should succeed
7883
self.test_desirable_service_flags(node, [NODE_NETWORK_LIMITED | NODE_WITNESS],
7984
DESIRABLE_SERVICE_FLAGS_PRUNED, expect_disconnect=False)
8085

0 commit comments

Comments
 (0)