From 5f0da8aa71b1f325c329a6fa53cd336415977927 Mon Sep 17 00:00:00 2001 From: UdjinM6 Date: Wed, 20 Sep 2017 23:30:56 +0300 Subject: [PATCH] fix sync (#1643) --- src/dsnotificationinterface.cpp | 7 ++++++- src/masternode-sync.cpp | 22 ++++++++++++++++++++-- src/masternode-sync.h | 1 + 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/dsnotificationinterface.cpp b/src/dsnotificationinterface.cpp index ad65e55b90929..8f89b731544d4 100644 --- a/src/dsnotificationinterface.cpp +++ b/src/dsnotificationinterface.cpp @@ -29,7 +29,12 @@ void CDSNotificationInterface::NotifyHeaderTip(const CBlockIndex *pindexNew, boo void CDSNotificationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) { - if (fInitialDownload || pindexNew == pindexFork) // In IBD or blocks were disconnected without any new ones + if (pindexNew == pindexFork) // blocks were disconnected without any new ones + return; + + masternodeSync.UpdatedBlockTip(pindexNew, fInitialDownload, connman); + + if (fInitialDownload) // In IBD return; mnodeman.UpdatedBlockTip(pindexNew); diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index ae3302e7630bf..951e38871819c 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -245,7 +245,7 @@ void CMasternodeSync::ProcessTick(CConnman& connman) // b) we waited for at least MASTERNODE_SYNC_TIMEOUT_SECONDS since we reached // the headers tip the last time (i.e. since we switched from // MASTERNODE_SYNC_INITIAL to MASTERNODE_SYNC_WAITING and bumped time); - // c) there were no blocks (NotifyHeaderTip) or headers (AcceptedBlockHeader) + // c) there were no blocks (UpdatedBlockTip, NotifyHeaderTip) or headers (AcceptedBlockHeader) // for at least MASTERNODE_SYNC_TIMEOUT_SECONDS. // We must be at the tip already, let's move to the next asset. SwitchToNextAsset(connman); @@ -431,8 +431,26 @@ void CMasternodeSync::NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitia // Postpone timeout each time new block arrives while we are still syncing blockchain BumpAssetLastTime("CMasternodeSync::NotifyHeaderTip"); } +} + +void CMasternodeSync::UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman& connman) +{ + LogPrint("mnsync", "CMasternodeSync::UpdatedBlockTip -- pindexNew->nHeight: %d fInitialDownload=%d\n", pindexNew->nHeight, fInitialDownload); + + if (IsFailed() || IsSynced() || !pindexBestHeader) + return; + + if (!IsBlockchainSynced()) { + // Postpone timeout each time new block arrives while we are still syncing blockchain + BumpAssetLastTime("CMasternodeSync::UpdatedBlockTip"); + } if (fInitialDownload) { + // switched too early + if (IsBlockchainSynced()) { + Reset(); + } + // no need to check any further while still in IBD mode return; } @@ -452,7 +470,7 @@ void CMasternodeSync::NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitia fReachedBestHeader = fReachedBestHeaderNew; - LogPrint("mnsync", "CMasternodeSync::NotifyHeaderTip -- pindexNew->nHeight: %d pindexBestHeader->nHeight: %d fInitialDownload=%d fReachedBestHeader=%d\n", + LogPrint("mnsync", "CMasternodeSync::UpdatedBlockTip -- pindexNew->nHeight: %d pindexBestHeader->nHeight: %d fInitialDownload=%d fReachedBestHeader=%d\n", pindexNew->nHeight, pindexBestHeader->nHeight, fInitialDownload, fReachedBestHeader); if (!IsBlockchainSynced() && fReachedBestHeader) { diff --git a/src/masternode-sync.h b/src/masternode-sync.h index 736fe1d4fe718..d60abca60b584 100644 --- a/src/masternode-sync.h +++ b/src/masternode-sync.h @@ -77,6 +77,7 @@ class CMasternodeSync void AcceptedBlockHeader(const CBlockIndex *pindexNew); void NotifyHeaderTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman& connman); + void UpdatedBlockTip(const CBlockIndex *pindexNew, bool fInitialDownload, CConnman& connman); }; #endif