Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
| Show First 20 Lines • Show All 2,500 Lines • ▼ Show 20 Lines | do { | ||||
| bool fInvalidAncestor = false; | bool fInvalidAncestor = false; | ||||
| while (pindexTest && !chainActive.Contains(pindexTest)) { | while (pindexTest && !chainActive.Contains(pindexTest)) { | ||||
| assert(pindexTest->nChainTx || pindexTest->nHeight == 0); | assert(pindexTest->nChainTx || pindexTest->nHeight == 0); | ||||
| // Pruned nodes may have entries in setBlockIndexCandidates for | // Pruned nodes may have entries in setBlockIndexCandidates for | ||||
| // which block files have been deleted. Remove those as candidates | // which block files have been deleted. Remove those as candidates | ||||
| // for the most work chain if we come across them; we can't switch | // for the most work chain if we come across them; we can't switch | ||||
| // to a chain unless we have all the non-active-chain parent blocks. | // to a chain unless we have all the non-active-chain parent blocks. | ||||
| bool fFailedChain = pindexTest->nStatus & BLOCK_FAILED_MASK; | bool fFailedChain = pindexTest->nStatus & BLOCK_NOT_VALID_MASK; | ||||
| bool fMissingData = !(pindexTest->nStatus & BLOCK_HAVE_DATA); | bool fMissingData = !(pindexTest->nStatus & BLOCK_HAVE_DATA); | ||||
| if (fFailedChain || fMissingData) { | if (fFailedChain || fMissingData) { | ||||
| // Candidate chain is not usable (either invalid or missing | // Candidate chain is not usable (either invalid or missing | ||||
| // data) | // data) | ||||
deadalnix: This comment is not accurate anymore. | |||||
| if (fFailedChain && | if (fFailedChain && | ||||
| (pindexBestInvalid == nullptr || | (pindexBestInvalid == nullptr || | ||||
| pindexNew->nChainWork > pindexBestInvalid->nChainWork)) | pindexNew->nChainWork > pindexBestInvalid->nChainWork)) | ||||
| pindexBestInvalid = pindexNew; | pindexBestInvalid = pindexNew; | ||||
| CBlockIndex *pindexFailed = pindexNew; | CBlockIndex *pindexFailed = pindexNew; | ||||
| // Remove the entire chain from the set. | // Remove the entire chain from the set. | ||||
| while (pindexTest != pindexFailed) { | while (pindexTest != pindexFailed) { | ||||
| if (fFailedChain) { | if (fFailedChain) { | ||||
| ▲ Show 20 Lines • Show All 617 Lines • ▼ Show 20 Lines | if (block.vtx.empty()) { | ||||
| "first tx is not coinbase"); | "first tx is not coinbase"); | ||||
| } | } | ||||
| // Size limits. | // Size limits. | ||||
| auto nMaxBlockSize = config.GetMaxBlockSize(); | auto nMaxBlockSize = config.GetMaxBlockSize(); | ||||
| // Bail early if there is no way this block is of reasonable size. | // Bail early if there is no way this block is of reasonable size. | ||||
| if ((block.vtx.size() * MIN_TRANSACTION_SIZE) > nMaxBlockSize) { | if ((block.vtx.size() * MIN_TRANSACTION_SIZE) > nMaxBlockSize) { | ||||
| return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, | return state.Excessive(10, false, REJECT_INVALID, "bad-blk-length", | ||||
| "size limits failed"); | false, "size limits failed"); | ||||
| } | } | ||||
| auto currentBlockSize = | auto currentBlockSize = | ||||
| ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION); | ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION); | ||||
| if (currentBlockSize > nMaxBlockSize) { | if (currentBlockSize > nMaxBlockSize) { | ||||
| return state.DoS(100, false, REJECT_INVALID, "bad-blk-length", false, | return state.Excessive(10, false, REJECT_INVALID, "bad-blk-length", | ||||
| "size limits failed"); | false, "size limits failed"); | ||||
| } | } | ||||
| // And a valid coinbase. | // And a valid coinbase. | ||||
| if (!CheckCoinbase(*block.vtx[0], state, false)) { | if (!CheckCoinbase(*block.vtx[0], state, false)) { | ||||
| return state.Invalid(false, state.GetRejectCode(), | return state.Invalid(false, state.GetRejectCode(), | ||||
| state.GetRejectReason(), | state.GetRejectReason(), | ||||
| strprintf("Coinbase check failed (txid %s) %s", | strprintf("Coinbase check failed (txid %s) %s", | ||||
| block.vtx[0]->GetId().ToString(), | block.vtx[0]->GetId().ToString(), | ||||
| ▲ Show 20 Lines • Show All 381 Lines • ▼ Show 20 Lines | static bool AcceptBlock(const Config &config, | ||||
| const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
| if (!CheckBlock(config, block, state, chainparams.GetConsensus()) || | if (!CheckBlock(config, block, state, chainparams.GetConsensus()) || | ||||
| !ContextualCheckBlock(config, block, state, chainparams.GetConsensus(), | !ContextualCheckBlock(config, block, state, chainparams.GetConsensus(), | ||||
| pindex->pprev)) { | pindex->pprev)) { | ||||
| if (state.IsInvalid() && !state.CorruptionPossible()) { | if (state.IsInvalid() && !state.CorruptionPossible()) { | ||||
| pindex->nStatus |= BLOCK_FAILED_VALID; | pindex->nStatus |= BLOCK_FAILED_VALID; | ||||
| setDirtyBlockIndex.insert(pindex); | setDirtyBlockIndex.insert(pindex); | ||||
| } else if (state.IsExcessive() && !state.CorruptionPossible()) { | |||||
| pindex->nStatus |= BLOCK_EXCESSIVE; | |||||
| setDirtyBlockIndex.insert(pindex); | |||||
| } | } | ||||
deadalnixUnsubmitted Not Done Inline ActionsThis should be refactored to use IsNotValid. The only thing that differs between the 2 is the flag added to nStatus so that can be a different check. deadalnix: This should be refactored to use IsNotValid. The only thing that differs between the 2 is the… | |||||
| return error("%s: %s (block %s)", __func__, FormatStateMessage(state), | return error("%s: %s (block %s)", __func__, FormatStateMessage(state), | ||||
| block.GetHash().ToString()); | block.GetHash().ToString()); | ||||
| } | } | ||||
| // Header is valid/has work, merkle tree and segwit merkle tree are | // Header is valid/has work, merkle tree and segwit merkle tree are | ||||
| // good...RELAY NOW (but if it does not build on our best tip, let the | // good...RELAY NOW (but if it does not build on our best tip, let the | ||||
| // SendMessages loop relay it) | // SendMessages loop relay it) | ||||
| if (!IsInitialBlockDownload() && chainActive.Tip() == pindex->pprev) { | if (!IsInitialBlockDownload() && chainActive.Tip() == pindex->pprev) { | ||||
| ▲ Show 20 Lines • Show All 1,401 Lines • Show Last 20 Lines | |||||
This comment is not accurate anymore.