From 2e8445e74112fbf62b38b35ebda6b7f4754bc34f Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Mon, 3 Aug 2015 23:42:18 +0300 Subject: [PATCH] refactor IsBlockchainSynced --- src/masternode-sync.cpp | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index 5e137260c8747..66020df143d1a 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -41,10 +41,22 @@ bool CMasternodeSync::IsSynced() bool CMasternodeSync::IsBlockchainSynced() { - CBlockIndex* pindexPrev = chainActive.Tip(); - if(pindexPrev == NULL) return false; + if (fImporting || fReindex) return false; + + TRY_LOCK(cs_main, lockMain); + if(!lockMain) return false; + + CBlockIndex* pindex = chainActive.Tip(); + if(pindex == NULL) return false; + + static bool fBlockchainSynced = false; + if(fBlockchainSynced) return true; + + if(pindex->nTime + 600 < GetTime()) + return false; + + fBlockchainSynced = true; - if(pindexPrev->nTime + 600 < GetTime()) return false; return true; } @@ -197,6 +209,10 @@ void CMasternodeSync::Process() if(RequestedMasternodeAssets == MASTERNODE_SYNC_INITIAL) GetNextAsset(); + // sporks synced but blockchain is not, wait until we're almost at a recent block to continue + if(Params().NetworkID() != CBaseChainParams::REGTEST && + !IsBlockchainSynced() && RequestedMasternodeAssets > MASTERNODE_SYNC_SPORKS) return; + TRY_LOCK(cs_vNodes, lockRecv); if(!lockRecv) return; @@ -231,16 +247,6 @@ void CMasternodeSync::Process() return; } - { - TRY_LOCK(cs_main, lockMain); - if(!lockMain) return; - - if(IsInitialBlockDownload()) return; - } - - //don't begin syncing until we're almost at a recent block - if(!IsBlockchainSynced()) return; - if (pnode->nVersion >= masternodePayments.GetMinMasternodePaymentsProto()) { if(RequestedMasternodeAssets == MASTERNODE_SYNC_LIST) {