9
9
10
10
This test connects to a node and sends it a few messages, trying to intice it
11
11
into sending us something it shouldn't.
12
- """
12
+
13
+ Also test that nodes that send unsupported service bits to bitcoind are disconnected
14
+ and don't receive a VERACK. Unsupported service bits are currently 1 << 5 and
15
+ 1 << 7 (until August 1st 2018)."""
13
16
14
17
from test_framework .mininode import *
15
18
from test_framework .test_framework import BitcoinTestFramework
@@ -98,20 +101,29 @@ def run_test(self):
98
101
no_version_bannode = CNodeNoVersionBan ()
99
102
no_version_idlenode = CNodeNoVersionIdle ()
100
103
no_verack_idlenode = CNodeNoVerackIdle ()
104
+ unsupported_service_bit5_node = CLazyNode ()
105
+ unsupported_service_bit7_node = CLazyNode ()
101
106
107
+ self .nodes [0 ].setmocktime (1501545600 ) # August 1st 2017
102
108
connections = []
103
109
connections .append (NodeConn ('127.0.0.1' , p2p_port (0 ), self .nodes [0 ], no_version_bannode , send_version = False ))
104
110
connections .append (NodeConn ('127.0.0.1' , p2p_port (0 ), self .nodes [0 ], no_version_idlenode , send_version = False ))
105
111
connections .append (NodeConn ('127.0.0.1' , p2p_port (0 ), self .nodes [0 ], no_verack_idlenode ))
112
+ connections .append (NodeConn ('127.0.0.1' , p2p_port (0 ), self .nodes [0 ], unsupported_service_bit5_node , services = NODE_NETWORK | NODE_UNSUPPORTED_SERVICE_BIT_5 ))
113
+ connections .append (NodeConn ('127.0.0.1' , p2p_port (0 ), self .nodes [0 ], unsupported_service_bit7_node , services = NODE_NETWORK | NODE_UNSUPPORTED_SERVICE_BIT_7 ))
106
114
no_version_bannode .add_connection (connections [0 ])
107
115
no_version_idlenode .add_connection (connections [1 ])
108
116
no_verack_idlenode .add_connection (connections [2 ])
117
+ unsupported_service_bit5_node .add_connection (connections [3 ])
118
+ unsupported_service_bit7_node .add_connection (connections [4 ])
109
119
110
120
NetworkThread ().start () # Start up network handling in another thread
111
121
112
122
assert wait_until (lambda : no_version_bannode .ever_connected , timeout = 10 )
113
123
assert wait_until (lambda : no_version_idlenode .ever_connected , timeout = 10 )
114
124
assert wait_until (lambda : no_verack_idlenode .version_received , timeout = 10 )
125
+ assert wait_until (lambda : unsupported_service_bit5_node .ever_connected , timeout = 10 )
126
+ assert wait_until (lambda : unsupported_service_bit7_node .ever_connected , timeout = 10 )
115
127
116
128
# Mine a block and make sure that it's not sent to the connected nodes
117
129
self .nodes [0 ].generate (1 )
@@ -122,12 +134,32 @@ def run_test(self):
122
134
#This node should have been banned
123
135
assert not no_version_bannode .connected
124
136
137
+ # These nodes should have been disconnected
138
+ assert not unsupported_service_bit5_node .connected
139
+ assert not unsupported_service_bit7_node .connected
140
+
125
141
[conn .disconnect_node () for conn in connections ]
126
142
127
143
# Make sure no unexpected messages came in
128
144
assert (no_version_bannode .unexpected_msg == False )
129
145
assert (no_version_idlenode .unexpected_msg == False )
130
146
assert (no_verack_idlenode .unexpected_msg == False )
147
+ assert not unsupported_service_bit5_node .unexpected_msg
148
+ assert not unsupported_service_bit7_node .unexpected_msg
149
+
150
+ self .log .info ("Service bits 5 and 7 are allowed after August 1st 2018" )
151
+ self .nodes [0 ].setmocktime (1533168000 ) # August 2nd 2018
152
+
153
+ allowed_service_bit5_node = NodeConnCB ()
154
+ allowed_service_bit7_node = NodeConnCB ()
155
+
156
+ connections .append (NodeConn ('127.0.0.1' , p2p_port (0 ), self .nodes [0 ], allowed_service_bit5_node , services = NODE_NETWORK | NODE_UNSUPPORTED_SERVICE_BIT_5 ))
157
+ connections .append (NodeConn ('127.0.0.1' , p2p_port (0 ), self .nodes [0 ], allowed_service_bit7_node , services = NODE_NETWORK | NODE_UNSUPPORTED_SERVICE_BIT_7 ))
158
+ allowed_service_bit5_node .add_connection (connections [5 ])
159
+ allowed_service_bit7_node .add_connection (connections [6 ])
160
+
161
+ assert wait_until (lambda : allowed_service_bit5_node .message_count ["verack" ], timeout = 10 )
162
+ assert wait_until (lambda : allowed_service_bit7_node .message_count ["verack" ], timeout = 10 )
131
163
132
164
if __name__ == '__main__' :
133
165
P2PLeakTest ().main ()
0 commit comments