From 3a72bea5b383b9841aefbcbf455b69c57360e2ed Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Thu, 30 Jul 2015 01:51:48 -0700 Subject: [PATCH] fixed sync edge case --- src/masternode-budget.cpp | 2 +- src/masternode-sync.cpp | 26 ++++++++++++++++---------- src/masternode-sync.h | 1 + 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/masternode-budget.cpp b/src/masternode-budget.cpp index d25bfd4ec..7332694b2 100644 --- a/src/masternode-budget.cpp +++ b/src/masternode-budget.cpp @@ -539,7 +539,7 @@ bool CBudgetManager::HasNextFinalizedBudget() if(budget.IsBudgetPaymentBlock(nBlockStart)) return true; - LogPrintf("CBudgetManager::HasNextFinalizedBudget() - Client is missing budget\n"); + LogPrintf("CBudgetManager::HasNextFinalizedBudget() - Client is missing budget - %lli\n", nBlockStart); return false; } diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 8d210e825..d3bbd7561 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -93,6 +93,7 @@ void CMasternodeSync::GetNextAsset() countBudgetItemProp = 0; countBudgetItemFin = 0; RequestedMasternodeAssets = MASTERNODE_SYNC_SPORKS; + ClearFulfilledRequest(); break; case(MASTERNODE_SYNC_SPORKS): RequestedMasternodeAssets = MASTERNODE_SYNC_LIST; @@ -150,7 +151,19 @@ void CMasternodeSync::ProcessMessage(CNode* pfrom, std::string& strCommand, CDat break; } - LogPrintf("ssc - got inventory count %d %d\n", nItemID, nCount); + LogPrintf("CMasternodeSync:ProcessMessage - ssc - got inventory count %d %d\n", nItemID, nCount); + } +} + +void CMasternodeSync::ClearFulfilledRequest() +{ + LOCK(cs_vNodes); + BOOST_FOREACH(CNode* pnode, vNodes) + { + pnode->ClearFulfilledRequest("getspork"); + pnode->ClearFulfilledRequest("mnsync"); + pnode->ClearFulfilledRequest("mnwsync"); + pnode->ClearFulfilledRequest("busync"); } } @@ -168,15 +181,7 @@ void CMasternodeSync::Process() Resync if we lose all masternodes from sleep/wake or failure to sync originally */ if(mnodeman.CountEnabled() == 0) { - LOCK(cs_vNodes); - BOOST_FOREACH(CNode* pnode, vNodes) - { - pnode->ClearFulfilledRequest("getspork"); - pnode->ClearFulfilledRequest("mnsync"); - pnode->ClearFulfilledRequest("mnwsync"); - pnode->ClearFulfilledRequest("busync"); - } - + ClearFulfilledRequest(); RequestedMasternodeAssets = MASTERNODE_SYNC_INITIAL; } else return; @@ -273,6 +278,7 @@ void CMasternodeSync::Process() if(RequestedMasternodeAssets == MASTERNODE_SYNC_BUDGET){ //we'll start rejecting votes if we accidentally get set as synced too soon if(lastBudgetItem > 0 && lastBudgetItem < GetTime() - MASTERNODE_SYNC_TIMEOUT && RequestedMasternodeAttempt >= 4){ //hasn't received a new item in the last five seconds, so we'll move to the + LogPrintf("CMasternodeSync::Process - HasNextFinalizedBudget %d nCountFailures %d IsBudgetPropEmpty %d\n", budget.HasNextFinalizedBudget(), nCountFailures, IsBudgetPropEmpty()); if(budget.HasNextFinalizedBudget() || nCountFailures >= 2 || IsBudgetPropEmpty()) { GetNextAsset(); diff --git a/src/masternode-sync.h b/src/masternode-sync.h index 74da058f9..7fa947a11 100644 --- a/src/masternode-sync.h +++ b/src/masternode-sync.h @@ -61,6 +61,7 @@ public: void Process(); bool IsSynced(); bool IsBlockchainSynced(); + void ClearFulfilledRequest(); }; #endif