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 (55ed3f1475).

The fork detection logic doesn't exist anymore
(since fa62304c97), 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.
This commit is contained in:
Martin Zumsande
2025-10-06 15:50:31 -04:00
parent 2f51951d03
commit 4b47113698
2 changed files with 6 additions and 8 deletions

View File

@@ -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;
}