Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 1,141 Lines • ▼ Show 20 Lines | bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, | ||||
try { | try { | ||||
filein >> block; | filein >> block; | ||||
} catch (const std::exception &e) { | } catch (const std::exception &e) { | ||||
return error("%s: Deserialize or I/O error - %s at %s", __func__, | return error("%s: Deserialize or I/O error - %s at %s", __func__, | ||||
e.what(), pos.ToString()); | e.what(), pos.ToString()); | ||||
} | } | ||||
// Check the header | // Check the header | ||||
if (!CheckProofOfWork(block.GetHash(), block.nBits, | if (!CheckProofOfWork(block.GetHash(), block.nBits, config)) { | ||||
config.GetChainParams().GetConsensus())) { | |||||
return error("ReadBlockFromDisk: Errors in block header at %s", | return error("ReadBlockFromDisk: Errors in block header at %s", | ||||
pos.ToString()); | pos.ToString()); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool ReadBlockFromDisk(CBlock &block, const CBlockIndex *pindex, | bool ReadBlockFromDisk(CBlock &block, const CBlockIndex *pindex, | ||||
▲ Show 20 Lines • Show All 2,030 Lines • ▼ Show 20 Lines | if (nNewChunks > nOldChunks) { | ||||
return state.Error("out of disk space"); | return state.Error("out of disk space"); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
static bool CheckBlockHeader(const Config &config, const CBlockHeader &block, | static bool CheckBlockHeader(const Config &config, const CBlockHeader &block, | ||||
CValidationState &state, bool fCheckPOW = true) { | CValidationState &state, bool fCheckPOW = true) { | ||||
const Consensus::Params &consensusParams = | |||||
config.GetChainParams().GetConsensus(); | |||||
// Check proof of work matches claimed amount | // Check proof of work matches claimed amount | ||||
if (fCheckPOW && | if (fCheckPOW && !CheckProofOfWork(block.GetHash(), block.nBits, config)) { | ||||
!CheckProofOfWork(block.GetHash(), block.nBits, consensusParams)) { | |||||
return state.DoS(50, false, REJECT_INVALID, "high-hash", false, | return state.DoS(50, false, REJECT_INVALID, "high-hash", false, | ||||
"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, | ||||
▲ Show 20 Lines • Show All 137 Lines • ▼ Show 20 Lines | static bool ContextualCheckBlockHeader(const Config &config, | ||||
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; | const int nHeight = pindexPrev == nullptr ? 0 : pindexPrev->nHeight + 1; | ||||
// Check proof of work | // Check proof of work | ||||
if (block.nBits != | if (block.nBits != GetNextWorkRequired(pindexPrev, &block, config)) { | ||||
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"); | ||||
▲ Show 20 Lines • Show All 1,709 Lines • Show Last 20 Lines |