diff options
| author | Hennadii Stepanov <[email protected]> | 2018-11-29 13:36:12 +0200 |
|---|---|---|
| committer | Hennadii Stepanov <[email protected]> | 2018-11-30 12:40:57 +0200 |
| commit | c5ed6e73d3e18f26558c49fa3ecb1b7b0bb40d12 (patch) | |
| tree | 10ec3fe50820e371ba6de079d7a56ce091e88663 /src/validation.cpp | |
| parent | Merge #14822: bench: Destroy wallet txs instead of leaking their memory (diff) | |
| download | discoin-c5ed6e73d3e18f26558c49fa3ecb1b7b0bb40d12.tar.xz discoin-c5ed6e73d3e18f26558c49fa3ecb1b7b0bb40d12.zip | |
Move CheckBlock() call to critical section
This prevents data race for CBlock::fChecked.
Diffstat (limited to 'src/validation.cpp')
| -rw-r--r-- | src/validation.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 6333dd98d..512a3619c 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -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); |