| 5107 | } |
| 5108 | |
| 5109 | bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* const pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot) |
| 5110 | { |
| 5111 | AssertLockHeld(cs_main); |
| 5112 | // printf("%s\n",__func__); |
| 5113 | // In some cases, chainActive.Tip() may return nullptr |
| 5114 | CBlockIndex *pIndex = chainActive.Tip(); |
| 5115 | if (pIndex == nullptr) { |
| 5116 | // printf("%s: Invalid chain tip!\n", __func__); |
| 5117 | return false; |
| 5118 | } |
| 5119 | else if (pindexPrev != pIndex) { |
| 5120 | // printf("%s: Invalid prevblock!\n", __func__); |
| 5121 | return false; |
| 5122 | } |
| 5123 | |
| 5124 | CCoinsViewCache viewNew(pcoinsTip); |
| 5125 | CBlockIndex index(block); |
| 5126 | index.pprev = pindexPrev; |
| 5127 | index.nHeight = pindexPrev->nHeight + 1; |
| 5128 | |
| 5129 | // NOTE: CheckBlockHeader is called by CheckBlock |
| 5130 | if (!ContextualCheckBlockHeader(block, state, chainparams.GetConsensus(), pindexPrev)) |
| 5131 | return error("%s: Consensus::ContextualCheckBlockHeader: %s", __func__, FormatStateMessage(state)); |
| 5132 | if (!CheckBlock(block, state, chainparams.GetConsensus(), fCheckPOW, fCheckMerkleRoot)) |
| 5133 | return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state)); |
| 5134 | if (!ContextualCheckBlock(block, state, pindexPrev)) |
| 5135 | return error("%s: Consensus::ContextualCheckBlock: %s", __func__, FormatStateMessage(state)); |
| 5136 | if (block.IsProofOfStake() && !stake->CheckProof(pindexPrev, block, index.hashProofOfStake)) |
| 5137 | return false; |
| 5138 | |
| 5139 | // printf("%s after checks\n",__func__); |
| 5140 | |
| 5141 | dev::h256 oldHashStateRoot = getGlobalStateRoot(&index); |
| 5142 | dev::h256 oldHashUTXORoot = getGlobalStateUTXO(&index); |
| 5143 | |
| 5144 | if (!ConnectBlock(block, state, &index, viewNew, chainparams, true)) { |
| 5145 | // printf("%s fail connectblock\n",__func__); |
| 5146 | if (index.nHeight >= chainparams.FirstSCBlock()) { |
| 5147 | setGlobalStateRoot(oldHashStateRoot); |
| 5148 | setGlobalStateUTXO(oldHashUTXORoot); |
| 5149 | pstorageresult->clearCacheResult(); |
| 5150 | } |
| 5151 | return false; |
| 5152 | } |
| 5153 | |
| 5154 | if (!state.IsValid()) { |
| 5155 | // printf("%s state invalid\n",__func__); |
| 5156 | return false; |
| 5157 | } |
| 5158 | // printf("%s everything fine here\n",__func__); |
| 5159 | return true; |
| 5160 | } |
| 5161 | |
| 5162 | |
| 5163 | bool AbortNode(const std::string& strMessage, const std::string& userMessage) |
no test coverage detected