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

Function TestBlockValidity

src/validation.cpp:4213–4243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4211}
4212
4213bool TestBlockValidity(BlockValidationState& state,
4214 const CChainParams& chainparams,
4215 CChainState& chainstate,
4216 const CBlock& block,
4217 CBlockIndex* pindexPrev,
4218 bool fCheckPOW,
4219 bool fCheckMerkleRoot)
4220{
4221 AssertLockHeld(cs_main);
4222 assert(pindexPrev && pindexPrev == chainstate.m_chain.Tip());
4223 CCoinsViewCache viewNew(&chainstate.CoinsTip());
4224 uint256 block_hash(block.GetHash());
4225 CBlockIndex indexDummy(block);
4226 indexDummy.pprev = pindexPrev;
4227 indexDummy.nHeight = pindexPrev->nHeight + 1;
4228 indexDummy.phashBlock = &block_hash;
4229
4230 // NOTE: CheckBlockHeader is called by CheckBlock
4231 if (!ContextualCheckBlockHeader(block, state, chainstate.m_blockman, chainparams, pindexPrev, GetAdjustedTime()))
4232 return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, state.ToString());
4233 if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot))
4234 return error("%s: Consensus::CheckBlock: %s", __func__, state.ToString());
4235 if (!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindexPrev))
4236 return error("%s: Consensus::ContextualCheckBlock: %s", __func__, state.ToString());
4237 if (!chainstate.ConnectBlock(block, state, &indexDummy, viewNew, NULL, true)) {
4238 return false;
4239 }
4240 assert(state.IsValid());
4241
4242 return true;
4243}
4244
4245/* This function is called from the RPC code for pruneblockchain */
4246void PruneBlockFilesManual(CChainState& active_chainstate, int nManualPruneHeight)

Callers 5

generateblockFunction · 0.85
getblocktemplateFunction · 0.85
testproposedblockFunction · 0.85
CreateNewBlockMethod · 0.85
testBlockValidityMethod · 0.85

Calls 9

GetAdjustedTimeFunction · 0.85
errorFunction · 0.85
CheckBlockFunction · 0.85
ContextualCheckBlockFunction · 0.85
ConnectBlockMethod · 0.80
TipMethod · 0.45
GetHashMethod · 0.45
ToStringMethod · 0.45
IsValidMethod · 0.45

Tested by

no test coverage detected