@@ -120,8 +120,9 @@ def __init__(self):
120
120
def is_connected (self ):
121
121
return self ._transport is not None
122
122
123
- def peer_connect (self , dstaddr , dstport , * , net ):
123
+ def peer_connect (self , dstaddr , dstport , * , net , factor ):
124
124
assert not self .is_connected
125
+ self .factor = factor
125
126
self .dstaddr = dstaddr
126
127
self .dstport = dstport
127
128
# The initial message to send after the connection was made:
@@ -367,9 +368,12 @@ def on_version(self, message):
367
368
368
369
# Connection helper methods
369
370
371
+ def wait_until (self , test_function , timeout ):
372
+ wait_until (test_function , timeout = timeout , lock = mininode_lock , factor = self .factor )
373
+
370
374
def wait_for_disconnect (self , timeout = 60 ):
371
375
test_function = lambda : not self .is_connected
372
- wait_until (test_function , timeout = timeout , lock = mininode_lock )
376
+ self . wait_until (test_function , timeout = timeout )
373
377
374
378
# Message receiving helper methods
375
379
@@ -380,14 +384,14 @@ def test_function():
380
384
return False
381
385
return self .last_message ['tx' ].tx .rehash () == txid
382
386
383
- wait_until (test_function , timeout = timeout , lock = mininode_lock )
387
+ self . wait_until (test_function , timeout = timeout )
384
388
385
389
def wait_for_block (self , blockhash , timeout = 60 ):
386
390
def test_function ():
387
391
assert self .is_connected
388
392
return self .last_message .get ("block" ) and self .last_message ["block" ].block .rehash () == blockhash
389
393
390
- wait_until (test_function , timeout = timeout , lock = mininode_lock )
394
+ self . wait_until (test_function , timeout = timeout )
391
395
392
396
def wait_for_header (self , blockhash , timeout = 60 ):
393
397
def test_function ():
@@ -397,7 +401,7 @@ def test_function():
397
401
return False
398
402
return last_headers .headers [0 ].rehash () == int (blockhash , 16 )
399
403
400
- wait_until (test_function , timeout = timeout , lock = mininode_lock )
404
+ self . wait_until (test_function , timeout = timeout )
401
405
402
406
def wait_for_merkleblock (self , blockhash , timeout = 60 ):
403
407
def test_function ():
@@ -407,7 +411,7 @@ def test_function():
407
411
return False
408
412
return last_filtered_block .merkleblock .header .rehash () == int (blockhash , 16 )
409
413
410
- wait_until (test_function , timeout = timeout , lock = mininode_lock )
414
+ self . wait_until (test_function , timeout = timeout )
411
415
412
416
def wait_for_getdata (self , hash_list , timeout = 60 ):
413
417
"""Waits for a getdata message.
@@ -421,7 +425,7 @@ def test_function():
421
425
return False
422
426
return [x .hash for x in last_data .inv ] == hash_list
423
427
424
- wait_until (test_function , timeout = timeout , lock = mininode_lock )
428
+ self . wait_until (test_function , timeout = timeout )
425
429
426
430
def wait_for_getheaders (self , timeout = 60 ):
427
431
"""Waits for a getheaders message.
@@ -435,7 +439,7 @@ def test_function():
435
439
assert self .is_connected
436
440
return self .last_message .get ("getheaders" )
437
441
438
- wait_until (test_function , timeout = timeout , lock = mininode_lock )
442
+ self . wait_until (test_function , timeout = timeout )
439
443
440
444
def wait_for_inv (self , expected_inv , timeout = 60 ):
441
445
"""Waits for an INV message and checks that the first inv object in the message was as expected."""
@@ -448,13 +452,13 @@ def test_function():
448
452
self .last_message ["inv" ].inv [0 ].type == expected_inv [0 ].type and \
449
453
self .last_message ["inv" ].inv [0 ].hash == expected_inv [0 ].hash
450
454
451
- wait_until (test_function , timeout = timeout , lock = mininode_lock )
455
+ self . wait_until (test_function , timeout = timeout )
452
456
453
457
def wait_for_verack (self , timeout = 60 ):
454
458
def test_function ():
455
459
return self .message_count ["verack" ]
456
460
457
- wait_until (test_function , timeout = timeout , lock = mininode_lock )
461
+ self . wait_until (test_function , timeout = timeout )
458
462
459
463
# Message sending helper functions
460
464
@@ -470,7 +474,7 @@ def test_function():
470
474
assert self .is_connected
471
475
return self .last_message .get ("pong" ) and self .last_message ["pong" ].nonce == self .ping_counter
472
476
473
- wait_until (test_function , timeout = timeout , lock = mininode_lock )
477
+ self . wait_until (test_function , timeout = timeout )
474
478
self .ping_counter += 1
475
479
476
480
@@ -586,15 +590,15 @@ def send_blocks_and_test(self, blocks, node, *, success=True, force_send=False,
586
590
self .send_message (msg_block (block = b ))
587
591
else :
588
592
self .send_message (msg_headers ([CBlockHeader (block ) for block in blocks ]))
589
- wait_until (lambda : blocks [- 1 ].sha256 in self .getdata_requests , timeout = timeout , lock = mininode_lock )
593
+ self . wait_until (lambda : blocks [- 1 ].sha256 in self .getdata_requests , timeout = timeout )
590
594
591
595
if expect_disconnect :
592
596
self .wait_for_disconnect (timeout = timeout )
593
597
else :
594
598
self .sync_with_ping (timeout = timeout )
595
599
596
600
if success :
597
- wait_until (lambda : node .getbestblockhash () == blocks [- 1 ].hash , timeout = timeout )
601
+ self . wait_until (lambda : node .getbestblockhash () == blocks [- 1 ].hash , timeout = timeout )
598
602
else :
599
603
assert node .getbestblockhash () != blocks [- 1 ].hash
600
604
0 commit comments