aboutsummaryrefslogtreecommitdiff
path: root/src/validation.cpp
diff options
context:
space:
mode:
authorSuhas Daftuar <[email protected]>2018-03-05 10:42:26 -0500
committerSuhas Daftuar <[email protected]>2018-03-05 10:51:29 -0500
commit0e7c52dc6cbb8fd881a0dd57a6167a812fe71dc4 (patch)
treeb6b91027ec3b8e27f8177f2e8c9ee6b82f681b14 /src/validation.cpp
parentMerge #12556: [Trivial] fix version typo in getpeerinfo RPC call help (diff)
downloaddiscoin-0e7c52dc6cbb8fd881a0dd57a6167a812fe71dc4.tar.xz
discoin-0e7c52dc6cbb8fd881a0dd57a6167a812fe71dc4.zip
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.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r--src/validation.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/validation.cpp b/src/validation.cpp
index d2438b060..8ec30cac3 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1791,8 +1791,15 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
// is enforced in ContextualCheckBlockHeader(); we wouldn't want to
// re-enforce that rule here (at least until we make it impossible for
// GetAdjustedTime() to go backward).
- if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck))
+ if (!CheckBlock(block, state, chainparams.GetConsensus(), !fJustCheck, !fJustCheck)) {
+ if (state.CorruptionPossible()) {
+ // We don't write down blocks to disk if they may have been
+ // corrupted, so this should be impossible unless we're having hardware
+ // problems.
+ return AbortNode(state, "Corrupt block found indicating potential hardware failure; shutting down");
+ }
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
+ }
// verify that the view's current state corresponds to the previous block
uint256 hashPrevBlock = pindex->pprev == nullptr ? uint256() : pindex->pprev->GetBlockHash();