Skip to content

Commit d3243c1

Browse files
authored
backport: Shut down if trying to connect a corrupted block (#1126)
Manual backport of bitcoin#0e7c52dc6cbb8fd881a0dd57a6167a812fe71dc4 Fixes issue #1087 Commit message by author sdaftuar: The call to CheckBlock() in ConnectBlock() is redundant with calls to it prior to storing a block on disk. If CheckBlock() fails with an error indicating the block is potentially corrupted, then shut down immediately, as this is an indication that the node is experiencing hardware issues. (If we didn't shut down, we could go into an infinite loop trying to reconnect this same bad block, as we're not setting the block's status to FAILED in the case where there is potential corruption.) If CheckBlock() fails for some other reason, we'll end up flagging this block as bad (perhaps some prior software version "let a bad block in", as the comment indicates), and not trying to connect it again, so this case should be properly handled.
1 parent 260f3c7 commit d3243c1

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/validation.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -2416,9 +2416,15 @@ static bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockInd
24162416
int64_t nTimeStart = GetTimeMicros();
24172417

24182418
// Check it again in case a previous version let a bad block in
2419-
if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck)) // Force the check of asset duplicates when connecting the block
2419+
if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck)) { // Force the check of asset duplicates when connecting the block
2420+
if (state.CorruptionPossible()) {
2421+
// We don't write down blocks to disk if they may have been
2422+
// corrupted, so this should be impossible unless we're having hardware
2423+
// problems.
2424+
return AbortNode(state, "Corrupt block found indicating potential hardware failure; shutting down");
2425+
}
24202426
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
2421-
2427+
}
24222428
// verify that the view's current state corresponds to the previous block
24232429
uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256() : pindex->pprev->GetBlockHash();
24242430
assert(hashPrevBlock == view.GetBestBlock());

0 commit comments

Comments
 (0)