Skip to content

Commit 0e7c52d

Browse files
committed
Shut down if trying to connect a corrupted block
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 9e2ed25 commit 0e7c52d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/validation.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1791,8 +1791,15 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
17911791
// is enforced in ContextualCheckBlockHeader(); we wouldn't want to
17921792
// re-enforce that rule here (at least until we make it impossible for
17931793
// GetAdjustedTime() to go backward).
1794-
if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck))
1794+
if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck)) {
1795+
if (state.CorruptionPossible()) {
1796+
// We don't write down blocks to disk if they may have been
1797+
// corrupted, so this should be impossible unless we're having hardware
1798+
// problems.
1799+
return AbortNode(state, "Corrupt block found indicating potential hardware failure; shutting down");
1800+
}
17951801
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
1802+
}
17961803

17971804
// verify that the view's current state corresponds to the previous block
17981805
uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256() : pindex->pprev->GetBlockHash();

0 commit comments

Comments
 (0)