mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 23:03:45 +01:00
p2p: Add warning message when receiving headers for blocks cached as invalid
Currently, if database corruption leads to a block being marked as invalid incorrectly, we can get stuck in an infinite headerssync loop with no indication what went wrong or how to fix it. With the added log message, users will receive an explicit warning after each failed headerssync attempt with an outbound peer.
This commit is contained in:
@@ -2955,6 +2955,13 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
|
||||
state, &pindexLast)};
|
||||
if (!processed) {
|
||||
if (state.IsInvalid()) {
|
||||
if (!pfrom.IsInboundConn() && state.GetResult() == BlockValidationResult::BLOCK_CACHED_INVALID) {
|
||||
// Warn user if outgoing peers send us headers of blocks that we previously marked as invalid.
|
||||
LogWarning("%s (received from peer=%i). "
|
||||
"If this happens with all peers, consider database corruption (that -reindex may fix) "
|
||||
"or a potential consensus incompatibility.",
|
||||
state.GetDebugMessage(), pfrom.GetId());
|
||||
}
|
||||
MaybePunishNodeForBlock(pfrom.GetId(), state, via_compact_block, "invalid header received");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4244,7 +4244,8 @@ bool ChainstateManager::AcceptBlockHeader(const CBlockHeader& block, BlockValida
|
||||
*ppindex = pindex;
|
||||
if (pindex->nStatus & BLOCK_FAILED_MASK) {
|
||||
LogDebug(BCLog::VALIDATION, "%s: block %s is marked invalid\n", __func__, hash.ToString());
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CACHED_INVALID, "duplicate-invalid");
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CACHED_INVALID, "duplicate-invalid",
|
||||
strprintf("block %s was previously marked invalid", hash.ToString()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user