From 04b943b63ca4c27aa857b03e5de82ed8cae7b17d Mon Sep 17 00:00:00 2001 From: Martin Zumsande Date: Mon, 6 Oct 2025 15:50:31 -0400 Subject: [PATCH] validation: call CheckForkWarningConditions during IBD, and at startup The existing IBD check 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. --- src/validation.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/validation.cpp b/src/validation.cpp index 3f77955da62..46b670ff698 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2026,15 +2026,12 @@ 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)) { - LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n", __func__); + LogWarning("Found invalid chain at least ~6 blocks longer than our best chain. Chain state database corruption likely."); 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.")); @@ -4677,6 +4674,8 @@ bool Chainstate::LoadChainTip() /*verification_progress=*/m_chainman.GuessVerificationProgress(tip)); } + CheckForkWarningConditions(); + return true; }