Merge pull request #2286 from rnicoll/1.14.4-improve-checkblock-failure
Shut down if trying to connect a corrupted block
This commit is contained in:
commit
097d87df2f
|
@ -1778,8 +1778,28 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
|
||||||
int64_t nTimeStart = GetTimeMicros();
|
int64_t nTimeStart = GetTimeMicros();
|
||||||
|
|
||||||
// Check it again in case a previous version let a bad block in
|
// Check it again in case a previous version let a bad block in
|
||||||
if (!CheckBlock(block, state, !fJustCheck, !fJustCheck))
|
// NOTE: We don't currently (re-)invoke ContextualCheckBlock() or
|
||||||
|
// ContextualCheckBlockHeader() here. This means that if we add a new
|
||||||
|
// consensus rule that is enforced in one of those two functions, then we
|
||||||
|
// may have let in a block that violates the rule prior to updating the
|
||||||
|
// software, and we would NOT be enforcing the rule here. Fully solving
|
||||||
|
// upgrade from one software version to the next after a consensus rule
|
||||||
|
// change is potentially tricky and issue-specific (see RewindBlockIndex()
|
||||||
|
// for one general approach that was used for BIP 141 deployment).
|
||||||
|
// Also, currently the rule against blocks more than 2 hours in the future
|
||||||
|
// 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, !fJustCheck, !fJustCheck)) {
|
||||||
|
if (state.CorruptionPossible()) {
|
||||||
|
LogPrintf("%s: Attempt to connect corrupted block %s.\n", __func__, block.GetHash().ToString());
|
||||||
|
// 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));
|
return error("%s: Consensus::CheckBlock: %s", __func__, FormatStateMessage(state));
|
||||||
|
}
|
||||||
|
|
||||||
// verify that the view's current state corresponds to the previous block
|
// verify that the view's current state corresponds to the previous block
|
||||||
uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash();
|
uint256 hashPrevBlock = pindex->pprev == NULL ? uint256() : pindex->pprev->GetBlockHash();
|
||||||
|
|
Loading…
Reference in a new issue