Skip to content

Commit c5ed6e7

Browse files
committed
Move CheckBlock() call to critical section
This prevents data race for CBlock::fChecked.
1 parent 60b20c8 commit c5ed6e7

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/validation.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3530,12 +3530,14 @@ bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<cons
35303530
CBlockIndex *pindex = nullptr;
35313531
if (fNewBlock) *fNewBlock = false;
35323532
CValidationState state;
3533-
// Ensure that CheckBlock() passes before calling AcceptBlock, as
3534-
// belt-and-suspenders.
3535-
bool ret = CheckBlock(*pblock, state, chainparams.GetConsensus());
35363533

3534+
// CheckBlock() does not support multi-threaded block validation because CBlock::fChecked can cause data race.
3535+
// Therefore, the following critical section must include the CheckBlock() call as well.
35373536
LOCK(cs_main);
35383537

3538+
// Ensure that CheckBlock() passes before calling AcceptBlock, as
3539+
// belt-and-suspenders.
3540+
bool ret = CheckBlock(*pblock, state, chainparams.GetConsensus());
35393541
if (ret) {
35403542
// Store to disk
35413543
ret = g_chainstate.AcceptBlock(pblock, state, chainparams, &pindex, fForceProcessing, nullptr, fNewBlock);

test/sanitizer_suppressions/tsan

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
# ThreadSanitizer suppressions
22
# ============================
33

4-
# fChecked is theoretically racy, practically only in unit tests
5-
race:CheckBlock
6-
74
# WalletBatch (unidentified deadlock)
85
deadlock:WalletBatch
96

0 commit comments

Comments
 (0)