@@ -106,12 +106,17 @@ void CActiveMasternode::ManageStatus()
106106 return ;
107107 }
108108
109- if (!Register (vin, service, keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, errorMessage)) {
109+ CMasternodeBroadcast mnb;
110+ if (!CreateBroadcast (vin, service, keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, errorMessage, mnb)) {
110111 notCapableReason = " Error on Register: " + errorMessage;
111- LogPrintf (" Register ::ManageStatus() - %s\n " , notCapableReason);
112+ LogPrintf (" CActiveMasternode ::ManageStatus() - %s\n " , notCapableReason);
112113 return ;
113114 }
114115
116+ // send to all peers
117+ LogPrintf (" CActiveMasternode::ManageStatus() - Relay broadcast vin = %s\n " , vin.ToString ());
118+ mnb.Relay ();
119+
115120 LogPrintf (" CActiveMasternode::ManageStatus() - Is capable master node!\n " );
116121 status = ACTIVE_MASTERNODE_STARTED;
117122
@@ -230,7 +235,7 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage)
230235 }
231236}
232237
233- bool CActiveMasternode::Register (std::string strService, std::string strKeyMasternode, std::string strTxHash, std::string strOutputIndex, std::string& errorMessage)
238+ bool CActiveMasternode::CreateBroadcast (std::string strService, std::string strKeyMasternode, std::string strTxHash, std::string strOutputIndex, std::string& errorMessage, CMasternodeBroadcast &mnb, bool fOffline )
234239{
235240 CTxIn vin;
236241 CPubKey pubKeyCollateralAddress;
@@ -239,68 +244,56 @@ bool CActiveMasternode::Register(std::string strService, std::string strKeyMaste
239244 CKey keyMasternode;
240245
241246 // need correct blocks to send ping
242- if (!masternodeSync.IsBlockchainSynced ()) {
243- errorMessage = GetStatus () ;
244- LogPrintf (" CActiveMasternode::Register () - %s\n " , errorMessage);
247+ if (!fOffline && ! masternodeSync.IsBlockchainSynced ()) {
248+ errorMessage = " Sync in progress. Must wait until sync is complete to start Masternode " ;
249+ LogPrintf (" CActiveMasternode::CreateBroadcast () - %s\n " , errorMessage);
245250 return false ;
246251 }
247252
248253 if (!obfuScationSigner.SetKey (strKeyMasternode, errorMessage, keyMasternode, pubKeyMasternode)) {
249254 errorMessage = strprintf (" Can't find keys for masternode %s - %s" , strService, errorMessage);
250- LogPrintf (" CActiveMasternode::Register () - %s\n " , errorMessage);
255+ LogPrintf (" CActiveMasternode::CreateBroadcast () - %s\n " , errorMessage);
251256 return false ;
252257 }
253258
254259 if (!GetMasterNodeVin (vin, pubKeyCollateralAddress, keyCollateralAddress, strTxHash, strOutputIndex)) {
255260 errorMessage = strprintf (" Could not allocate vin %s:%s for masternode %s" , strTxHash, strOutputIndex, strService);
256- LogPrintf (" CActiveMasternode::Register () - %s\n " , errorMessage);
261+ LogPrintf (" CActiveMasternode::CreateBroadcast () - %s\n " , errorMessage);
257262 return false ;
258263 }
259264
260265 CService service = CService (strService);
261266
262267 // The service needs the correct default port to work properly
263- if (!CMasternodeBroadcast::CheckDefaultPort (strService, errorMessage, " CActiveMasternode::Register ()" ))
268+ if (!CMasternodeBroadcast::CheckDefaultPort (strService, errorMessage, " CActiveMasternode::CreateBroadcast ()" ))
264269 return false ;
265270
266271 addrman.Add (CAddress (service), CNetAddr (" 127.0.0.1" ), 2 * 60 * 60 );
267272
268- return Register (vin, CService (strService), keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, errorMessage);
273+ return CreateBroadcast (vin, CService (strService), keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, errorMessage, mnb );
269274}
270275
271- bool CActiveMasternode::Register (CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, std::string& errorMessage)
276+ bool CActiveMasternode::CreateBroadcast (CTxIn vin, CService service, CKey keyCollateralAddress, CPubKey pubKeyCollateralAddress, CKey keyMasternode, CPubKey pubKeyMasternode, std::string& errorMessage, CMasternodeBroadcast &mnb )
272277{
273- CMasternodeBroadcast mnb;
278+ // wait for reindex and/or import to finish
279+ if (fImporting || fReindex ) return false ;
280+
274281 CMasternodePing mnp (vin);
275282 if (!mnp.Sign (keyMasternode, pubKeyMasternode)) {
276283 errorMessage = strprintf (" Failed to sign ping, vin: %s" , vin.ToString ());
277- LogPrintf (" CActiveMasternode::Register() - %s\n " , errorMessage);
284+ LogPrintf (" CActiveMasternode::CreateBroadcast() - %s\n " , errorMessage);
285+ mnb = CMasternodeBroadcast ();
278286 return false ;
279287 }
280- mnodeman.mapSeenMasternodePing .insert (make_pair (mnp.GetHash (), mnp));
281288
282- LogPrintf (" CActiveMasternode::Register() - Adding to Masternode list\n service: %s\n vin: %s\n " , service.ToString (), vin.ToString ());
283289 mnb = CMasternodeBroadcast (service, vin, pubKeyCollateralAddress, pubKeyMasternode, PROTOCOL_VERSION);
284290 mnb.lastPing = mnp;
285291 if (!mnb.Sign (keyCollateralAddress)) {
286292 errorMessage = strprintf (" Failed to sign broadcast, vin: %s" , vin.ToString ());
287- LogPrintf (" CActiveMasternode::Register() - %s\n " , errorMessage);
293+ LogPrintf (" CActiveMasternode::CreateBroadcast() - %s\n " , errorMessage);
294+ mnb = CMasternodeBroadcast ();
288295 return false ;
289296 }
290- mnodeman.mapSeenMasternodeBroadcast .insert (make_pair (mnb.GetHash (), mnb));
291- masternodeSync.AddedMasternodeList (mnb.GetHash ());
292-
293- CMasternode* pmn = mnodeman.Find (vin);
294- if (pmn == NULL ) {
295- CMasternode mn (mnb);
296- mnodeman.Add (mn);
297- } else {
298- pmn->UpdateFromNewBroadcast (mnb);
299- }
300-
301- // send to all peers
302- LogPrintf (" CActiveMasternode::Register() - RelayElectionEntry vin = %s\n " , vin.ToString ());
303- mnb.Relay ();
304297
305298 /*
306299 * IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS
@@ -350,6 +343,9 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr
350343
351344bool CActiveMasternode::GetMasterNodeVin (CTxIn& vin, CPubKey& pubkey, CKey& secretKey, std::string strTxHash, std::string strOutputIndex)
352345{
346+ // wait for reindex and/or import to finish
347+ if (fImporting || fReindex ) return false ;
348+
353349 // Find possible candidates
354350 TRY_LOCK (pwalletMain->cs_wallet , fWallet );
355351 if (!fWallet ) return false ;
@@ -399,6 +395,9 @@ bool CActiveMasternode::GetMasterNodeVin(CTxIn& vin, CPubKey& pubkey, CKey& secr
399395// Extract Masternode vin information from output
400396bool CActiveMasternode::GetVinFromOutput (COutput out, CTxIn& vin, CPubKey& pubkey, CKey& secretKey)
401397{
398+ // wait for reindex and/or import to finish
399+ if (fImporting || fReindex ) return false ;
400+
402401 CScript pubScript;
403402
404403 vin = CTxIn (out.tx ->GetHash (), out.i );
0 commit comments