Skip to content

Commit faed5d3

Browse files
author
MarcoFalke
committed
test: Non-Shy version sender
1 parent 6f9db1e commit faed5d3

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

test/functional/p2p_add_connections.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2020-2021 The Bitcoin Core developers
2+
# Copyright (c) 2020-present The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test add_outbound_p2p_connection test framework functionality"""
@@ -11,6 +11,14 @@
1111
check_node_connections,
1212
)
1313

14+
15+
class VersionSender(P2PInterface):
16+
def on_open(self):
17+
assert self.on_connection_send_msg is not None
18+
self.send_version()
19+
assert self.on_connection_send_msg is None
20+
21+
1422
class P2PFeelerReceiver(P2PInterface):
1523
def on_version(self, message):
1624
# The bitcoind node closes feeler connections as soon as a version
@@ -106,5 +114,19 @@ def run_test(self):
106114
# Feeler connections do not request tx relay
107115
assert_equal(feeler_conn.last_message["version"].relay, 0)
108116

117+
self.log.info("Send version message early to node")
118+
# Normally the test framework would be shy and send the version message
119+
# only after it received one. See the on_version method. Check that
120+
# bitcoind behaves properly when a version is sent unexpectedly (but
121+
# tolerably) early.
122+
#
123+
# This checks that bitcoind sends its own version prior to processing
124+
# the remote version (and replying with a verack). Otherwise it would
125+
# be violating its own rules, such as "non-version message before
126+
# version handshake".
127+
ver_conn = self.nodes[0].add_outbound_p2p_connection(VersionSender(), p2p_idx=6, connection_type="outbound-full-relay", supports_v2_p2p=False, advertise_v2_p2p=False)
128+
ver_conn.sync_with_ping()
129+
130+
109131
if __name__ == '__main__':
110132
P2PAddConnections().main()

0 commit comments

Comments
 (0)