Skip to content

Commit

Permalink
fix sync (#1643)
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 authored Sep 20, 2017
1 parent 8949f43 commit 5f0da8a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/dsnotificationinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 20 additions & 2 deletions src/masternode-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/masternode-sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 5f0da8a

Please sign in to comment.