Skip to content

Commit

Permalink
Support "fast" mode when calling sync_masternodes (#2383)
Browse files Browse the repository at this point in the history
This will call "mnsync next" multiple times to force finishing of mnsync.
Also reduce sleep time to 200ms.
  • Loading branch information
codablock authored and UdjinM6 committed Oct 26, 2018
1 parent fcea333 commit 8f9b004
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
8 changes: 4 additions & 4 deletions qa/rpc-tests/autoix-mempool.py
Expand Up @@ -49,7 +49,7 @@ def activate_autoix_bip9(self):
if counter % sync_period == 0:
# sync nodes
self.sync_all()
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)

while self.get_autoix_bip9_status() == 'started':
set_mocktime(get_mocktime() + 1)
Expand All @@ -59,7 +59,7 @@ def activate_autoix_bip9(self):
if counter % sync_period == 0:
# sync nodes
self.sync_all()
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)

while self.get_autoix_bip9_status() == 'locked_in':
set_mocktime(get_mocktime() + 1)
Expand All @@ -69,11 +69,11 @@ def activate_autoix_bip9(self):
if counter % sync_period == 0:
# sync nodes
self.sync_all()
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)

# sync nodes
self.sync_all()
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)

assert(self.get_autoix_bip9_status() == 'active')

Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/invalidblockrequest.py
Expand Up @@ -33,7 +33,7 @@ def run_test(self):
self.tip = None
self.block_time = None
NetworkThread().start() # Start up network handling in another thread
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)
test.run()

def get_tests(self):
Expand Down
8 changes: 4 additions & 4 deletions qa/rpc-tests/p2p-autoinstantsend.py
Expand Up @@ -51,7 +51,7 @@ def activate_autoix_bip9(self):
if counter % sync_period == 0:
# sync nodes
self.sync_all()
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)

while self.get_autoix_bip9_status() == 'started':
set_mocktime(get_mocktime() + 1)
Expand All @@ -61,7 +61,7 @@ def activate_autoix_bip9(self):
if counter % sync_period == 0:
# sync nodes
self.sync_all()
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)

while self.get_autoix_bip9_status() == 'locked_in':
set_mocktime(get_mocktime() + 1)
Expand All @@ -71,11 +71,11 @@ def activate_autoix_bip9(self):
if counter % sync_period == 0:
# sync nodes
self.sync_all()
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)

# sync nodes
self.sync_all()
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)

assert(self.get_autoix_bip9_status() == 'active')

Expand Down
2 changes: 1 addition & 1 deletion qa/rpc-tests/p2p-fullblocktest.py
Expand Up @@ -69,7 +69,7 @@ def run_test(self):
self.test = TestManager(self, self.options.tmpdir)
self.test.add_all_connections(self.nodes)
NetworkThread().start() # Start up network handling in another thread
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)
self.test.run()

def add_transactions_to_block(self, block, tx_list):
Expand Down
4 changes: 2 additions & 2 deletions qa/rpc-tests/test_framework/test_framework.py
Expand Up @@ -301,11 +301,11 @@ def setup_network(self):
self.sync_all()
set_mocktime(get_mocktime() + 1)
set_node_times(self.nodes, get_mocktime())
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)
for i in range(1, self.mn_count + 1):
res = self.nodes[0].masternode("start-alias", "mn%d" % i)
assert (res["result"] == 'successful')
sync_masternodes(self.nodes)
sync_masternodes(self.nodes, True)
mn_info = self.nodes[0].masternodelist("status")
assert (len(mn_info) == self.mn_count)
for status in mn_info.values():
Expand Down
16 changes: 10 additions & 6 deletions qa/rpc-tests/test_framework/util.py
Expand Up @@ -105,11 +105,15 @@ def get_mnsync_status(node):
result = node.mnsync("status")
return result['IsSynced']

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

def p2p_port(n):
assert(n <= MAX_NODES)
Expand Down Expand Up @@ -191,9 +195,9 @@ def sync_mempools(rpc_connections, *, wait=1, timeout=60):
timeout -= wait
raise AssertionError("Mempool sync failed")

def sync_masternodes(rpc_connections):
def sync_masternodes(rpc_connections, fast_mnsync=False):
for node in rpc_connections:
wait_to_sync(node)
wait_to_sync(node, fast_mnsync)

bitcoind_processes = {}

Expand Down

0 comments on commit 8f9b004

Please sign in to comment.