| 3826 | } |
| 3827 | |
| 3828 | bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot) |
| 3829 | { |
| 3830 | AssertLockHeld(cs_main); |
| 3831 | assert(pindexPrev && pindexPrev == chainActive.Tip()); |
| 3832 | CCoinsViewCache viewNew(pcoinsTip.get()); |
| 3833 | uint256 block_hash(block.GetHash()); |
| 3834 | CBlockIndex indexDummy(block); |
| 3835 | indexDummy.pprev = pindexPrev; |
| 3836 | indexDummy.nHeight = pindexPrev->nHeight + 1; |
| 3837 | indexDummy.phashBlock = &block_hash; |
| 3838 | |
| 3839 | // NOTE: CheckBlockHeader is called by CheckBlock |
| 3840 | if (!ContextualCheckBlockHeader(block, state, chainparams, pindexPrev, GetAdjustedTime())) |
| 3841 | return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, FormatStateMessage(state)); |
| 3842 | if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot)) |
| 3843 | return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state)); |
| 3844 | if (!ContextualCheckBlock(block, state, chainparams.GetConsensus(), pindexPrev)) |
| 3845 | return error("%s: Consensus::ContextualCheckBlock: %s", __func__, FormatStateMessage(state)); |
| 3846 | if (!g_chainstate.ConnectBlock(block, state, &indexDummy, viewNew, chainparams, true)) |
| 3847 | return false; |
| 3848 | assert(state.IsValid()); |
| 3849 | |
| 3850 | return true; |
| 3851 | } |
| 3852 | |
| 3853 | /** |
| 3854 | * BLOCK PRUNING CODE |
no test coverage detected