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