validation: Reword CheckForkWarningConditions and call it also during IBD and at startup
What changed, and why it matters
This Bitcoin Core commit changes when and how the node warns users about a potentially serious problem: an invalid blockchain that has more work than the node's own best chain. Previously, the warning was skipped while the node was still downloading the blockchain for the first time (Initial Block Download, or IBD). Now it also runs at startup and during IBD. The wording is also made more neutral, mentioning both database corruption and consensus incompatibility as possible causes, instead of assuming corruption. This is a diagnostic/logging improvement, not a fix for an exploitable vulnerability.
No immediate security action required. Operators should treat the new/reworded warning as a diagnostic aid. If the warning appears, investigate possible chainstate corruption or consensus-rule divergence as before.
Security signals we found
Behavior change in fork/invalid-chain warning logic
Warning now emitted during IBD and at startup
Log/alert text no longer assumes database corruption
No cryptographic, consensus, or network protocol change
Evidence from the diff
CheckForkWarningConditions() in src/validation.cpp is now called from LoadChainTip() at startup and is no longer skipped during IBD (it is still skipped for the background chainstate). The warning threshold remains the same: an invalid chain whose chainwork exceeds the local tip’s chainwork by more than six blocks’ worth of work. The log message and GUI/notification text are unified and reworded to indicate the problem could be either local chainstate corruption or a consensus incompatibility with peers. A functional test string is updated accordingly.
Changed components
src/validation.cpp: Chainstate::CheckForkWarningConditions()src/validation.cpp: Chainstate::LoadChainTip()test/functional/feature_notifications.pyInspect captured patch +6 / −8
diff --git a/src/validation.cpp b/src/validation.cpp
index e1d6babf..2f71c2c5 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1958,18 +1958,15 @@ void Chainstate::CheckForkWarningConditions()
{
AssertLockHeld(cs_main);
- // Before we get past initial download, we cannot reliably alert about forks
- // (we assume we don't get stuck on a fork before finishing our initial sync)
- // Also not applicable to the background chainstate
- if (m_chainman.IsInitialBlockDownload() || this->GetRole() == ChainstateRole::BACKGROUND) {
+ if (this->GetRole() == ChainstateRole::BACKGROUND) {
return;
}
if (m_chainman.m_best_invalid && m_chainman.m_best_invalid->nChainWork > m_chain.Tip()->nChainWork + (GetBlockProof(*m_chain.Tip()) * 6)) {
- LogWarning("Found invalid chain at least ~6 blocks longer than our best chain. Chain state database corruption likely.");
+ LogWarning("Found invalid chain more than 6 blocks longer than our best chain. This could be due to database corruption or consensus incompatibility with peers.");
m_chainman.GetNotifications().warningSet(
kernel::Warning::LARGE_WORK_INVALID_CHAIN,
- _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade."));
+ _("Warning: Found invalid chain more than 6 blocks longer than our best chain. This could be due to database corruption or consensus incompatibility with peers."));
} else {
m_chainman.GetNotifications().warningUnset(kernel::Warning::LARGE_WORK_INVALID_CHAIN);
}
@@ -4638,6 +4635,8 @@ bool Chainstate::LoadChainTip()
/*verification_progress=*/m_chainman.GuessVerificationProgress(tip));
}
+ CheckForkWarningConditions();
+
return true;
}
diff --git a/test/functional/feature_notifications.py b/test/functional/feature_notifications.py
index 519d80b9..c08bf07f 100755
--- a/test/functional/feature_notifications.py
+++ b/test/functional/feature_notifications.py
@@ -25,8 +25,7 @@ FILE_CHARS_DISALLOWED = '/\\?%*:|"<>' if platform.system() == 'Windows' else '/'
UNCONFIRMED_HASH_STRING = 'unconfirmed'
LARGE_WORK_INVALID_CHAIN_WARNING = (
- "Warning: We do not appear to fully agree with our peers " # Exclamation mark removed by SanitizeString in AlertNotify
- "You may need to upgrade, or other nodes may need to upgrade."
+ "Warning: Found invalid chain more than 6 blocks longer than our best chain. This could be due to database corruption or consensus incompatibility with peers."
)
Why this scored 22/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.