mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 23:09:44 -04:00
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 https://github.com/bitcoin/bitcoin/pull/29623
This commit is contained in:
parent
71b63195b3
commit
032a597482
1 changed files with 7 additions and 2 deletions
|
@ -62,6 +62,11 @@ class P2PHandshakeTest(BitcoinTestFramework):
|
||||||
assert (services & desirable_service_flags) == desirable_service_flags
|
assert (services & desirable_service_flags) == desirable_service_flags
|
||||||
self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)
|
self.add_outbound_connection(node, conn_type, services, wait_for_disconnect=False)
|
||||||
|
|
||||||
|
def generate_at_mocktime(self, time):
|
||||||
|
self.nodes[0].setmocktime(time)
|
||||||
|
self.generate(self.nodes[0], 1)
|
||||||
|
self.nodes[0].setmocktime(0)
|
||||||
|
|
||||||
def run_test(self):
|
def run_test(self):
|
||||||
node = self.nodes[0]
|
node = self.nodes[0]
|
||||||
self.log.info("Check that lacking desired service flags leads to disconnect (non-pruned peers)")
|
self.log.info("Check that lacking desired service flags leads to disconnect (non-pruned peers)")
|
||||||
|
@ -71,10 +76,10 @@ class P2PHandshakeTest(BitcoinTestFramework):
|
||||||
DESIRABLE_SERVICE_FLAGS_FULL, expect_disconnect=False)
|
DESIRABLE_SERVICE_FLAGS_FULL, expect_disconnect=False)
|
||||||
|
|
||||||
self.log.info("Check that limited peers are only desired if the local chain is close to the tip (<24h)")
|
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.generate_at_mocktime(int(time.time()) - 25 * 3600) # tip outside the 24h window, should fail
|
||||||
self.test_desirable_service_flags(node, [NODE_NETWORK_LIMITED | NODE_WITNESS],
|
self.test_desirable_service_flags(node, [NODE_NETWORK_LIMITED | NODE_WITNESS],
|
||||||
DESIRABLE_SERVICE_FLAGS_FULL, expect_disconnect=True)
|
DESIRABLE_SERVICE_FLAGS_FULL, expect_disconnect=True)
|
||||||
node.setmocktime(int(time.time()) + 23 * 3600) # tip inside the 24h window, should succeed
|
self.generate_at_mocktime(int(time.time()) - 23 * 3600) # tip inside the 24h window, should succeed
|
||||||
self.test_desirable_service_flags(node, [NODE_NETWORK_LIMITED | NODE_WITNESS],
|
self.test_desirable_service_flags(node, [NODE_NETWORK_LIMITED | NODE_WITNESS],
|
||||||
DESIRABLE_SERVICE_FLAGS_PRUNED, expect_disconnect=False)
|
DESIRABLE_SERVICE_FLAGS_PRUNED, expect_disconnect=False)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue