eth/downloader, eth/sync: reduce sync stall on BSC's 0.45s block inte… #3556
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Reduce sync stalls on BSC after the block interval was 0.45s. For #3525 #3548
Cap critical-path header timeout – Introduce masterPeerHeaderTimeout (5s) to bound blocking fetchHeadersByHash / fetchHeadersByNumber. The dynamic TargetTimeout can exceed 10s, stalling the entire pipeline on one slow peer. Also add missing cancelCh handling in fetchHeadersByHash.
Preserve forced sync on failure – Keep cs.forced = true on doSync error, so the sync loop retries immediately with minPeers=1 instead of waiting up to 10s.
Shorten near-head wait – Replace blocking 2s time.Sleep with a non-blocking 500ms select in nextSyncOp, responsive to quit signals and peer events.
Rationale
With 0.45s block intervals, the old parameters (designed for 3s/12s cadence) cause compounding delays: a single slow peer triggers a 10s+ timeout, followed by a 10s recovery wait — ~45 blocks of drift total. These changes reduce worst-case sync stall from ~20s to ~5s.
Changes