Auto merge of #4387 - gladcow:issue3813_backport_upstream_11107, r=daira

Fix races in AppInitMain and others with lock and atomic bools (Bitcoin backport)

Backport bitcoin https://github.com/bitcoin/bitcoin/pull/11107 (excluding the last commit,  it was fixed in Zcash before).

This functionality is required for https://github.com/zcash/zcash/pull/4368 (details https://github.com/zcash/zcash/pull/4368#issuecomment-595284681) as part of the issue https://github.com/zcash/zcash/issues/3813 resolution.
This commit is contained in:
Homu 2020-03-09 19:52:20 +00:00
commit 8c48786d7d
4 changed files with 19 additions and 13 deletions

View File

@ -1621,15 +1621,21 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
return InitError(strErrors.str());
//// debug print
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size());
LogPrintf("nBestHeight = %d\n", chainActive.Height());
{
LOCK(cs_main);
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size());
LogPrintf("nBestHeight = %d\n", chainActive.Height());
}
#ifdef ENABLE_WALLET
LogPrintf("setKeyPool.size() = %u\n", pwalletMain ? pwalletMain->setKeyPool.size() : 0);
LogPrintf("mapWallet.size() = %u\n", pwalletMain ? pwalletMain->mapWallet.size() : 0);
LogPrintf("mapAddressBook.size() = %u\n", pwalletMain ? pwalletMain->mapAddressBook.size() : 0);
if (pwalletMain)
{
LOCK(pwalletMain->cs_wallet);
LogPrintf("setKeyPool.size() = %u\n", pwalletMain->setKeyPool.size());
LogPrintf("mapWallet.size() = %u\n", pwalletMain->mapWallet.size());
LogPrintf("mapAddressBook.size() = %u\n", pwalletMain->mapAddressBook.size());
}
#endif
if (GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION))
StartTorControl(threadGroup, scheduler);

View File

@ -67,7 +67,7 @@ CConditionVariable cvBlockChange;
int nScriptCheckThreads = 0;
bool fExperimentalMode = false;
bool fImporting = false;
bool fReindex = false;
std::atomic_bool fReindex(false);
bool fTxIndex = false;
bool fInsightExplorer = false; // insightexplorer
bool fAddressIndex = false; // insightexplorer
@ -4455,7 +4455,7 @@ bool static LoadBlockIndexDB()
// Check whether we need to continue reindexing
bool fReindexing = false;
pblocktree->ReadReindexing(fReindexing);
fReindex |= fReindexing;
if(fReindexing) fReindex = true;
// Check whether we have a transaction index
pblocktree->ReadFlag("txindex", fTxIndex);

View File

@ -139,7 +139,7 @@ extern CWaitableCriticalSection csBestBlock;
extern CConditionVariable cvBlockChange;
extern bool fExperimentalMode;
extern bool fImporting;
extern bool fReindex;
extern std::atomic_bool fReindex;
extern int nScriptCheckThreads;
extern bool fTxIndex;

View File

@ -107,12 +107,12 @@ private:
public:
bool WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo);
bool EraseBatchSync(const std::vector<const CBlockIndex*>& blockinfo);
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo);
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info);
bool ReadLastBlockFile(int &nFile);
bool WriteReindexing(bool fReindex);
bool ReadReindexing(bool &fReindex);
bool WriteReindexing(bool fReindexing);
bool ReadReindexing(bool &fReindexing);
bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos);
bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &list);
bool WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> > &vect);
// START insightexplorer
bool UpdateAddressUnspentIndex(const std::vector<CAddressUnspentDbEntry> &vect);