Skip to content

Commit 9ff0bc9

Browse files
committed
Merge pull request #5158
9ec75c5 Add a locking mechanism to IsInitialBlockDownload to ensure it never goes from false to true. (Ruben Dario Ponticelli) a2d0fc6 Fix IsInitialBlockDownload which was broken by headers first. (Ruben Dario Ponticelli)
2 parents b031137 + 9ec75c5 commit 9ff0bc9

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/main.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,15 +1199,14 @@ bool IsInitialBlockDownload()
11991199
LOCK(cs_main);
12001200
if (fImporting || fReindex || chainActive.Height() < Checkpoints::GetTotalBlocksEstimate())
12011201
return true;
1202-
static int64_t nLastUpdate;
1203-
static CBlockIndex* pindexLastBest;
1204-
if (chainActive.Tip() != pindexLastBest)
1205-
{
1206-
pindexLastBest = chainActive.Tip();
1207-
nLastUpdate = GetTime();
1208-
}
1209-
return (GetTime() - nLastUpdate < 10 &&
1210-
chainActive.Tip()->GetBlockTime() < GetTime() - 24 * 60 * 60);
1202+
static bool lockIBDState = false;
1203+
if (lockIBDState)
1204+
return false;
1205+
bool state = (chainActive.Height() < pindexBestHeader->nHeight - 24 * 6 ||
1206+
pindexBestHeader->GetBlockTime() < GetTime() - 24 * 60 * 60);
1207+
if (!state)
1208+
lockIBDState = true;
1209+
return state;
12111210
}
12121211

12131212
bool fLargeWorkForkFound = false;

0 commit comments

Comments
 (0)