Skip to content

Commit 5ab5341

Browse files
committed
Merge #14841: consensus: Move CheckBlock() call to critical section
c5ed6e7 Move CheckBlock() call to critical section (Hennadii Stepanov) Pull request description: This is an alternative to #14803. Refs: - #14058 - #14072 - bitcoin/bitcoin#14803 (comment) by @gmaxwell > It doesn't support multithreaded validation and there are lot of things that prevent that, which is why I was concerned. Why doesn't the lock on the block index or even cs main prevent concurrency here? - bitcoin/bitcoin#14803 (comment) by @MarcoFalke Tree-SHA512: 2152e97106e11da5763b2748234ecd2982daadab13a0da04215f4db60af802a44ab5700f32249137d122eb13fc2a02e0f2d561d364607d727d8c6ab879339afb
2 parents 011c42c + c5ed6e7 commit 5ab5341

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)