Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 942 Lines • ▼ Show 20 Lines | LogPrintf("%s: current best=%s height=%d log2_work=%.8g date=%s\n", | ||||
__func__, tip->GetBlockHash().ToString(), | __func__, tip->GetBlockHash().ToString(), | ||||
::ChainActive().Height(), | ::ChainActive().Height(), | ||||
log(tip->nChainWork.getdouble()) / log(2.0), | log(tip->nChainWork.getdouble()) / log(2.0), | ||||
FormatISO8601DateTime(tip->GetBlockTime())); | FormatISO8601DateTime(tip->GetBlockTime())); | ||||
} | } | ||||
void CChainState::InvalidBlockFound(CBlockIndex *pindex, | void CChainState::InvalidBlockFound(CBlockIndex *pindex, | ||||
const CValidationState &state) { | const CValidationState &state) { | ||||
if (!state.CorruptionPossible()) { | if (state.GetReason() != ValidationInvalidReason::BLOCK_MUTATED) { | ||||
pindex->nStatus = pindex->nStatus.withFailed(); | pindex->nStatus = pindex->nStatus.withFailed(); | ||||
m_failed_blocks.insert(pindex); | m_failed_blocks.insert(pindex); | ||||
setDirtyBlockIndex.insert(pindex); | setDirtyBlockIndex.insert(pindex); | ||||
InvalidChainFound(pindex); | InvalidChainFound(pindex); | ||||
} | } | ||||
} | } | ||||
void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, | void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, | ||||
▲ Show 20 Lines • Show All 544 Lines • ▼ Show 20 Lines | bool CChainState::ConnectBlock(const CBlock &block, CValidationState &state, | ||||
// change is potentially tricky and issue-specific. | // change is potentially tricky and issue-specific. | ||||
// Also, currently the rule against blocks more than 2 hours in the future | // Also, currently the rule against blocks more than 2 hours in the future | ||||
// is enforced in ContextualCheckBlockHeader(); we wouldn't want to | // is enforced in ContextualCheckBlockHeader(); we wouldn't want to | ||||
// re-enforce that rule here (at least until we make it impossible for | // re-enforce that rule here (at least until we make it impossible for | ||||
// GetAdjustedTime() to go backward). | // GetAdjustedTime() to go backward). | ||||
if (!CheckBlock(block, state, consensusParams, | if (!CheckBlock(block, state, consensusParams, | ||||
options.withCheckPoW(!fJustCheck) | options.withCheckPoW(!fJustCheck) | ||||
.withCheckMerkleRoot(!fJustCheck))) { | .withCheckMerkleRoot(!fJustCheck))) { | ||||
if (state.CorruptionPossible()) { | if (state.GetReason() == ValidationInvalidReason::BLOCK_MUTATED) { | ||||
// We don't write down blocks to disk if they may have been | // We don't write down blocks to disk if they may have been | ||||
// corrupted, so this should be impossible unless we're having | // corrupted, so this should be impossible unless we're having | ||||
// hardware problems. | // hardware problems. | ||||
return AbortNode(state, "Corrupt block found indicating potential " | return AbortNode(state, "Corrupt block found indicating potential " | ||||
"hardware failure; shutting down"); | "hardware failure; shutting down"); | ||||
} | } | ||||
return error("%s: Consensus::CheckBlock: %s", __func__, | return error("%s: Consensus::CheckBlock: %s", __func__, | ||||
FormatStateMessage(state)); | FormatStateMessage(state)); | ||||
▲ Show 20 Lines • Show All 1,151 Lines • ▼ Show 20 Lines | while (fContinue && nHeight != pindexMostWork->nHeight) { | ||||
for (CBlockIndex *pindexConnect : reverse_iterate(vpindexToConnect)) { | for (CBlockIndex *pindexConnect : reverse_iterate(vpindexToConnect)) { | ||||
if (!ConnectTip(config, state, pindexConnect, | if (!ConnectTip(config, state, pindexConnect, | ||||
pindexConnect == pindexMostWork | pindexConnect == pindexMostWork | ||||
? pblock | ? pblock | ||||
: std::shared_ptr<const CBlock>(), | : std::shared_ptr<const CBlock>(), | ||||
connectTrace, disconnectpool)) { | connectTrace, disconnectpool)) { | ||||
if (state.IsInvalid()) { | if (state.IsInvalid()) { | ||||
// The block violates a consensus rule. | // The block violates a consensus rule. | ||||
if (!state.CorruptionPossible()) { | if (state.GetReason() != | ||||
ValidationInvalidReason::BLOCK_MUTATED) { | |||||
InvalidChainFound(vpindexToConnect.back()); | InvalidChainFound(vpindexToConnect.back()); | ||||
} | } | ||||
state = CValidationState(); | state = CValidationState(); | ||||
fInvalidFound = true; | fInvalidFound = true; | ||||
fContinue = false; | fContinue = false; | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,307 Lines • ▼ Show 20 Lines | bool CChainState::AcceptBlock(const Config &config, | ||||
} | } | ||||
const CChainParams &chainparams = config.GetChainParams(); | const CChainParams &chainparams = config.GetChainParams(); | ||||
const Consensus::Params &consensusParams = chainparams.GetConsensus(); | const Consensus::Params &consensusParams = chainparams.GetConsensus(); | ||||
if (!CheckBlock(block, state, consensusParams, | if (!CheckBlock(block, state, consensusParams, | ||||
BlockValidationOptions(config)) || | BlockValidationOptions(config)) || | ||||
!ContextualCheckBlock(block, state, consensusParams, pindex->pprev)) { | !ContextualCheckBlock(block, state, consensusParams, pindex->pprev)) { | ||||
if (state.IsInvalid() && !state.CorruptionPossible()) { | if (state.IsInvalid() && | ||||
state.GetReason() != ValidationInvalidReason::BLOCK_MUTATED) { | |||||
pindex->nStatus = pindex->nStatus.withFailed(); | pindex->nStatus = pindex->nStatus.withFailed(); | ||||
setDirtyBlockIndex.insert(pindex); | setDirtyBlockIndex.insert(pindex); | ||||
} | } | ||||
return error("%s: %s (block %s)", __func__, FormatStateMessage(state), | return error("%s: %s (block %s)", __func__, FormatStateMessage(state), | ||||
block.GetHash().ToString()); | block.GetHash().ToString()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,638 Lines • Show Last 20 Lines |