Skip to content

Commit

Permalink
Fixes and refactorings related to using mnsync in tests (#3136)
Browse files Browse the repository at this point in the history
* Drop `get_mnsync_status`, `wait_to_sync` and `sync_masternodes` and introduce `force_finish_mnsync` for MNs only

* Use `force_finish_mnsync` from util.py in dip3-deterministicmns.py and drop local unused functions

Also move the call, `force_finish_mnsync` should be called before `connect_nodes_bi`
  • Loading branch information
UdjinM6 authored Oct 9, 2019
1 parent eb87ad2 commit e0c5624
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 49 deletions.
21 changes: 1 addition & 20 deletions test/functional/dip3-deterministicmns.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,12 +243,12 @@ def start_mn(self, mn):
self.add_nodes(1)
extra_args = ['-masternode=1', '-masternodeblsprivkey=%s' % mn.blsMnkey]
self.start_node(mn.idx, extra_args = self.extra_args + extra_args)
force_finish_mnsync(self.nodes[mn.idx])
for i in range(0, len(self.nodes)):
if i < len(self.nodes) and self.nodes[i] is not None and self.nodes[i].process is not None and i != mn.idx:
connect_nodes_bi(self.nodes, mn.idx, i)
mn.node = self.nodes[mn.idx]
self.sync_all()
self.force_finish_mnsync(mn.node)

def spend_mn_collateral(self, mn, with_dummy_input_output=False):
return self.spend_input(mn.collateral_txid, mn.collateral_vout, 1000, with_dummy_input_output)
Expand Down Expand Up @@ -276,25 +276,6 @@ def test_protx_update_service(self, mn):
self.nodes[0].protx('update_service', mn.protx_hash, '127.0.0.1:%d' % mn.p2p_port, mn.blsMnkey, "", mn.fundsAddr)
self.nodes[0].generate(1)

def force_finish_mnsync(self, node):
while True:
s = node.mnsync('next')
if s == 'sync updated to MASTERNODE_SYNC_FINISHED':
break
time.sleep(0.1)

def force_finish_mnsync_list(self, node):
if node.mnsync('status')['AssetName'] == 'MASTERNODE_SYNC_WAITING':
node.mnsync('next')

while True:
mnlist = node.masternode('list', 'status')
if len(mnlist) != 0:
time.sleep(0.5)
self.force_finish_mnsync(node)
return
time.sleep(0.1)

def assert_mnlists(self, mns):
for node in self.nodes:
self.assert_mnlist(node, mns)
Expand Down
3 changes: 1 addition & 2 deletions test/functional/invalidblockrequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from test_framework.blocktools import create_block, create_coinbase, create_transaction, network_thread_start
from test_framework.mininode import P2PDataStore, COIN
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, sync_masternodes
from test_framework.util import assert_equal


class InvalidBlockRequestTest(BitcoinTestFramework):
Expand All @@ -30,7 +30,6 @@ def run_test(self):
node.add_p2p_connection(P2PDataStore())

network_thread_start()
sync_masternodes(self.nodes, True)
node.p2p.wait_for_verack()

best_block = node.getblock(node.getbestblockhash())
Expand Down
1 change: 0 additions & 1 deletion test/functional/p2p-fullblocktest.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ def run_test(self):
self.test = TestManager(self, self.options.tmpdir)
self.test.add_all_connections(self.nodes)
network_thread_start()
sync_masternodes(self.nodes, True)
self.test.run()

def add_transactions_to_block(self, block, tx_list):
Expand Down
3 changes: 0 additions & 3 deletions test/functional/sporks.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ def run_test(self):
assert(self.get_test_spork_state(self.nodes[0]))
assert(self.get_test_spork_state(self.nodes[1]))

# Force finish mnsync node as otherwise it will never send out headers to other peers
wait_to_sync(self.nodes[1], fast_mnsync=True)

# Generate one block to kick off masternode sync, which also starts sporks syncing for node2
self.nodes[1].generate(1)

Expand Down
8 changes: 2 additions & 6 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,14 @@
connect_nodes,
copy_datadir,
disconnect_nodes,
force_finish_mnsync,
initialize_datadir,
log_filename,
p2p_port,
set_node_times,
satoshi_round,
sync_blocks,
sync_mempools,
sync_masternodes,
wait_to_sync,
wait_until,
)

Expand Down Expand Up @@ -580,7 +579,7 @@ def do_start(idx):
self.start_node(idx + start_idx, extra_args=args)
self.mninfo[idx].nodeIdx = idx + start_idx
self.mninfo[idx].node = self.nodes[idx + start_idx]
wait_to_sync(self.mninfo[idx].node, True)
force_finish_mnsync(self.mninfo[idx].node)

def do_connect(idx):
for i in range(0, idx + 1):
Expand All @@ -606,8 +605,6 @@ def do_connect(idx):
job.result()
jobs.clear()

sync_masternodes(self.nodes, True)

executor.shutdown()

def setup_network(self):
Expand All @@ -624,7 +621,6 @@ def setup_network(self):
self.log.info("Creating and starting %s simple nodes", num_simple_nodes)
for i in range(0, num_simple_nodes):
self.create_simple_node()
sync_masternodes(self.nodes, True)

self.log.info("Activating DIP3")
if not self.fast_dip3_enforcement:
Expand Down
26 changes: 9 additions & 17 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,6 @@ def get_rpc_proxy(url, node_number, timeout=None, coveragedir=None):

return coverage.AuthServiceProxyWrapper(proxy, coverage_logfile)

def get_mnsync_status(node):
result = node.mnsync("status")
return result['IsSynced']

def wait_to_sync(node, fast_mnsync=False):
while True:
synced = get_mnsync_status(node)
if synced:
break
time.sleep(0.2)
if fast_mnsync:
# skip mnsync states
node.mnsync("next")

def p2p_port(n):
assert(n <= MAX_NODES)
return PORT_MIN + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES)
Expand Down Expand Up @@ -449,9 +435,15 @@ def sync_mempools(rpc_connections, *, wait=1, timeout=60):
timeout -= wait
raise AssertionError("Mempool sync failed")

def sync_masternodes(rpc_connections, fast_mnsync=False):
for node in rpc_connections:
wait_to_sync(node, fast_mnsync)
def force_finish_mnsync(node):
"""
Masternodes won't accept incoming connections while IsSynced is false.
Force them to switch to this state to speed things up.
"""
while True:
if node.mnsync("status")['IsSynced']:
break
node.mnsync("next")

# Transaction/Block functions
#############################
Expand Down

0 comments on commit e0c5624

Please sign in to comment.