diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 701111ee3861c..5c709c6a5e7ee 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -124,19 +124,18 @@ void CMasternodeSync::GetNextAsset() case(MASTERNODE_SYNC_INITIAL): case(MASTERNODE_SYNC_FAILED): // should never be used here actually, use Reset() instead ClearFulfilledRequest(); - //printf("MASTERNODE_SYNC_SPORKS\n"); RequestedMasternodeAssets = MASTERNODE_SYNC_SPORKS; break; case(MASTERNODE_SYNC_SPORKS): - //printf("MASTERNODE_SYNC_LIST\n"); + lastMasternodeList = GetTime(); RequestedMasternodeAssets = MASTERNODE_SYNC_LIST; break; case(MASTERNODE_SYNC_LIST): - //printf("MASTERNODE_SYNC_MNW\n"); + lastMasternodeWinner = GetTime(); RequestedMasternodeAssets = MASTERNODE_SYNC_MNW; break; case(MASTERNODE_SYNC_MNW): - //printf("MASTERNODE_SYNC_BUDGET\n"); + lastBudgetItem = GetTime(); RequestedMasternodeAssets = MASTERNODE_SYNC_BUDGET; break; case(MASTERNODE_SYNC_BUDGET): @@ -231,7 +230,7 @@ void CMasternodeSync::Process() /* Resync if we lose all masternodes from sleep/wake or failure to sync originally */ - if(mnodeman.CountEnabled() == 0) { + if(nMnCount == 0) { Reset(); } else return; @@ -257,14 +256,9 @@ void CMasternodeSync::Process() if(Params().NetworkIDString() != CBaseChainParams::REGTEST && !IsBlockchainSynced() && RequestedMasternodeAssets > MASTERNODE_SYNC_SPORKS) return; - - //printf("CMasternodeSync::Process() TICK2 - %d %d \n", tick, RequestedMasternodeAssets); - TRY_LOCK(cs_vNodes, lockRecv); if(!lockRecv) return; - //printf("CMasternodeSync::Process() TICK3 - %d %d \n", tick, RequestedMasternodeAssets); - BOOST_FOREACH(CNode* pnode, vNodes) { /* @@ -292,33 +286,27 @@ void CMasternodeSync::Process() */ // ALWAYS ASK FOR SPORKS AS WE SYNC (we skip this mode now) + if(!pnode->HasFulfilledRequest("getspork")) { - if(!pnode->HasFulfilledRequest("getspork")) - { - pnode->FulfilledRequest("getspork"); - pnode->PushMessage(NetMsgType::GETSPORKS); //get current network sporks - } + pnode->FulfilledRequest("getspork"); + pnode->PushMessage(NetMsgType::GETSPORKS); //get current network sporks + } - //we always ask for sporks, so just skip this - if(RequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS){ - GetNextAsset(); - return; - } + //we always ask for sporks, so just skip this + if(RequestedMasternodeAssets == MASTERNODE_SYNC_SPORKS){ + GetNextAsset(); + return; } if (pnode->nVersion >= mnpayments.GetMinMasternodePaymentsProto()) { // MODE : MASTERNODE_SYNC_LIST if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) { - //printf("MASTERNODE_SYNC_LIST Timeout at %d\n", lastMasternodeList < GetTime() - MASTERNODE_SYNC_TIMEOUT); // shall we move onto the next asset? - - //printf("Masternode count %d est %d\n", nMnCount, mnodeman.GetEstimatedMasternodes(pCurrentBlockIndex->nHeight)); if(nMnCount > mnodeman.GetEstimatedMasternodes(pCurrentBlockIndex->nHeight)*0.9) { GetNextAsset(); - //printf("synced masternode list successfully\n"); return; } @@ -343,7 +331,6 @@ void CMasternodeSync::Process() // MODE : MASTERNODE_SYNC_MNW if(RequestedMasternodeAssets == MASTERNODE_SYNC_MNW) { - //printf("MASTERNODE_SYNC_MNW Timeout at %d\n", lastMasternodeWinner < GetTime() - MASTERNODE_SYNC_TIMEOUT); // Shall we move onto the next asset? // -- @@ -353,16 +340,13 @@ void CMasternodeSync::Process() return; } - //printf("MASTERNODE_SYNC_MNW BlockCount %d, mnCount %d\n", mnpayments.GetBlockCount(), nMnCount); - // target blocks count - if(mnpayments.GetBlockCount() > nMnCount) + // we store nMnCount*1.25 payments blocks so nMnCount*1.2 should be enough most of the time + if(mnpayments.GetBlockCount() > nMnCount*1.2) { - //printf("MASTERNODE_SYNC_MNW VoteCount %d, mnCount*6 %d\n", mnpayments.GetVoteCount(), nMnCount*6); // target votes, max ten per item. 6 average should be fine - if(mnpayments.GetVoteCount() > nMnCount*6) + if(mnpayments.GetVoteCount() > nMnCount*1.2*6) { - //printf("Successfully synced mnw blocks and votes %d %d\n", mnpayments.GetBlockCount(), mnpayments.GetVoteCount()); GetNextAsset(); return; } @@ -383,20 +367,13 @@ void CMasternodeSync::Process() // MODE : MASTERNODE_SYNC_BUDGET if(RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET){ - //printf("MASTERNODE_SYNC_BUDGET Timeout at %d\n", lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT); - // shall we move onto the next asset if(countBudgetItemProp > 0 && countBudgetItemFin) { - //printf("MASTERNODE_SYNC_BUDGET countBudgetItemProp %d - %d\n", (sumBudgetItemProp / countBudgetItemProp), budget.CountProposalInventoryItems()); - //printf("MASTERNODE_SYNC_BUDGET countBudgetItemFin %d - %d\n", (sumBudgetItemFin / countBudgetItemFin), budget.CountFinalizedInventoryItems()); - if(budget.CountProposalInventoryItems() >= (sumBudgetItemProp / countBudgetItemProp)*0.9) { - //printf("HAVE BUDGETS\n"); if(budget.CountFinalizedInventoryItems() >= (sumBudgetItemFin / countBudgetItemFin)*0.9) { - //printf("HAVE FINAL BUDGETS\n"); GetNextAsset(); return; } diff --git a/src/masternode-sync.h b/src/masternode-sync.h index 647d0cc1c1d01..41ae8ebcd3a2a 100644 --- a/src/masternode-sync.h +++ b/src/masternode-sync.h @@ -15,7 +15,7 @@ #define MASTERNODE_SYNC_FAILED 998 #define MASTERNODE_SYNC_FINISHED 999 -#define MASTERNODE_SYNC_TIMEOUT 120 +#define MASTERNODE_SYNC_TIMEOUT 30 // our blocks are 2.5 minutes so 30 seconds should be fine class CMasternodeSync; extern CMasternodeSync masternodeSync;