From 4b4711369880369729893ba7baef11ba2a36cf4b Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Mon, 6 Oct 2025 15:50:31 -0400 Subject: [PATCH] validation: Reword CheckForkWarningConditions and call it also during IBD and at startup The existing IBD disable was added at a time when CheckForkWarningConditions did also sophisticated fork detection that could lead to false positives during IBD (55ed3f14751206fc87f0cbf8cb4e223efacef338). The fork detection logic doesn't exist anymore (since fa62304c9760f0de9838e56150008816e7a9bacb), so the IBD check is no longer necessary. Displaying the log at startup will help node operators diagnose the problem better. Also unify log message and alert warning text, since a long invalid chain could be due to chainstate corruption or an actual consensus incompatibility with peers. Previously the log assumed the former and the alert the latter. --- src/validation.cpp | 11 +++++------ test/functional/feature_notifications.py | 3 +-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index e1d6babfd0e..2f71c2c571a 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 519d80b9abf..c08bf07fb8d 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." )