Skip to content

Commit 24133b1

Browse files
committed
Merge #12561: Check for block corruption in ConnectBlock()
0e7c52d Shut down if trying to connect a corrupted block (Suhas Daftuar) Pull request description: (Updated OP after reworking the approach) Shut down if a corrupted block is found in ConnectBlock(). This prevents an infinite loop trying to connect such a block, and alerts the node operator that there may be potential hardware failure. Tree-SHA512: f20d56aa9d36d6eeff4c3d13c0fbd14f06a57701bd13c2416d36f0cc4235f81f752139e336a073617e8e803782c5096c960108af122b19a51227de512e9095ee
2 parents 3190785 + 0e7c52d commit 24133b1

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
@@ -1793,8 +1793,15 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
17931793
// is enforced in ContextualCheckBlockHeader(); we wouldn't want to
17941794
// re-enforce that rule here (at least until we make it impossible for
17951795
// GetAdjustedTime() to go backward).
1796-
if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck))
1796+
if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck)) {
1797+
if (state.CorruptionPossible()) {
1798+
// We don't write down blocks to disk if they may have been
1799+
// corrupted, so this should be impossible unless we're having hardware
1800+
// problems.
1801+
return AbortNode(state, "Corrupt block found indicating potential hardware failure; shutting down");
1802+
}
17971803
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
1804+
}
17981805

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

0 commit comments

Comments
 (0)