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:
Martin Zumsande 2025-10-06 16:07:19 -04:00
parent a33bd767a3
commit 419ff388b9
1 changed files with 6 additions and 0 deletions

View File

@ -2956,6 +2956,12 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, Peer& peer,
state, &pindexLast)};
if (!processed) {
if (state.IsInvalid()) {
if (!pfrom.IsInboundConn() && state.GetResult() == BlockValidationResult::BLOCK_CACHED_INVALID) {
LogWarning("Header received from peer=%i was previously marked as invalid. "
"If this happens with all peers, database corruption is likely and "
"-reindex may be necessary to recover.",
pfrom.GetId());
}
MaybePunishNodeForBlock(pfrom.GetId(), state, via_compact_block, "invalid header received");
return;
}