File tree Expand file tree Collapse file tree 4 files changed +31
-8
lines changed Expand file tree Collapse file tree 4 files changed +31
-8
lines changed Original file line number Diff line number Diff line change 38
38
CTransaction ,
39
39
CTxIn ,
40
40
CTxOut ,
41
+ network_thread_join ,
42
+ network_thread_start ,
41
43
P2PInterface ,
42
44
msg_block ,
43
- msg_headers ,
44
- network_thread_start )
45
+ msg_headers )
45
46
from test_framework .script import (CScript , OP_TRUE )
46
47
from test_framework .test_framework import BitcoinTestFramework
47
48
from test_framework .util import assert_equal
@@ -159,13 +160,22 @@ def run_test(self):
159
160
self .block_time += 1
160
161
height += 1
161
162
163
+ # We're adding new connections so terminate the network thread
164
+ self .nodes [0 ].disconnect_p2ps ()
165
+ network_thread_join ()
166
+
162
167
# Start node1 and node2 with assumevalid so they accept a block with a bad signature.
163
168
self .start_node (1 , extra_args = ["-assumevalid=" + hex (block102 .sha256 )])
164
- p2p1 = self .nodes [1 ].add_p2p_connection (BaseNode ())
165
- p2p1 .wait_for_verack ()
166
-
167
169
self .start_node (2 , extra_args = ["-assumevalid=" + hex (block102 .sha256 )])
170
+
171
+ p2p0 = self .nodes [0 ].add_p2p_connection (BaseNode ())
172
+ p2p1 = self .nodes [1 ].add_p2p_connection (BaseNode ())
168
173
p2p2 = self .nodes [2 ].add_p2p_connection (BaseNode ())
174
+
175
+ network_thread_start ()
176
+
177
+ p2p0 .wait_for_verack ()
178
+ p2p1 .wait_for_verack ()
169
179
p2p2 .wait_for_verack ()
170
180
171
181
# send header lists to all three nodes
Original file line number Diff line number Diff line change 21
21
mininode_lock ,
22
22
msg_block ,
23
23
msg_getdata ,
24
+ network_thread_join ,
24
25
network_thread_start ,
25
26
)
26
27
from test_framework .test_framework import BitcoinTestFramework
@@ -131,7 +132,7 @@ def custom_method(self):
131
132
def run_test (self ):
132
133
"""Main test logic"""
133
134
134
- # Create a P2P connection to one of the nodes
135
+ # Create P2P connections to two of the nodes
135
136
self .nodes [0 ].add_p2p_connection (BaseNode ())
136
137
137
138
# Start up network handling in another thread. This needs to be called
@@ -188,7 +189,14 @@ def run_test(self):
188
189
connect_nodes (self .nodes [1 ], 2 )
189
190
190
191
self .log .info ("Add P2P connection to node2" )
192
+ # We can't add additional P2P connections once the network thread has started. Disconnect the connection
193
+ # to node0, wait for the network thread to terminate, then connect to node2. This is specific to
194
+ # the current implementation of the network thread and may be improved in future.
195
+ self .nodes [0 ].disconnect_p2ps ()
196
+ network_thread_join ()
197
+
191
198
self .nodes [2 ].add_p2p_connection (BaseNode ())
199
+ network_thread_start ()
192
200
self .nodes [2 ].p2p .wait_for_verack ()
193
201
194
202
self .log .info ("Wait for node2 reach current tip. Test that it has propagated all the blocks to us" )
Original file line number Diff line number Diff line change @@ -207,9 +207,13 @@ def run_test(self):
207
207
# disconnect/reconnect first
208
208
209
209
self .nodes [0 ].disconnect_p2ps ()
210
- test_node = self .nodes [0 ].add_p2p_connection (P2PInterface ())
210
+ self .nodes [1 ].disconnect_p2ps ()
211
+ network_thread_join ()
211
212
213
+ test_node = self .nodes [0 ].add_p2p_connection (P2PInterface ())
214
+ network_thread_start ()
212
215
test_node .wait_for_verack ()
216
+
213
217
test_node .send_message (msg_block (block_h1f ))
214
218
215
219
test_node .sync_with_ping ()
Original file line number Diff line number Diff line change @@ -126,8 +126,9 @@ def run_test(self):
126
126
127
127
self .nodes [0 ].disconnect_p2ps ()
128
128
129
- # Wait until all connections are closed
129
+ # Wait until all connections are closed and the network thread has terminated
130
130
wait_until (lambda : len (self .nodes [0 ].getpeerinfo ()) == 0 )
131
+ network_thread_join ()
131
132
132
133
# Make sure no unexpected messages came in
133
134
assert (no_version_bannode .unexpected_msg == False )
You can’t perform that action at this time.
0 commit comments