Skip to content

Commit e0c5624

Browse files
authored
Fixes and refactorings related to using mnsync in tests (#3136)
* 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`
1 parent eb87ad2 commit e0c5624

File tree

6 files changed

+13
-49
lines changed

6 files changed

+13
-49
lines changed

test/functional/dip3-deterministicmns.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,12 @@ def start_mn(self, mn):
243243
self.add_nodes(1)
244244
extra_args = ['-masternode=1', '-masternodeblsprivkey=%s' % mn.blsMnkey]
245245
self.start_node(mn.idx, extra_args = self.extra_args + extra_args)
246+
force_finish_mnsync(self.nodes[mn.idx])
246247
for i in range(0, len(self.nodes)):
247248
if i < len(self.nodes) and self.nodes[i] is not None and self.nodes[i].process is not None and i != mn.idx:
248249
connect_nodes_bi(self.nodes, mn.idx, i)
249250
mn.node = self.nodes[mn.idx]
250251
self.sync_all()
251-
self.force_finish_mnsync(mn.node)
252252

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

279-
def force_finish_mnsync(self, node):
280-
while True:
281-
s = node.mnsync('next')
282-
if s == 'sync updated to MASTERNODE_SYNC_FINISHED':
283-
break
284-
time.sleep(0.1)
285-
286-
def force_finish_mnsync_list(self, node):
287-
if node.mnsync('status')['AssetName'] == 'MASTERNODE_SYNC_WAITING':
288-
node.mnsync('next')
289-
290-
while True:
291-
mnlist = node.masternode('list', 'status')
292-
if len(mnlist) != 0:
293-
time.sleep(0.5)
294-
self.force_finish_mnsync(node)
295-
return
296-
time.sleep(0.1)
297-
298279
def assert_mnlists(self, mns):
299280
for node in self.nodes:
300281
self.assert_mnlist(node, mns)

test/functional/invalidblockrequest.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from test_framework.blocktools import create_block, create_coinbase, create_transaction, network_thread_start
1616
from test_framework.mininode import P2PDataStore, COIN
1717
from test_framework.test_framework import BitcoinTestFramework
18-
from test_framework.util import assert_equal, sync_masternodes
18+
from test_framework.util import assert_equal
1919

2020

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

3232
network_thread_start()
33-
sync_masternodes(self.nodes, True)
3433
node.p2p.wait_for_verack()
3534

3635
best_block = node.getblock(node.getbestblockhash())

test/functional/p2p-fullblocktest.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ def run_test(self):
7171
self.test = TestManager(self, self.options.tmpdir)
7272
self.test.add_all_connections(self.nodes)
7373
network_thread_start()
74-
sync_masternodes(self.nodes, True)
7574
self.test.run()
7675

7776
def add_transactions_to_block(self, block, tx_list):

test/functional/sporks.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ def run_test(self):
6363
assert(self.get_test_spork_state(self.nodes[0]))
6464
assert(self.get_test_spork_state(self.nodes[1]))
6565

66-
# Force finish mnsync node as otherwise it will never send out headers to other peers
67-
wait_to_sync(self.nodes[1], fast_mnsync=True)
68-
6966
# Generate one block to kick off masternode sync, which also starts sporks syncing for node2
7067
self.nodes[1].generate(1)
7168

test/functional/test_framework/test_framework.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,14 @@
3030
connect_nodes,
3131
copy_datadir,
3232
disconnect_nodes,
33+
force_finish_mnsync,
3334
initialize_datadir,
3435
log_filename,
3536
p2p_port,
3637
set_node_times,
3738
satoshi_round,
3839
sync_blocks,
3940
sync_mempools,
40-
sync_masternodes,
41-
wait_to_sync,
4241
wait_until,
4342
)
4443

@@ -580,7 +579,7 @@ def do_start(idx):
580579
self.start_node(idx + start_idx, extra_args=args)
581580
self.mninfo[idx].nodeIdx = idx + start_idx
582581
self.mninfo[idx].node = self.nodes[idx + start_idx]
583-
wait_to_sync(self.mninfo[idx].node, True)
582+
force_finish_mnsync(self.mninfo[idx].node)
584583

585584
def do_connect(idx):
586585
for i in range(0, idx + 1):
@@ -606,8 +605,6 @@ def do_connect(idx):
606605
job.result()
607606
jobs.clear()
608607

609-
sync_masternodes(self.nodes, True)
610-
611608
executor.shutdown()
612609

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

629625
self.log.info("Activating DIP3")
630626
if not self.fast_dip3_enforcement:

test/functional/test_framework/util.py

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -263,20 +263,6 @@ def get_rpc_proxy(url, node_number, timeout=None, coveragedir=None):
263263

264264
return coverage.AuthServiceProxyWrapper(proxy, coverage_logfile)
265265

266-
def get_mnsync_status(node):
267-
result = node.mnsync("status")
268-
return result['IsSynced']
269-
270-
def wait_to_sync(node, fast_mnsync=False):
271-
while True:
272-
synced = get_mnsync_status(node)
273-
if synced:
274-
break
275-
time.sleep(0.2)
276-
if fast_mnsync:
277-
# skip mnsync states
278-
node.mnsync("next")
279-
280266
def p2p_port(n):
281267
assert(n <= MAX_NODES)
282268
return PORT_MIN + n + (MAX_NODES * PortSeed.n) % (PORT_RANGE - 1 - MAX_NODES)
@@ -449,9 +435,15 @@ def sync_mempools(rpc_connections, *, wait=1, timeout=60):
449435
timeout -= wait
450436
raise AssertionError("Mempool sync failed")
451437

452-
def sync_masternodes(rpc_connections, fast_mnsync=False):
453-
for node in rpc_connections:
454-
wait_to_sync(node, fast_mnsync)
438+
def force_finish_mnsync(node):
439+
"""
440+
Masternodes won't accept incoming connections while IsSynced is false.
441+
Force them to switch to this state to speed things up.
442+
"""
443+
while True:
444+
if node.mnsync("status")['IsSynced']:
445+
break
446+
node.mnsync("next")
455447

456448
# Transaction/Block functions
457449
#############################

0 commit comments

Comments
 (0)