fixes for sync

This commit is contained in:
UdjinM6 2015-07-19 02:25:52 +03:00
parent dba572ac96
commit 86c869137f
3 changed files with 34 additions and 28 deletions

View File

@ -47,6 +47,9 @@ void CMasternodeSync::GetNextAsset()
switch(RequestedMasternodeAssets) switch(RequestedMasternodeAssets)
{ {
case(MASTERNODE_SYNC_INITIAL): case(MASTERNODE_SYNC_INITIAL):
lastMasternodeList = 0;
lastMasternodeWinner = 0;
lastBudgetItem = 0;
RequestedMasternodeAssets = MASTERNODE_SYNC_SPORKS; RequestedMasternodeAssets = MASTERNODE_SYNC_SPORKS;
break; break;
case(MASTERNODE_SYNC_SPORKS): case(MASTERNODE_SYNC_SPORKS):
@ -76,7 +79,7 @@ void CMasternodeSync::Process()
*/ */
if(mnodeman.CountEnabled() == 0) { if(mnodeman.CountEnabled() == 0) {
RequestedMasternodeAssets = MASTERNODE_SYNC_INITIAL; RequestedMasternodeAssets = MASTERNODE_SYNC_INITIAL;
RequestedMasternodeAttempt = 0; GetNextAsset();
} }
return; return;
} }
@ -85,7 +88,6 @@ void CMasternodeSync::Process()
if(fDebug) LogPrintf("CMasternodeSync::Process() - RequestedMasternodeAssets %d c %d\n", RequestedMasternodeAssets, c); 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(); if(RequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) GetNextAsset();
CBlockIndex* pindexPrev = chainActive.Tip(); CBlockIndex* pindexPrev = chainActive.Tip();
@ -94,31 +96,33 @@ void CMasternodeSync::Process()
LOCK(cs_vNodes); LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes) BOOST_FOREACH(CNode* pnode, vNodes)
{ {
if (pnode->nVersion >= MIN_POOL_PEER_PROTO_VERSION)
{ //set to synced
//set to syned if(Params().NetworkID() == CBaseChainParams::REGTEST && c >= 10) {
if(Params().NetworkID() == CBaseChainParams::REGTEST && c >= 10) { LogPrintf("CMasternodeSync::Process - Sync has finished\n");
LogPrintf("CMasternodeSync::Process - Sync has finished\n"); RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED;
RequestedMasternodeAssets = MASTERNODE_SYNC_FINISHED; RequestedMasternodeAttempt = 0;
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){ //don't begin syncing until we're at a recent block
if(pnode->HasFulfilledRequest("getspork")) continue; if(pindexPrev->nHeight < pindexBestHeader->nHeight) return;
pnode->FulfilledRequest("getspork");
if(RequestedMasternodeAttempt <= 2){ if (pnode->nVersion >= nMasternodeMinProtocol) {
pnode->PushMessage("getsporks"); //get current network sporks
if(RequestedMasternodeAttempt == 2) GetNextAsset();
RequestedMasternodeAttempt++;
}
return;
}
//don't begin syncing until we're at a recent block if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) {
if(pindexPrev->nTime + 600 < GetTime()) return; if(fDebug) LogPrintf("CMasternodeSync::Process() - lastMasternodeList %lld (GetTime() - MASTERNODE_SYNC_TIMEOUT) %lld\n", lastMasternodeList, GetTime() - MASTERNODE_SYNC_TIMEOUT);
if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST){
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 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(); GetNextAsset();
return; return;
@ -134,8 +138,10 @@ void CMasternodeSync::Process()
} }
return; 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 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(); GetNextAsset();
return; return;
@ -151,6 +157,9 @@ void CMasternodeSync::Process()
} }
return; return;
} }
}
if (pnode->nVersion >= MIN_BUDGET_PEER_PROTO_VERSION) {
if(RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET){ 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 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

View File

@ -355,6 +355,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
pmn->UpdateFromNewBroadcast((*this)); pmn->UpdateFromNewBroadcast((*this));
pmn->Check(); pmn->Check();
if(pmn->IsEnabled()) Relay(); if(pmn->IsEnabled()) Relay();
masternodeSync.AddedMasternodeList();
} }
return true; return true;

View File

@ -618,10 +618,6 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
return; 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 //search existing Masternode list, if it's known -- don't ask for the mnb
CMasternode* pmn = mnodeman.Find(mnp.vin); CMasternode* pmn = mnodeman.Find(mnp.vin);
if(pmn != NULL) return; if(pmn != NULL) return;