Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,382 Lines • ▼ Show 20 Lines | |||||
* For context-dependent calls, see ContextualCheckBlockHeader. | * For context-dependent calls, see ContextualCheckBlockHeader. | ||||
*/ | */ | ||||
static bool CheckBlockHeader(const CBlockHeader &block, CValidationState &state, | static bool CheckBlockHeader(const CBlockHeader &block, CValidationState &state, | ||||
const Consensus::Params ¶ms, | const Consensus::Params ¶ms, | ||||
BlockValidationOptions validationOptions) { | BlockValidationOptions validationOptions) { | ||||
// Check proof of work matches claimed amount | // Check proof of work matches claimed amount | ||||
if (validationOptions.shouldValidatePoW() && | if (validationOptions.shouldValidatePoW() && | ||||
!CheckProofOfWork(block.GetHash(), block.nBits, params)) { | !CheckProofOfWork(block.GetHash(), block.nBits, params)) { | ||||
return state.DoS(50, false, REJECT_INVALID, "high-hash", false, | return state.DoS(100, false, REJECT_INVALID, "high-hash", false, | ||||
"proof of work failed"); | "proof of work failed"); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool CheckBlock(const CBlock &block, CValidationState &state, | bool CheckBlock(const CBlock &block, CValidationState &state, | ||||
const Consensus::Params ¶ms, | const Consensus::Params ¶ms, | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | if (fCheckpointsEnabled) { | ||||
error("%s: forked chain older than last checkpoint (height %d)", | error("%s: forked chain older than last checkpoint (height %d)", | ||||
__func__, nHeight), | __func__, nHeight), | ||||
REJECT_CHECKPOINT, "bad-fork-prior-to-checkpoint"); | REJECT_CHECKPOINT, "bad-fork-prior-to-checkpoint"); | ||||
} | } | ||||
} | } | ||||
// Check timestamp against prev | // Check timestamp against prev | ||||
if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) { | if (block.GetBlockTime() <= pindexPrev->GetMedianTimePast()) { | ||||
return state.Invalid(false, REJECT_INVALID, "time-too-old", | return state.DoS(100, false, REJECT_INVALID, "time-too-old", | ||||
"block's timestamp is too early"); | "block's timestamp is too early"); | ||||
} | } | ||||
// Check timestamp | // Check timestamp | ||||
if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME) { | if (block.GetBlockTime() > nAdjustedTime + MAX_FUTURE_BLOCK_TIME) { | ||||
return state.Invalid(false, REJECT_INVALID, "time-too-new", | return state.Invalid(false, REJECT_INVALID, "time-too-new", | ||||
"block timestamp too far in the future"); | "block timestamp too far in the future"); | ||||
} | } | ||||
// Reject outdated version blocks when 95% (75% on testnet) of the network | // Reject outdated version blocks when 95% (75% on testnet) of the network | ||||
// has upgraded: | // has upgraded: | ||||
// check for version 2, 3 and 4 upgrades | // check for version 2, 3 and 4 upgrades | ||||
if ((block.nVersion < 2 && nHeight >= consensusParams.BIP34Height) || | if ((block.nVersion < 2 && nHeight >= consensusParams.BIP34Height) || | ||||
(block.nVersion < 3 && nHeight >= consensusParams.BIP66Height) || | (block.nVersion < 3 && nHeight >= consensusParams.BIP66Height) || | ||||
(block.nVersion < 4 && nHeight >= consensusParams.BIP65Height)) { | (block.nVersion < 4 && nHeight >= consensusParams.BIP65Height)) { | ||||
return state.Invalid( | return state.DoS( | ||||
false, REJECT_OBSOLETE, | 100, false, REJECT_OBSOLETE, | ||||
strprintf("bad-version(0x%08x)", block.nVersion), | strprintf("bad-version(0x%08x)", block.nVersion), false, | ||||
strprintf("rejected nVersion=0x%08x block", block.nVersion)); | strprintf("rejected nVersion=0x%08x block", block.nVersion)); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool ContextualCheckTransactionForCurrentBlock(const Consensus::Params ¶ms, | bool ContextualCheckTransactionForCurrentBlock(const Consensus::Params ¶ms, | ||||
const CTransaction &tx, | const CTransaction &tx, | ||||
▲ Show 20 Lines • Show All 2,043 Lines • Show Last 20 Lines |