MCPcopy Create free account
hub / github.com/LUX-Core/lux / TestBlockValidity

Function TestBlockValidity

src/main.cpp:5109–5160  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5107}
5108
5109bool 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
5163bool AbortNode(const std::string& strMessage, const std::string& userMessage)

Callers 3

CreateNewBlockMethod · 0.85
getblocktemplateFunction · 0.85
submitblockFunction · 0.85

Calls 15

errorFunction · 0.85
FormatStateMessageFunction · 0.85
ContextualCheckBlockFunction · 0.85
getGlobalStateRootFunction · 0.85
getGlobalStateUTXOFunction · 0.85
ConnectBlockFunction · 0.85
setGlobalStateRootFunction · 0.85
setGlobalStateUTXOFunction · 0.85
TipMethod · 0.80
CheckProofMethod · 0.80
FirstSCBlockMethod · 0.80

Tested by

no test coverage detected