Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 3,178 Lines • ▼ Show 20 Lines | static bool CheckIndexAgainstCheckpoint(const CBlockIndex *pindexPrev, | ||||
return true; | return true; | ||||
} | } | ||||
bool ContextualCheckBlockHeader(const CBlockHeader &block, | bool ContextualCheckBlockHeader(const CBlockHeader &block, | ||||
CValidationState &state, | CValidationState &state, | ||||
const Consensus::Params &consensusParams, | const Consensus::Params &consensusParams, | ||||
const CBlockIndex *pindexPrev, | const CBlockIndex *pindexPrev, | ||||
int64_t nAdjustedTime) { | int64_t nAdjustedTime) { | ||||
const int nHeight = pindexPrev == NULL ? 0 : pindexPrev->nHeight + 1; | const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; | ||||
// Check proof of work | // Check proof of work | ||||
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, consensusParams)) | if (block.nBits != | ||||
GetNextWorkRequired(pindexPrev, &block, consensusParams)) { | |||||
return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, | return state.DoS(100, false, REJECT_INVALID, "bad-diffbits", false, | ||||
"incorrect proof of work"); | "incorrect proof of work"); | ||||
} | |||||
// 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.Invalid(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 + 2 * 60 * 60) | if (block.GetBlockTime() > nAdjustedTime + 2 * 60 * 60) { | ||||
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.Invalid( | ||||
false, REJECT_OBSOLETE, | false, REJECT_OBSOLETE, | ||||
strprintf("bad-version(0x%08x)", block.nVersion), | strprintf("bad-version(0x%08x)", block.nVersion), | ||||
strprintf("rejected nVersion=0x%08x block", block.nVersion)); | strprintf("rejected nVersion=0x%08x block", block.nVersion)); | ||||
} | |||||
return true; | return true; | ||||
} | } | ||||
bool ContextualCheckTransaction(const Config &config, const CTransaction &tx, | bool ContextualCheckTransaction(const Config &config, const CTransaction &tx, | ||||
CValidationState &state, | CValidationState &state, | ||||
const Consensus::Params &consensusParams, | const Consensus::Params &consensusParams, | ||||
int nHeight, int64_t nLockTimeCutoff, | int nHeight, int64_t nLockTimeCutoff, | ||||
▲ Show 20 Lines • Show All 1,575 Lines • Show Last 20 Lines |