File tree Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Expand file tree Collapse file tree 1 file changed +11
-4
lines changed Original file line number Diff line number Diff line change 37
37
#include " validationinterface.h"
38
38
#include " versionbits.h"
39
39
40
+ #include < atomic>
40
41
#include < sstream>
41
42
42
43
#include < boost/algorithm/string/replace.hpp>
@@ -1577,18 +1578,24 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
1577
1578
bool IsInitialBlockDownload ()
1578
1579
{
1579
1580
const CChainParams& chainParams = Params ();
1581
+
1582
+ // Once this function has returned false, it must remain false.
1583
+ static std::atomic<bool > latchToFalse{false };
1584
+ // Optimization: pre-test latch before taking the lock.
1585
+ if (latchToFalse.load (std::memory_order_relaxed))
1586
+ return false ;
1587
+
1580
1588
LOCK (cs_main);
1589
+ if (latchToFalse.load (std::memory_order_relaxed))
1590
+ return false ;
1581
1591
if (fImporting || fReindex )
1582
1592
return true ;
1583
1593
if (fCheckpointsEnabled && chainActive.Height () < Checkpoints::GetTotalBlocksEstimate (chainParams.Checkpoints ()))
1584
1594
return true ;
1585
- static bool lockIBDState = false ;
1586
- if (lockIBDState)
1587
- return false ;
1588
1595
bool state = (chainActive.Height () < pindexBestHeader->nHeight - 24 * 6 ||
1589
1596
std::max (chainActive.Tip ()->GetBlockTime (), pindexBestHeader->GetBlockTime ()) < GetTime () - nMaxTipAge);
1590
1597
if (!state)
1591
- lockIBDState = true ;
1598
+ latchToFalse. store ( true , std::memory_order_relaxed) ;
1592
1599
return state;
1593
1600
}
1594
1601
You can’t perform that action at this time.
0 commit comments