From a2d0fc658a7b21d2d41ef2a6c657d24114b6c49e Mon Sep 17 00:00:00 2001 From: Ruben Dario Ponticelli Date: Tue, 28 Oct 2014 14:48:50 -0300 Subject: [PATCH 1/2] Fix IsInitialBlockDownload which was broken by headers first. --- src/main.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 008a05910..bf487df39 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1177,15 +1177,8 @@ bool IsInitialBlockDownload() LOCK(cs_main); if (fImporting || fReindex || chainActive.Height() < Checkpoints::GetTotalBlocksEstimate()) return true; - static int64_t nLastUpdate; - static CBlockIndex* pindexLastBest; - if (chainActive.Tip() != pindexLastBest) - { - pindexLastBest = chainActive.Tip(); - nLastUpdate = GetTime(); - } - return (GetTime() - nLastUpdate < 10 && - chainActive.Tip()->GetBlockTime() < GetTime() - 24 * 60 * 60); + return (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 || + pindexBestHeader->GetBlockTime() < GetTime() - 24 * 60 * 60); } bool fLargeWorkForkFound = false; From 9ec75c5ef4182a38e261beaafdc94325785cc7c5 Mon Sep 17 00:00:00 2001 From: Ruben Dario Ponticelli Date: Wed, 5 Nov 2014 20:52:27 -0300 Subject: [PATCH 2/2] Add a locking mechanism to IsInitialBlockDownload to ensure it never goes from false to true. --- src/main.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index bf487df39..0fd806534 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1177,8 +1177,14 @@ bool IsInitialBlockDownload() LOCK(cs_main); if (fImporting || fReindex || chainActive.Height() < Checkpoints::GetTotalBlocksEstimate()) return true; - return (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 || + static bool lockIBDState = false; + if (lockIBDState) + return false; + bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 || pindexBestHeader->GetBlockTime() < GetTime() - 24 * 60 * 60); + if (!state) + lockIBDState = true; + return state; } bool fLargeWorkForkFound = false;