MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ProcessNewBlock

Method ProcessNewBlock

src/validation.cpp:4415–4463  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4413}
4414
4415bool 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
4465MempoolAcceptResult ChainstateManager::ProcessTransaction(const CTransactionRef& tx, bool test_accept)
4466{

Callers 11

ProcessBlockMethod · 0.80
BOOST_FIXTURE_TEST_CASEFunction · 0.80
BOOST_FIXTURE_TEST_CASEFunction · 0.80
mineBlockFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
ProcessBlockFunction · 0.80
CreateAndProcessBlockMethod · 0.80
GenerateBlockFunction · 0.80
submitblockFunction · 0.80
SubmitBlockFunction · 0.80

Calls 4

CheckBlockFunction · 0.85
ActivateBestChainMethod · 0.80
BlockCheckedMethod · 0.45
ToStringMethod · 0.45

Tested by 6

BOOST_FIXTURE_TEST_CASEFunction · 0.64
BOOST_FIXTURE_TEST_CASEFunction · 0.64
mineBlockFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
ProcessBlockFunction · 0.64
CreateAndProcessBlockMethod · 0.64