Move CheckBlock() call to critical section

This prevents data race for CBlock::fChecked.
This commit is contained in:
Hennadii Stepanov 2018-11-29 13:36:12 +02:00
parent 60b20c869f
commit c5ed6e73d3
No known key found for this signature in database
GPG key ID: 410108112E7EA81F
2 changed files with 5 additions and 6 deletions

View file

@ -3530,12 +3530,14 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
CBlockIndex *pindex = nullptr;
if (fNewBlock) *fNewBlock = false;
CValidationState state;
// CheckBlock() does not support multi-threaded block validation because CBlock::fChecked can cause data race.
// Therefore, the following critical section must include the CheckBlock() call as well.
LOCK(cs_main);
// Ensure that CheckBlock() passes before calling AcceptBlock, as
// belt-and-suspenders.
bool ret = CheckBlock(*pblock, state, chainparams.GetConsensus());
LOCK(cs_main);
if (ret) {
// Store to disk
ret = g_chainstate.AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, nullptr, fNewBlock);

View file

@ -1,9 +1,6 @@
# ThreadSanitizer suppressions
# ============================
# fChecked is theoretically racy, practically only in unit tests
race:CheckBlock
# WalletBatch (unidentified deadlock)
deadlock:WalletBatch