Skip to content

Conversation

@zlacfzy
Copy link
Contributor

@zlacfzy zlacfzy commented Feb 10, 2026

Description

Reduce sync stalls on BSC after the block interval was 0.45s. For #3525 #3548

  1. 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.

  2. 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.

  3. 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

  • eth/downloader/fetchers.go: Add masterPeerHeaderTimeout = 5s; cap TTL in both header fetch functions; add cancelCh in fetchHeadersByHash
  • eth/sync.go: Preserve cs.forced = true on sync failure for immediate retry; replace 2s blocking sleep with 500ms non-blocking select

@NathanBSC
Copy link
Contributor

maybe can solve this issue by adjust https://github.com/bnb-chain/bsc/blob/master/eth/downloader/downloader.go#L61

// If the node is only slightly behind (e.g., 1 block), syncing is unnecessary.
// It's likely still processing broadcasted blocks(such as including a big tx) or block hash announcements.
// In most cases, the node will catch up within 2 seconds.
time.Sleep(2 * time.Second)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just change it to time.Sleep(500 * time.Millisecond)

case <-waitTimer.C:
case <-cs.handler.quitSync:
return nil
case <-cs.peerEventCh:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need trigger by this signal peerEventCh

@allformless allformless marked this pull request as draft February 11, 2026 07:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants