Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,636 Lines • ▼ Show 20 Lines | |||||
* represented by coins. Validity checks that depend on the UTXO set are also | * represented by coins. Validity checks that depend on the UTXO set are also | ||||
* done; ConnectBlock() can fail if those validity checks fail (among other | * done; ConnectBlock() can fail if those validity checks fail (among other | ||||
* reasons). | * reasons). | ||||
*/ | */ | ||||
static bool ConnectBlock(const Config &config, const CBlock &block, | static bool ConnectBlock(const Config &config, const CBlock &block, | ||||
CValidationState &state, CBlockIndex *pindex, | CValidationState &state, CBlockIndex *pindex, | ||||
CCoinsViewCache &view, bool fJustCheck = false) { | CCoinsViewCache &view, bool fJustCheck = false) { | ||||
AssertLockHeld(cs_main); | AssertLockHeld(cs_main); | ||||
assert(pindex); | |||||
// pindex->phashBlock can be null if called by | |||||
// CreateNewBlock/TestBlockValidity | |||||
assert((pindex->phashBlock == nullptr) || | |||||
(*pindex->phashBlock == block.GetHash())); | |||||
int64_t nTimeStart = GetTimeMicros(); | int64_t nTimeStart = GetTimeMicros(); | ||||
// Check it again in case a previous version let a bad block in | // Check it again in case a previous version let a bad block in | ||||
BlockValidationOptions validationOptions = | BlockValidationOptions validationOptions = | ||||
BlockValidationOptions(!fJustCheck, !fJustCheck); | BlockValidationOptions(!fJustCheck, !fJustCheck); | ||||
if (!CheckBlock(config, block, state, validationOptions)) { | if (!CheckBlock(config, block, state, validationOptions)) { | ||||
return error("%s: Consensus::CheckBlock: %s", __func__, | return error("%s: Consensus::CheckBlock: %s", __func__, | ||||
FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
▲ Show 20 Lines • Show All 1,907 Lines • ▼ Show 20 Lines | |||||
static bool ContextualCheckBlockHeader(const Config &config, | static bool ContextualCheckBlockHeader(const Config &config, | ||||
const CBlockHeader &block, | const CBlockHeader &block, | ||||
CValidationState &state, | CValidationState &state, | ||||
const CBlockIndex *pindexPrev, | const CBlockIndex *pindexPrev, | ||||
int64_t nAdjustedTime) { | int64_t nAdjustedTime) { | ||||
const Consensus::Params &consensusParams = | const Consensus::Params &consensusParams = | ||||
config.GetChainParams().GetConsensus(); | config.GetChainParams().GetConsensus(); | ||||
const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; | assert(pindexPrev != nullptr); | ||||
const int nHeight = pindexPrev->nHeight + 1; | |||||
// Check proof of work | // Check proof of work | ||||
if (block.nBits != GetNextWorkRequired(pindexPrev, &block, config)) { | if (block.nBits != GetNextWorkRequired(pindexPrev, &block, config)) { | ||||
LogPrintf("bad bits after height: %d\n", pindexPrev->nHeight); | LogPrintf("bad bits after height: %d\n", pindexPrev->nHeight); | ||||
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"); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,004 Lines • Show Last 20 Lines |