Skip to content

Commit

Permalink
Move CheckBlock() call to critical section
Browse files Browse the repository at this point in the history
This prevents data race for CBlock::fChecked.
  • Loading branch information
hebasto committed Nov 30, 2018
1 parent 60b20c8 commit c5ed6e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/validation.cpp
Expand Up @@ -3530,12 +3530,14 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
CBlockIndex *pindex = nullptr;
if (fNewBlock) *fNewBlock = false;
CValidationState state;
// Ensure that CheckBlock() passes before calling AcceptBlock, as
// belt-and-suspenders.
bool ret = CheckBlock(*pblock, state, chainparams.GetConsensus());

// 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());
if (ret) {
// Store to disk
ret = g_chainstate.AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, nullptr, fNewBlock);
Expand Down
3 changes: 0 additions & 3 deletions test/sanitizer_suppressions/tsan
@@ -1,9 +1,6 @@
# ThreadSanitizer suppressions
# ============================

# fChecked is theoretically racy, practically only in unit tests
race:CheckBlock

# WalletBatch (unidentified deadlock)
deadlock:WalletBatch

Expand Down

0 comments on commit c5ed6e7

Please sign in to comment.