22
22
from test_framework .crypto .chacha20 import REKEY_INTERVAL
23
23
24
24
25
+ def check_v2_connection_info (node , peer ):
26
+ peerinfo = node .getpeerinfo ()[- 1 ]
27
+ protocol_type = peerinfo ["transport_protocol_type" ]
28
+ if peer .supports_v2_p2p :
29
+ assert_equal (protocol_type , "v2" )
30
+ assert_equal (peer .v2_state .peer ['session_id' ].hex (), peerinfo ["session_id" ])
31
+ else :
32
+ assert_equal (protocol_type , "v1" )
33
+
34
+
25
35
class P2PEncrypted (BitcoinTestFramework ):
26
36
def set_test_params (self ):
27
37
self .num_nodes = 2
@@ -56,28 +66,29 @@ def run_test(self):
56
66
self .log .info ("Check inbound connection to v2 TestNode from v2 P2PConnection is v2" )
57
67
peer1 = node0 .add_p2p_connection (P2PInterface (), wait_for_verack = True , supports_v2_p2p = True )
58
68
assert peer1 .supports_v2_p2p
59
- assert_equal (node0 . getpeerinfo ()[ - 1 ][ "transport_protocol_type" ], "v2" )
69
+ check_v2_connection_info (node0 , peer1 )
60
70
61
71
self .log .info ("Check inbound connection to v2 TestNode from v1 P2PConnection is v1" )
62
72
peer2 = node0 .add_p2p_connection (P2PInterface (), wait_for_verack = True , supports_v2_p2p = False )
63
73
assert not peer2 .supports_v2_p2p
64
- assert_equal (node0 . getpeerinfo ()[ - 1 ][ "transport_protocol_type" ], "v1" )
74
+ check_v2_connection_info (node0 , peer2 )
65
75
66
76
self .log .info ("Check outbound connection from v2 TestNode to v1 P2PConnection advertised as v1 is v1" )
67
77
peer3 = node0 .add_outbound_p2p_connection (P2PInterface (), p2p_idx = 0 , supports_v2_p2p = False , advertise_v2_p2p = False )
68
78
assert not peer3 .supports_v2_p2p
69
- assert_equal (node0 . getpeerinfo ()[ - 1 ][ "transport_protocol_type" ], "v1" )
79
+ check_v2_connection_info (node0 , peer3 )
70
80
71
81
# v2 TestNode performs downgrading here
72
82
self .log .info ("Check outbound connection from v2 TestNode to v1 P2PConnection advertised as v2 is v1" )
73
- peer4 = node0 .add_outbound_p2p_connection (P2PInterface (), p2p_idx = 1 , supports_v2_p2p = False , advertise_v2_p2p = True )
83
+ with node0 .assert_debug_log (['retrying with v1 transport protocol for peer' ], timeout = 5 ):
84
+ peer4 = node0 .add_outbound_p2p_connection (P2PInterface (), p2p_idx = 1 , supports_v2_p2p = False , advertise_v2_p2p = True )
74
85
assert not peer4 .supports_v2_p2p
75
- assert_equal (node0 . getpeerinfo ()[ - 1 ][ "transport_protocol_type" ], "v1" )
86
+ check_v2_connection_info (node0 , peer4 )
76
87
77
88
self .log .info ("Check outbound connection from v2 TestNode to v2 P2PConnection advertised as v2 is v2" )
78
89
peer5 = node0 .add_outbound_p2p_connection (P2PInterface (), p2p_idx = 2 , supports_v2_p2p = True , advertise_v2_p2p = True )
79
90
assert peer5 .supports_v2_p2p
80
- assert_equal (node0 . getpeerinfo ()[ - 1 ][ "transport_protocol_type" ], "v2" )
91
+ check_v2_connection_info (node0 , peer5 )
81
92
82
93
self .log .info ("Check if version is sent and verack is received in inbound/outbound connections" )
83
94
assert_equal (len (node0 .getpeerinfo ()), 5 ) # check if above 5 connections are present in node0's getpeerinfo()
@@ -92,7 +103,7 @@ def run_test(self):
92
103
for i in range (2 ):
93
104
peer6 = node0 .add_p2p_connection (P2PDataStore (), supports_v2_p2p = True )
94
105
assert peer6 .supports_v2_p2p
95
- assert_equal (node0 . getpeerinfo ()[ - 1 ][ "transport_protocol_type" ], "v2" )
106
+ check_v2_connection_info (node0 , peer6 )
96
107
97
108
# Consider: node0 <-- peer6. node0 and node1 aren't connected here.
98
109
# Construct the following topology: node1 <--> node0 <-- peer6
@@ -126,7 +137,7 @@ def run_test(self):
126
137
self .restart_node (0 , ["-v2transport=0" ])
127
138
peer1 = node0 .add_p2p_connection (P2PInterface (), wait_for_verack = True , supports_v2_p2p = True )
128
139
assert not peer1 .supports_v2_p2p
129
- assert_equal (node0 . getpeerinfo ()[ - 1 ][ "transport_protocol_type" ], "v1" )
140
+ check_v2_connection_info (node0 , peer1 )
130
141
check_node_connections (node = node0 , num_in = 1 , num_out = 0 )
131
142
132
143
0 commit comments