@@ -1110,6 +1110,7 @@ def get_mn_status(self, node, mnTxHash):
11101110 mnData = node .listmasternodes (mnTxHash )
11111111 if len (mnData ) == 0 :
11121112 return ""
1113+ assert_equal (len (mnData ), 1 )
11131114 return mnData [0 ]["status" ]
11141115
11151116
@@ -1119,36 +1120,56 @@ def advance_mocktime(self, secs):
11191120 time .sleep (1 )
11201121
11211122
1122- def wait_until_mnsync_finished (self , _timeout ):
1123- for i in range (self .num_nodes ):
1124- try :
1125- wait_until (lambda : self .nodes [i ].mnsync ("status" )["RequestedMasternodeAssets" ] == 999 ,
1126- timeout = _timeout , mocktime = self .advance_mocktime )
1127- except AssertionError :
1128- raise AssertionError ("Unable to complete mnsync on node %d" % i )
1123+ def wait_until_mnsync_finished (self ):
1124+ SYNC_FINISHED = [999 ] * self .num_nodes
1125+ synced = [- 1 ] * self .num_nodes
1126+ time .sleep (2 )
1127+ timeout = time .time () + 300
1128+ while synced != SYNC_FINISHED and time .time () < timeout :
1129+ for i in range (self .num_nodes ):
1130+ if synced [i ] != SYNC_FINISHED [i ]:
1131+ synced [i ] = self .nodes [i ].mnsync ("status" )["RequestedMasternodeAssets" ]
1132+ if synced != SYNC_FINISHED :
1133+ time .sleep (5 )
1134+ if synced != SYNC_FINISHED :
1135+ raise AssertionError ("Unable to complete mnsync: %s" % str (synced ))
11291136
11301137
11311138 def wait_until_mn_status (self , status , mnTxHash , _timeout , orEmpty = False , with_ping_mns = []):
1132- def _sendpings ():
1133- if len (with_ping_mns ) == 0 :
1134- return
1135- else :
1136- self .send_pings (with_ping_mns )
1139+ nodes_status = [None ] * self .num_nodes
11371140
1138- for i in range (self .num_nodes ):
1139- try :
1140- wait_until (lambda : (self .get_mn_status (self .nodes [i ], mnTxHash ) == status or
1141- (orEmpty and self .get_mn_status (self .nodes [i ], mnTxHash ) == "" )),
1142- timeout = _timeout , sendpings = _sendpings , mocktime = self .advance_mocktime )
1143- except AssertionError :
1144- strErr = "Unable to get status \" %s\" on node %d for mnode %s" % (status , i , mnTxHash )
1145- raise AssertionError (strErr )
1141+ def node_synced (i ):
1142+ return nodes_status [i ] == status or (orEmpty and nodes_status [i ] == "" )
1143+
1144+ def all_synced ():
1145+ for i in range (self .num_nodes ):
1146+ if not node_synced (i ):
1147+ return False
1148+ return True
1149+
1150+ time .sleep (2 )
1151+ timeout = time .time () + _timeout
1152+ while not all_synced () and time .time () < timeout :
1153+ for i in range (self .num_nodes ):
1154+ if not node_synced (i ):
1155+ nodes_status [i ] = self .get_mn_status (self .nodes [i ], mnTxHash )
1156+ if not all_synced ():
1157+ time .sleep (2 )
1158+ self .send_pings (with_ping_mns )
1159+ if not all_synced ():
1160+ strErr = "Unable to get get status \" %s\" on all nodes for mnode %s. Current: %s" % (
1161+ status , mnTxHash , str (nodes_status ))
1162+ raise AssertionError (strErr )
11461163
11471164
11481165 def wait_until_mn_enabled (self , mnTxHash , _timeout , _with_ping_mns = []):
11491166 self .wait_until_mn_status ("ENABLED" , mnTxHash , _timeout , with_ping_mns = _with_ping_mns )
11501167
11511168
1169+ def wait_until_mn_preenabled (self , mnTxHash , _timeout , _with_ping_mns = []):
1170+ self .wait_until_mn_status ("PRE_ENABLED" , mnTxHash , _timeout , with_ping_mns = _with_ping_mns )
1171+
1172+
11521173 def wait_until_mn_vinspent (self , mnTxHash , _timeout , _with_ping_mns = []):
11531174 self .wait_until_mn_status ("VIN_SPENT" , mnTxHash , _timeout , orEmpty = True , with_ping_mns = _with_ping_mns )
11541175
@@ -1205,7 +1226,7 @@ def setupMasternode(self,
12051226 assert_equal (mnCollateralOutput ["txhash" ], collateralTxId )
12061227 mnCollateralOutputIndex = mnCollateralOutput ["outputidx" ]
12071228
1208- self .log .info ("collateral accepted for " + masternodeAlias + ".. updating masternode.conf and stopping the node " )
1229+ self .log .info ("collateral accepted for " + masternodeAlias + ". Updating masternode.conf... " )
12091230
12101231 # verify collateral confirmed
12111232 confData = masternodeAlias + " 127.0.0.1:" + str (p2p_port (mnRemotePos )) + " " + str (masternodePrivKey ) + " " + str (mnCollateralOutput ["txhash" ]) + " " + str (mnCollateralOutputIndex )
@@ -1269,7 +1290,6 @@ def set_test_params(self):
12691290 [],
12701291 ["-listen" , "-externalip=127.0.0.1" ],
12711292 ["-sporkkey=932HEevBSujW2ud7RfB1YF91AFygbBRQj3de3LyaCRqNzKKgWXi" ]]
1272- self .setup_clean_chain = True
12731293 self .enable_mocktime ()
12741294
12751295 self .ownerOnePos = 0
@@ -1293,6 +1313,7 @@ def set_test_params(self):
12931313 self .mnOneTxHash = ""
12941314 self .mnTwoTxHash = ""
12951315
1316+
12961317 def send_3_pings (self ):
12971318 self .advance_mocktime (30 )
12981319 self .send_pings ([self .remoteOne , self .remoteTwo ])
@@ -1307,10 +1328,12 @@ def stake(self, num_blocks, with_ping_mns=[]):
13071328 def controller_start_all_masternodes (self ):
13081329 self .controller_start_masternode (self .ownerOne , self .masternodeOneAlias )
13091330 self .controller_start_masternode (self .ownerTwo , self .masternodeTwoAlias )
1331+ self .wait_until_mn_preenabled (self .mnOneTxHash , 40 )
1332+ self .wait_until_mn_preenabled (self .mnTwoTxHash , 40 )
13101333 self .log .info ("masternodes started, waiting until both get enabled.." )
13111334 self .send_3_pings ()
1312- self .wait_until_mn_enabled (self .mnOneTxHash , 60 , [self .remoteOne , self .remoteTwo ])
1313- self .wait_until_mn_enabled (self .mnTwoTxHash , 60 , [self .remoteOne , self .remoteTwo ])
1335+ self .wait_until_mn_enabled (self .mnOneTxHash , 120 , [self .remoteOne , self .remoteTwo ])
1336+ self .wait_until_mn_enabled (self .mnTwoTxHash , 120 , [self .remoteOne , self .remoteTwo ])
13141337 self .log .info ("masternodes enabled and running properly!" )
13151338
13161339 def advance_mocktime_and_stake (self , secs_to_add ):
@@ -1361,12 +1384,10 @@ def setup_2_masternodes_network(self):
13611384 remoteTwoPort = p2p_port (self .remoteOnePos )
13621385 self .remoteOne .initmasternode (self .mnOnePrivkey , "127.0.0.1:" + str (remoteOnePort ))
13631386 self .remoteTwo .initmasternode (self .mnTwoPrivkey , "127.0.0.1:" + str (remoteTwoPort ))
1364- self .advance_mocktime (3 )
13651387
13661388 # wait until mnsync complete on all nodes
13671389 self .stake (1 )
1368- time .sleep (20 )
1369- self .wait_until_mnsync_finished (35 )
1390+ self .wait_until_mnsync_finished ()
13701391 self .log .info ("tier two synced! starting masternodes.." )
13711392
13721393 # Now everything is set, can start both masternodes
0 commit comments