From 86c869137f66a0d2bb6eaca8cd92ae2f53a3b551 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Sun, 19 Jul 2015 02:25:52 +0300 Subject: [PATCH] fixes for sync --- src/masternode-sync.cpp | 57 ++++++++++++++++++++++++----------------- src/masternode.cpp | 1 + src/masternodeman.cpp | 4 --- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 2507a72b1..5d66ef4cf 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -47,6 +47,9 @@ void CMasternodeSync::GetNextAsset() switch(RequestedMasternodeAssets) { case(MASTERNODE_SYNC_INITIAL): + lastMasternodeList = 0; + lastMasternodeWinner = 0; + lastBudgetItem = 0; RequestedMasternodeAssets = MASTERNODE_SYNC_SPORKS; break; case(MASTERNODE_SYNC_SPORKS): @@ -76,7 +79,7 @@ void CMasternodeSync::Process() */ if(mnodeman.CountEnabled() == 0) { RequestedMasternodeAssets = MASTERNODE_SYNC_INITIAL; - RequestedMasternodeAttempt = 0; + GetNextAsset(); } return; } @@ -85,7 +88,6 @@ void CMasternodeSync::Process() if(fDebug) LogPrintf("CMasternodeSync::Process() - RequestedMasternodeAssets %d c %d\n", RequestedMasternodeAssets, c); - //request full mn list only if Masternodes.dat was updated quite a long time ago if(RequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) GetNextAsset(); CBlockIndex* pindexPrev = chainActive.Tip(); @@ -94,31 +96,33 @@ void CMasternodeSync::Process() LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) { - if (pnode->nVersion >= MIN_POOL_PEER_PROTO_VERSION) - { - //set to syned - if(Params().NetworkID() == CBaseChainParams::REGTEST && c >= 10) { - LogPrintf("CMasternodeSync::Process - Sync has finished\n"); - RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED; - RequestedMasternodeAttempt = 0; + + //set to synced + if(Params().NetworkID() == CBaseChainParams::REGTEST && c >= 10) { + LogPrintf("CMasternodeSync::Process - Sync has finished\n"); + RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED; + RequestedMasternodeAttempt = 0; + } + + if(RequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS){ + if(pnode->HasFulfilledRequest("getspork")) continue; + pnode->FulfilledRequest("getspork"); + + if(RequestedMasternodeAttempt <= 2){ + pnode->PushMessage("getsporks"); //get current network sporks + if(RequestedMasternodeAttempt == 2) GetNextAsset(); + RequestedMasternodeAttempt++; } + return; + } - if(RequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS){ - if(pnode->HasFulfilledRequest("getspork")) continue; - pnode->FulfilledRequest("getspork"); + //don't begin syncing until we're at a recent block + if(pindexPrev->nHeight < pindexBestHeader->nHeight) return; - if(RequestedMasternodeAttempt <= 2){ - pnode->PushMessage("getsporks"); //get current network sporks - if(RequestedMasternodeAttempt == 2) GetNextAsset(); - RequestedMasternodeAttempt++; - } - return; - } + if (pnode->nVersion >= nMasternodeMinProtocol) { - //don't begin syncing until we're at a recent block - if(pindexPrev->nTime + 600 < GetTime()) return; - - if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST){ + if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) { + if(fDebug) LogPrintf("CMasternodeSync::Process() - lastMasternodeList %lld (GetTime() - MASTERNODE_SYNC_TIMEOUT) %lld\n", lastMasternodeList, GetTime() - MASTERNODE_SYNC_TIMEOUT); if(lastMasternodeList > 0 && lastMasternodeList < GetTime() - MASTERNODE_SYNC_TIMEOUT){ //hasn't received a new item in the last five seconds, so we'll move to the GetNextAsset(); return; @@ -134,8 +138,10 @@ void CMasternodeSync::Process() } return; } + } - if(RequestedMasternodeAssets == MASTERNODE_SYNC_MNW){ + if (pnode->nVersion >= masternodePayments.GetMinMasternodePaymentsProto()) { + if(RequestedMasternodeAssets == MASTERNODE_SYNC_MNW) { if(lastMasternodeWinner > 0 && lastMasternodeWinner < GetTime() - MASTERNODE_SYNC_TIMEOUT){ //hasn't received a new item in the last five seconds, so we'll move to the GetNextAsset(); return; @@ -151,6 +157,9 @@ void CMasternodeSync::Process() } return; } + } + + if (pnode->nVersion >= MIN_BUDGET_PEER_PROTO_VERSION) { if(RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET){ if(lastBudgetItem > 0 && lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT){ //hasn't received a new item in the last five seconds, so we'll move to the diff --git a/src/masternode.cpp b/src/masternode.cpp index 279ecbeb4..ed49a8005 100644 --- a/src/masternode.cpp +++ b/src/masternode.cpp @@ -355,6 +355,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos) pmn->UpdateFromNewBroadcast((*this)); pmn->Check(); if(pmn->IsEnabled()) Relay(); + masternodeSync.AddedMasternodeList(); } return true; diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 6bf28ca10..932e54ba2 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -618,10 +618,6 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData return; } - // only ask for missing items after our syncing process is complete -- - // otherwise we'll think a full sync succeeded when they return a result - if(!masternodeSync.IsSynced()) return; - //search existing Masternode list, if it's known -- don't ask for the mnb CMasternode* pmn = mnodeman.Find(mnp.vin); if(pmn != NULL) return;