| 4413 | } |
| 4414 | |
| 4415 | bool ChainstateManager::ProcessNewBlock(const std::shared_ptr<const CBlock>& block, bool force_processing, bool min_pow_checked, bool* new_block) |
| 4416 | { |
| 4417 | AssertLockNotHeld(cs_main); |
| 4418 | |
| 4419 | { |
| 4420 | CBlockIndex *pindex = nullptr; |
| 4421 | if (new_block) *new_block = false; |
| 4422 | BlockValidationState state; |
| 4423 | |
| 4424 | // CheckBlock() does not support multi-threaded block validation because CBlock::fChecked can cause data race. |
| 4425 | // Therefore, the following critical section must include the CheckBlock() call as well. |
| 4426 | LOCK(cs_main); |
| 4427 | |
| 4428 | // Skipping AcceptBlock() for CheckBlock() failures means that we will never mark a block as invalid if |
| 4429 | // CheckBlock() fails. This is protective against consensus failure if there are any unknown forms of block |
| 4430 | // malleability that cause CheckBlock() to fail; see e.g. CVE-2012-2459 and |
| 4431 | // https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-February/016697.html. Because CheckBlock() is |
| 4432 | // not very expensive, the anti-DoS benefits of caching failure (of a definitely-invalid block) are not substantial. |
| 4433 | bool ret = CheckBlock(*block, state, GetConsensus()); |
| 4434 | if (ret) { |
| 4435 | // Store to disk |
| 4436 | ret = AcceptBlock(block, state, &pindex, force_processing, nullptr, new_block, min_pow_checked); |
| 4437 | } |
| 4438 | if (!ret) { |
| 4439 | if (m_options.signals) { |
| 4440 | m_options.signals->BlockChecked(block, state); |
| 4441 | } |
| 4442 | LogError("%s: AcceptBlock FAILED (%s)\n", __func__, state.ToString()); |
| 4443 | return false; |
| 4444 | } |
| 4445 | } |
| 4446 | |
| 4447 | NotifyHeaderTip(); |
| 4448 | |
| 4449 | BlockValidationState state; // Only used to report errors, not invalidity - ignore it |
| 4450 | if (!ActiveChainstate().ActivateBestChain(state, block)) { |
| 4451 | LogError("%s: ActivateBestChain failed (%s)\n", __func__, state.ToString()); |
| 4452 | return false; |
| 4453 | } |
| 4454 | |
| 4455 | Chainstate* bg_chain{WITH_LOCK(cs_main, return HistoricalChainstate())}; |
| 4456 | BlockValidationState bg_state; |
| 4457 | if (bg_chain && !bg_chain->ActivateBestChain(bg_state, block)) { |
| 4458 | LogError("%s: [background] ActivateBestChain failed (%s)\n", __func__, bg_state.ToString()); |
| 4459 | return false; |
| 4460 | } |
| 4461 | |
| 4462 | return true; |
| 4463 | } |
| 4464 | |
| 4465 | MempoolAcceptResult ChainstateManager::ProcessTransaction(const CTransactionRef& tx, bool test_accept) |
| 4466 | { |