diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 753e347e4..d9c8db472 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -17,21 +17,7 @@ CMasternodeSync masternodeSync; CMasternodeSync::CMasternodeSync() { - lastMasternodeList = 0; - lastMasternodeWinner = 0; - lastBudgetItem = 0; - lastFailure = 0; - nCountFailures = 0; - sumMasternodeList = 0; - sumMasternodeWinner = 0; - sumBudgetItemProp = 0; - sumBudgetItemFin = 0; - countMasternodeList = 0; - countMasternodeWinner = 0; - countBudgetItemProp = 0; - countBudgetItemFin = 0; - RequestedMasternodeAssets = MASTERNODE_SYNC_INITIAL; - RequestedMasternodeAttempt = 0; + Reset(); } bool CMasternodeSync::IsSynced() @@ -61,6 +47,49 @@ bool CMasternodeSync::IsBlockchainSynced() return true; } +// if the last call to this function was more than 10 minutes ago, reset the sync process +// - Get new masternode information +// - Get new votes we missed (budgets and winners) +// - Get new masternode budget +void CMasternodeSync::WakeUp() +{ + // was asleep for more than 10 minutes? + if(GetTime() - lastProcess > 60*10) { + static bool fBlockchainSynced = false; + fBlockchainSynced = false; + + Reset(); + + // this could get us banned by our peers, but we'll need to try and get new information we missed + ClearFulfilledRequest(); + + // maybe we should reset all masternode based information and resync from scratch? + // maybe we should get 8 new peers? + } + + lastProcess = GetTime(); +} + +void CMasternodeSync::Reset() +{ + lastMasternodeList = 0; + lastMasternodeWinner = 0; + lastBudgetItem = 0; + lastFailure = 0; + lastProcess = GetTime(); + nCountFailures = 0; + sumMasternodeList = 0; + sumMasternodeWinner = 0; + sumBudgetItemProp = 0; + sumBudgetItemFin = 0; + countMasternodeList = 0; + countMasternodeWinner = 0; + countBudgetItemProp = 0; + countBudgetItemFin = 0; + RequestedMasternodeAssets = MASTERNODE_SYNC_INITIAL; + RequestedMasternodeAttempt = 0; +} + void CMasternodeSync::AddedMasternodeList() { lastMasternodeList = GetTime(); @@ -186,6 +215,8 @@ void CMasternodeSync::Process() { static int tick = 0; + WakeUp(); + if(tick++ % MASTERNODE_SYNC_TIMEOUT != 0) return; if(IsSynced()) { diff --git a/src/masternode-sync.h b/src/masternode-sync.h index 7fa947a11..b50645b81 100644 --- a/src/masternode-sync.h +++ b/src/masternode-sync.h @@ -31,6 +31,7 @@ public: int64_t lastMasternodeWinner; int64_t lastBudgetItem; int64_t lastFailure; + int64_t lastProcess; int nCountFailures; // sum of all counts @@ -58,7 +59,9 @@ public: bool IsBudgetFinEmpty(); bool IsBudgetPropEmpty(); + void Reset(); void Process(); + void WakeUp(); bool IsSynced(); bool IsBlockchainSynced(); void ClearFulfilledRequest();