Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,125 Lines • ▼ Show 20 Lines | if (fCheckPOW && | ||||
"proof of work failed"); | "proof of work failed"); | ||||
return true; | return true; | ||||
} | } | ||||
bool CheckBlock(const Config &config, const CBlock &block, | bool CheckBlock(const Config &config, const CBlock &block, | ||||
CValidationState &state, | CValidationState &state, | ||||
const Consensus::Params &consensusParams, bool fCheckPOW, | const Consensus::Params &consensusParams, bool fCheckPOW, | ||||
bool fCheckMerkleRoot) { | bool fCheckMerkleRoot, bool fCheckExcessive) { | ||||
// These are checks that are independent of context. | // These are checks that are independent of context. | ||||
if (block.fChecked) { | if (block.fChecked) { | ||||
return true; | return true; | ||||
} | } | ||||
// Check that the header is valid (particularly PoW). This is mostly | // Check that the header is valid (particularly PoW). This is mostly | ||||
// redundant with the call in AcceptBlockHeader. | // redundant with the call in AcceptBlockHeader. | ||||
if (!CheckBlockHeader(block, state, consensusParams, fCheckPOW)) { | if (!CheckBlockHeader(block, state, consensusParams, fCheckPOW)) { | ||||
Show All 25 Lines | bool CheckBlock(const Config &config, const CBlock &block, | ||||
// First transaction must be coinbase. | // First transaction must be coinbase. | ||||
if (block.vtx.empty()) { | if (block.vtx.empty()) { | ||||
return state.DoS(100, false, REJECT_INVALID, "bad-cb-missing", false, | return state.DoS(100, false, REJECT_INVALID, "bad-cb-missing", false, | ||||
"first tx is not coinbase"); | "first tx is not coinbase"); | ||||
} | } | ||||
// Size limits. | // Size limits. | ||||
auto nMaxBlockSize = config.GetMaxBlockSize(); | auto nMaxBlockSize = config.GetMaxBlockSize(); | ||||
if (fCheckExcessive) { | |||||
// 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.Excessive(10, false, REJECT_INVALID, "bad-blk-length", | return state.Excessive(10, false, REJECT_INVALID, "bad-blk-length", | ||||
false, "size limits failed"); | false, "size limits failed"); | ||||
} | } | ||||
} | |||||
auto currentBlockSize = | auto currentBlockSize = | ||||
::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION); | ::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION); | ||||
if (fCheckExcessive) { | |||||
if (currentBlockSize > nMaxBlockSize) { | if (currentBlockSize > nMaxBlockSize) { | ||||
return state.Excessive(10, false, REJECT_INVALID, "bad-blk-length", | return state.Excessive(10, false, REJECT_INVALID, "bad-blk-length", | ||||
false, "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(), | ||||
state.GetDebugMessage())); | state.GetDebugMessage())); | ||||
▲ Show 20 Lines • Show All 1,829 Lines • Show Last 20 Lines |