Merge pull request #5337 from LarryRuane/2021-09-testIBD

Fix two boost tests that require post-IBD
This commit is contained in:
Steven 2021-10-13 08:16:58 -07:00 committed by GitHub
commit 1a7c2a3b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -2239,16 +2239,23 @@ CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams)
} }
} }
static std::atomic<bool> IBDLatchToFalse{false};
// testing-only, allow initial block down state to be set or reset
bool TestSetIBD(bool ibd) {
bool ret = !IBDLatchToFalse;
IBDLatchToFalse.store(!ibd, std::memory_order_relaxed);
return ret;
}
bool IsInitialBlockDownload(const Consensus::Params& params) bool IsInitialBlockDownload(const Consensus::Params& params)
{ {
// Once this function has returned false, it must remain false. // Once this function has returned false, it must remain false.
static std::atomic<bool> latchToFalse{false};
// Optimization: pre-test latch before taking the lock. // Optimization: pre-test latch before taking the lock.
if (latchToFalse.load(std::memory_order_relaxed)) if (IBDLatchToFalse.load(std::memory_order_relaxed))
return false; return false;
LOCK(cs_main); LOCK(cs_main);
if (latchToFalse.load(std::memory_order_relaxed)) if (IBDLatchToFalse.load(std::memory_order_relaxed))
return false; return false;
if (fImporting || fReindex) if (fImporting || fReindex)
return true; return true;
@ -2310,7 +2317,7 @@ bool IsInitialBlockDownload(const Consensus::Params& params)
if (chainActive.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge)) if (chainActive.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge))
return true; return true;
LogPrintf("Leaving InitialBlockDownload (latching to false)\n"); LogPrintf("Leaving InitialBlockDownload (latching to false)\n");
latchToFalse.store(true, std::memory_order_relaxed); IBDLatchToFalse.store(true, std::memory_order_relaxed);
return false; return false;
} }

View File

@ -273,6 +273,8 @@ bool SendMessages(const Consensus::Params& params, CNode* pto);
void ThreadScriptCheck(); void ThreadScriptCheck();
/** Check whether we are doing an initial block download (synchronizing from disk or network) */ /** Check whether we are doing an initial block download (synchronizing from disk or network) */
bool IsInitialBlockDownload(const Consensus::Params& params); bool IsInitialBlockDownload(const Consensus::Params& params);
/** testing-only, set or reset initial block down (IBD) state, return previous */
bool TestSetIBD(bool);
/** Format a string that describes several potential problems detected by the core */ /** Format a string that describes several potential problems detected by the core */
std::pair<std::string, int64_t> GetWarnings(const std::string& strFor); std::pair<std::string, int64_t> GetWarnings(const std::string& strFor);
/** Retrieve a transaction (from memory pool, or from disk, if possible) */ /** Retrieve a transaction (from memory pool, or from disk, if possible) */

View File

@ -78,6 +78,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
fCheckBlockIndex = true; fCheckBlockIndex = true;
SelectParams(chainName); SelectParams(chainName);
noui_connect(); noui_connect();
TestSetIBD(false);
} }
BasicTestingSetup::~BasicTestingSetup() BasicTestingSetup::~BasicTestingSetup()