Skip to content

Commit 94f1c52

Browse files
committed
masternodesync: re-format peer version check.
no functional change. Github-Pull: #2659 Rebased-From: fd7d569
1 parent 946444e commit 94f1c52

File tree

1 file changed

+96
-94
lines changed

1 file changed

+96
-94
lines changed

src/masternode-sync.cpp

Lines changed: 96 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -346,127 +346,129 @@ bool CMasternodeSync::SyncWithNode(CNode* pnode, bool fLegacyMnObsolete)
346346
return false;
347347
}
348348

349-
if (pnode->nVersion >= ActiveProtocol()) {
350-
if (RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) {
351-
if (fLegacyMnObsolete) {
352-
SwitchToNextAsset();
353-
return false;
354-
}
349+
if (pnode->nVersion < ActiveProtocol()) {
350+
return true; // move to next peer
351+
}
352+
353+
if (RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) {
354+
if (fLegacyMnObsolete) {
355+
SwitchToNextAsset();
356+
return false;
357+
}
358+
359+
LogPrint(BCLog::MASTERNODE, "CMasternodeSync::Process() - lastMasternodeList %lld (GetTime() - MASTERNODE_SYNC_TIMEOUT) %lld\n", lastMasternodeList, GetTime() - MASTERNODE_SYNC_TIMEOUT);
360+
if (lastMasternodeList > 0 && lastMasternodeList < GetTime() - MASTERNODE_SYNC_TIMEOUT * 8 && RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD) {
361+
// hasn't received a new item in the last 40 seconds AND has sent at least a minimum of MASTERNODE_SYNC_THRESHOLD GETMNLIST requests,
362+
// so we'll move to the next asset.
363+
SwitchToNextAsset();
364+
return false;
365+
}
355366

356-
LogPrint(BCLog::MASTERNODE, "CMasternodeSync::Process() - lastMasternodeList %lld (GetTime() - MASTERNODE_SYNC_TIMEOUT) %lld\n", lastMasternodeList, GetTime() - MASTERNODE_SYNC_TIMEOUT);
357-
if (lastMasternodeList > 0 && lastMasternodeList < GetTime() - MASTERNODE_SYNC_TIMEOUT * 8 && RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD) {
358-
// hasn't received a new item in the last 40 seconds AND has sent at least a minimum of MASTERNODE_SYNC_THRESHOLD GETMNLIST requests,
359-
// so we'll move to the next asset.
367+
// timeout
368+
if (lastMasternodeList == 0 &&
369+
(RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5)) {
370+
if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) {
371+
syncTimeout("MASTERNODE_SYNC_LIST");
372+
} else {
360373
SwitchToNextAsset();
361-
return false;
362374
}
375+
return false;
376+
}
363377

364-
// timeout
365-
if (lastMasternodeList == 0 &&
366-
(RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5)) {
367-
if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) {
368-
syncTimeout("MASTERNODE_SYNC_LIST");
369-
} else {
370-
SwitchToNextAsset();
371-
}
372-
return false;
373-
}
378+
// Don't request mnlist initial sync to more than 8 randomly ordered peers in this round
379+
if (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 4) return false;
374380

375-
// Don't request mnlist initial sync to more than 8 randomly ordered peers in this round
376-
if (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 4) return false;
381+
// Request mnb sync if we haven't requested it yet.
382+
if (pnode->HasFulfilledRequest("mnsync")) return true;
377383

378-
// Request mnb sync if we haven't requested it yet.
379-
if (pnode->HasFulfilledRequest("mnsync")) return true;
384+
// Try to request MN list sync.
385+
if (!mnodeman.RequestMnList(pnode)) {
386+
return true; // Failed, try next peer.
387+
}
380388

381-
// Try to request MN list sync.
382-
if (!mnodeman.RequestMnList(pnode)) {
383-
return true; // Failed, try next peer.
384-
}
389+
// Mark sync requested.
390+
pnode->FulfilledRequest("mnsync");
391+
// Increase the sync attempt count
392+
RequestedMasternodeAttempt++;
385393

386-
// Mark sync requested.
387-
pnode->FulfilledRequest("mnsync");
388-
// Increase the sync attempt count
389-
RequestedMasternodeAttempt++;
394+
return false; // sleep 1 second before do another request round.
395+
}
390396

391-
return false; // sleep 1 second before do another request round.
397+
if (RequestedMasternodeAssets == MASTERNODE_SYNC_MNW) {
398+
if (fLegacyMnObsolete) {
399+
SwitchToNextAsset();
400+
return false;
392401
}
393402

394-
if (RequestedMasternodeAssets == MASTERNODE_SYNC_MNW) {
395-
if (fLegacyMnObsolete) {
396-
SwitchToNextAsset();
397-
return false;
398-
}
403+
if (lastMasternodeWinner > 0 && lastMasternodeWinner < GetTime() - MASTERNODE_SYNC_TIMEOUT * 2 && RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD) { //hasn't received a new item in the last five seconds, so we'll move to the
404+
SwitchToNextAsset();
405+
return false;
406+
}
399407

400-
if (lastMasternodeWinner > 0 && lastMasternodeWinner < GetTime() - MASTERNODE_SYNC_TIMEOUT * 2 && RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD) { //hasn't received a new item in the last five seconds, so we'll move to the
408+
// timeout
409+
if (lastMasternodeWinner == 0 &&
410+
(RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5)) {
411+
if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) {
412+
syncTimeout("MASTERNODE_SYNC_MNW");
413+
} else {
401414
SwitchToNextAsset();
402-
return false;
403-
}
404-
405-
// timeout
406-
if (lastMasternodeWinner == 0 &&
407-
(RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5)) {
408-
if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) {
409-
syncTimeout("MASTERNODE_SYNC_MNW");
410-
} else {
411-
SwitchToNextAsset();
412-
}
413-
return false;
414415
}
416+
return false;
417+
}
415418

416-
// Don't request mnw initial sync to more than 6 randomly ordered peers in this round.
417-
if (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3) return false;
419+
// Don't request mnw initial sync to more than 6 randomly ordered peers in this round.
420+
if (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3) return false;
418421

419-
// Request mnw sync if we haven't requested it yet.
420-
if (pnode->HasFulfilledRequest("mnwsync")) return true;
422+
// Request mnw sync if we haven't requested it yet.
423+
if (pnode->HasFulfilledRequest("mnwsync")) return true;
421424

422-
// Mark sync requested.
423-
pnode->FulfilledRequest("mnwsync");
425+
// Mark sync requested.
426+
pnode->FulfilledRequest("mnwsync");
424427

425-
// Sync mn winners
426-
int nMnCount = mnodeman.CountEnabled(true /* only_legacy */);
427-
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::GETMNWINNERS, nMnCount));
428-
RequestedMasternodeAttempt++;
428+
// Sync mn winners
429+
int nMnCount = mnodeman.CountEnabled(true /* only_legacy */);
430+
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::GETMNWINNERS, nMnCount));
431+
RequestedMasternodeAttempt++;
429432

430-
return false; // sleep 1 second before do another request round.
431-
}
433+
return false; // sleep 1 second before do another request round.
434+
}
432435

433-
if (RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET) {
434-
// We'll start rejecting votes if we accidentally get set as synced too soon
435-
if (lastBudgetItem > 0 && lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT * 10 && RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD) {
436-
// Hasn't received a new item in the last fifty seconds and more than MASTERNODE_SYNC_THRESHOLD requests were sent,
437-
// so we'll move to the next asset
438-
SwitchToNextAsset();
436+
if (RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET) {
437+
// We'll start rejecting votes if we accidentally get set as synced too soon
438+
if (lastBudgetItem > 0 && lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT * 10 && RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD) {
439+
// Hasn't received a new item in the last fifty seconds and more than MASTERNODE_SYNC_THRESHOLD requests were sent,
440+
// so we'll move to the next asset
441+
SwitchToNextAsset();
439442

440-
// Try to activate our masternode if possible
441-
activeMasternode.ManageStatus();
442-
return false;
443-
}
443+
// Try to activate our masternode if possible
444+
activeMasternode.ManageStatus();
445+
return false;
446+
}
444447

445-
// timeout
446-
if (lastBudgetItem == 0 &&
447-
(RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5)) {
448-
// maybe there is no budgets at all, so just finish syncing
449-
SwitchToNextAsset();
450-
activeMasternode.ManageStatus();
451-
return false;
452-
}
448+
// timeout
449+
if (lastBudgetItem == 0 &&
450+
(RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5)) {
451+
// maybe there is no budgets at all, so just finish syncing
452+
SwitchToNextAsset();
453+
activeMasternode.ManageStatus();
454+
return false;
455+
}
453456

454-
// Don't request budget initial sync to more than 6 randomly ordered peers in this round.
455-
if (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3) return false;
457+
// Don't request budget initial sync to more than 6 randomly ordered peers in this round.
458+
if (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3) return false;
456459

457-
// Request bud sync if we haven't requested it yet.
458-
if (pnode->HasFulfilledRequest("busync")) return true;
460+
// Request bud sync if we haven't requested it yet.
461+
if (pnode->HasFulfilledRequest("busync")) return true;
459462

460-
// Mark sync requested.
461-
pnode->FulfilledRequest("busync");
463+
// Mark sync requested.
464+
pnode->FulfilledRequest("busync");
462465

463-
// Sync proposals, finalizations and votes
464-
uint256 n;
465-
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::BUDGETVOTESYNC, n));
466-
RequestedMasternodeAttempt++;
466+
// Sync proposals, finalizations and votes
467+
uint256 n;
468+
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::BUDGETVOTESYNC, n));
469+
RequestedMasternodeAttempt++;
467470

468-
return false; // sleep 1 second before do another request round.
469-
}
471+
return false; // sleep 1 second before do another request round.
470472
}
471473

472474
return true;

0 commit comments

Comments
 (0)