fix(sync): detect IBD when behind peers to prevent sync stall
When a node restarts on a stalled chain (tip < 24h old from restart), IsInitialBlockDownload() returns false because the static nLastUpdate timestamp is recent. This prevents the stall recovery logic from triggering, leaving the node permanently stuck. Add a check: if our height is >5 blocks behind the peer median, we're in IBD regardless of the timestamp. This ensures nodes that are behind peers will enter IBD mode, send getheaders, and start downloading blocks. Fixes DNS2 sync stall at block 2,219,922 (4,841 blocks behind frozen tip).
This commit is contained in:
@@ -1750,6 +1750,13 @@ bool IsInitialBlockDownload()
|
||||
// handles the specific staking-broker scenario.
|
||||
if (GetTime() - nLastUpdate > 24 * 60 * 60)
|
||||
return true;
|
||||
// Also enter IBD if we're significantly behind peer heights, even if
|
||||
// the tip was recently updated (e.g. after a daemon restart on a
|
||||
// stalled chain). Without this, a node that restarts on a frozen
|
||||
// chain thinks it's fully synced (tip < 24h old from restart) and
|
||||
// never requests blocks from peers — permanently stuck.
|
||||
if (nBestHeight > 0 && nBestHeight < GetNumBlocksOfPeers() - 5)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user