Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 4,007 Lines • ▼ Show 20 Lines | if (!fRequested) { | ||||
// If our tip is behind, a peer could try to send us | // If our tip is behind, a peer could try to send us | ||||
// low-work blocks on a fake chain that we would never | // low-work blocks on a fake chain that we would never | ||||
// request; don't process these. | // request; don't process these. | ||||
if (pindex->nChainWork < nMinimumChainWork) { | if (pindex->nChainWork < nMinimumChainWork) { | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
if (fNewBlock) { | |||||
*fNewBlock = true; | |||||
} | |||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
if (!CheckBlock(config, block, state, BlockValidationOptions(config)) || | if (!CheckBlock(config, block, state, BlockValidationOptions(config)) || | ||||
!ContextualCheckBlock(block, state, chainparams.GetConsensus(), | !ContextualCheckBlock(block, state, chainparams.GetConsensus(), | ||||
pindex->pprev)) { | pindex->pprev)) { | ||||
if (state.IsInvalid() && !state.CorruptionPossible()) { | if (state.IsInvalid() && !state.CorruptionPossible()) { | ||||
pindex->nStatus = pindex->nStatus.withFailed(); | pindex->nStatus = pindex->nStatus.withFailed(); | ||||
setDirtyBlockIndex.insert(pindex); | setDirtyBlockIndex.insert(pindex); | ||||
Show All 20 Lines | bool CChainState::AcceptBlock(const Config &config, | ||||
// Header is valid/has work and the merkle tree is good. | // Header is valid/has work and the merkle tree is good. | ||||
// Relay now, but if it does not build on our best tip, let the | // Relay now, but if it does not build on our best tip, let the | ||||
// SendMessages loop relay it. | // SendMessages loop relay it. | ||||
if (!IsInitialBlockDownload() && chainActive.Tip() == pindex->pprev) { | if (!IsInitialBlockDownload() && chainActive.Tip() == pindex->pprev) { | ||||
GetMainSignals().NewPoWValidBlock(pindex, pblock); | GetMainSignals().NewPoWValidBlock(pindex, pblock); | ||||
} | } | ||||
// Write block to history file | // Write block to history file | ||||
if (fNewBlock) { | |||||
*fNewBlock = true; | |||||
} | |||||
try { | try { | ||||
FlatFilePos blockPos = | FlatFilePos blockPos = | ||||
SaveBlockToDisk(block, pindex->nHeight, chainparams, dbp); | SaveBlockToDisk(block, pindex->nHeight, chainparams, dbp); | ||||
if (blockPos.IsNull()) { | if (blockPos.IsNull()) { | ||||
state.Error(strprintf( | state.Error(strprintf( | ||||
"%s: Failed to find position to write new block to disk", | "%s: Failed to find position to write new block to disk", | ||||
__func__)); | __func__)); | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 1,654 Lines • Show Last 20 Lines |