@ -25,6 +25,8 @@ generator that returns TestInstance objects. See below for definition.
# on_getheaders: provide headers via BlockStore
# on_getheaders: provide headers via BlockStore
# on_getdata: provide blocks via BlockStore
# on_getdata: provide blocks via BlockStore
global mininode_lock
class TestNode ( NodeConnCB ) :
class TestNode ( NodeConnCB ) :
def __init__ ( self , block_store , tx_store ) :
def __init__ ( self , block_store , tx_store ) :
@ -148,6 +150,7 @@ class TestManager(object):
max_tries = 10 / sleep_time # Wait at most 10 seconds
max_tries = 10 / sleep_time # Wait at most 10 seconds
while max_tries > 0 :
while max_tries > 0 :
done = True
done = True
with mininode_lock :
for c in self . connections :
for c in self . connections :
if c . cb . verack_received is False :
if c . cb . verack_received is False :
done = False
done = False
@ -161,6 +164,7 @@ class TestManager(object):
while received_pongs is not True :
while received_pongs is not True :
time . sleep ( 0.05 )
time . sleep ( 0.05 )
received_pongs = True
received_pongs = True
with mininode_lock :
for c in self . connections :
for c in self . connections :
if c . cb . received_ping_response ( counter ) is not True :
if c . cb . received_ping_response ( counter ) is not True :
received_pongs = False
received_pongs = False
@ -173,6 +177,7 @@ class TestManager(object):
# Wait for nodes to request block (50ms sleep * 20 tries * num_blocks)
# Wait for nodes to request block (50ms sleep * 20 tries * num_blocks)
max_tries = 20 * num_blocks
max_tries = 20 * num_blocks
while max_tries > 0 :
while max_tries > 0 :
with mininode_lock :
results = [ blockhash in c . cb . block_request_map and
results = [ blockhash in c . cb . block_request_map and
c . cb . block_request_map [ blockhash ] for c in self . connections ]
c . cb . block_request_map [ blockhash ] for c in self . connections ]
if False not in results :
if False not in results :
@ -199,6 +204,7 @@ class TestManager(object):
# Wait for nodes to request transaction (50ms sleep * 20 tries * num_events)
# Wait for nodes to request transaction (50ms sleep * 20 tries * num_events)
max_tries = 20 * num_events
max_tries = 20 * num_events
while max_tries > 0 :
while max_tries > 0 :
with mininode_lock :
results = [ txhash in c . cb . tx_request_map and
results = [ txhash in c . cb . tx_request_map and
c . cb . tx_request_map [ txhash ] for c in self . connections ]
c . cb . tx_request_map [ txhash ] for c in self . connections ]
if False not in results :
if False not in results :
@ -221,11 +227,13 @@ class TestManager(object):
self . ping_counter + = 1
self . ping_counter + = 1
# Sort inv responses from each node
# Sort inv responses from each node
with mininode_lock :
[ c . cb . lastInv . sort ( ) for c in self . connections ]
[ c . cb . lastInv . sort ( ) for c in self . connections ]
# Verify that the tip of each connection all agree with each other, and
# Verify that the tip of each connection all agree with each other, and
# with the expected outcome (if given)
# with the expected outcome (if given)
def check_results ( self , blockhash , outcome ) :
def check_results ( self , blockhash , outcome ) :
with mininode_lock :
for c in self . connections :
for c in self . connections :
if outcome is None :
if outcome is None :
if c . cb . bestblockhash != self . connections [ 0 ] . cb . bestblockhash :
if c . cb . bestblockhash != self . connections [ 0 ] . cb . bestblockhash :
@ -242,6 +250,7 @@ class TestManager(object):
# perhaps it would be useful to add the ability to check explicitly that
# perhaps it would be useful to add the ability to check explicitly that
# a particular tx's existence in the mempool is the same across all nodes.
# a particular tx's existence in the mempool is the same across all nodes.
def check_mempool ( self , txhash , outcome ) :
def check_mempool ( self , txhash , outcome ) :
with mininode_lock :
for c in self . connections :
for c in self . connections :
if outcome is None :
if outcome is None :
# Make sure the mempools agree with each other
# Make sure the mempools agree with each other
@ -272,6 +281,7 @@ class TestManager(object):
block = b_or_t
block = b_or_t
block_outcome = outcome
block_outcome = outcome
# Add to shared block_store, set as current block
# Add to shared block_store, set as current block
with mininode_lock :
self . block_store . add_block ( block )
self . block_store . add_block ( block )
for c in self . connections :
for c in self . connections :
c . cb . block_request_map [ block . sha256 ] = False
c . cb . block_request_map [ block . sha256 ] = False
@ -288,7 +298,8 @@ class TestManager(object):
assert ( isinstance ( b_or_t , CTransaction ) )
assert ( isinstance ( b_or_t , CTransaction ) )
tx = b_or_t
tx = b_or_t
tx_outcome = outcome
tx_outcome = outcome
# Add to shared tx store
# Add to shared tx store and clear map entry
with mininode_lock :
self . tx_store . add_transaction ( tx )
self . tx_store . add_transaction ( tx )
for c in self . connections :
for c in self . connections :
c . cb . tx_request_map [ tx . sha256 ] = False
c . cb . tx_request_map [ tx . sha256 ] = False