MCPcopy Create free account
hub / github.com/ElementsProject/elements / ProcessNewBlock

Method ProcessNewBlock

src/validation.cpp:4160–4197  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4158}
4159
4160bool ChainstateManager::ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock>& block, bool force_processing, bool* new_block)
4161{
4162 AssertLockNotHeld(cs_main);
4163
4164 {
4165 CBlockIndex *pindex = nullptr;
4166 if (new_block) *new_block = false;
4167 BlockValidationState state;
4168
4169 // CheckBlock() does not support multi-threaded block validation because CBlock::fChecked can cause data race.
4170 // Therefore, the following critical section must include the CheckBlock() call as well.
4171 LOCK(cs_main);
4172
4173 // Skipping AcceptBlock() for CheckBlock() failures means that we will never mark a block as invalid if
4174 // CheckBlock() fails. This is protective against consensus failure if there are any unknown forms of block
4175 // malleability that cause CheckBlock() to fail; see e.g. CVE-2012-2459 and
4176 // https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2019-February/016697.html. Because CheckBlock() is
4177 // not very expensive, the anti-DoS benefits of caching failure (of a definitely-invalid block) are not substantial.
4178 bool ret = CheckBlock(*block, state, chainparams.GetConsensus());
4179 if (ret) {
4180 // Store to disk
4181 ret = ActiveChainstate().AcceptBlock(block, state, &pindex, force_processing, nullptr, new_block);
4182 }
4183 if (!ret) {
4184 GetMainSignals().BlockChecked(*block, state);
4185 return error("%s: AcceptBlock FAILED (%s)", __func__, state.ToString());
4186 }
4187 }
4188
4189 NotifyHeaderTip(ActiveChainstate());
4190
4191 BlockValidationState state; // Only used to report errors, not invalidity - ignore it
4192 if (!ActiveChainstate().ActivateBestChain(state, block)) {
4193 return error("%s: ActivateBestChain failed (%s)", __func__, state.ToString());
4194 }
4195
4196 return true;
4197}
4198
4199MempoolAcceptResult ChainstateManager::ProcessTransaction(const CTransactionRef& tx, bool test_accept)
4200{

Callers 8

ProcessBlockMethod · 0.80
BOOST_FIXTURE_TEST_CASEFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
BOOST_AUTO_TEST_CASEFunction · 0.80
MineBlockFunction · 0.80
CreateAndProcessBlockMethod · 0.80
GenerateBlockFunction · 0.80
submitblockFunction · 0.80

Calls 6

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

Tested by 5

BOOST_FIXTURE_TEST_CASEFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64
MineBlockFunction · 0.64
CreateAndProcessBlockMethod · 0.64