Bounty
XE-1126 · Bounty

statechain ResyncOnGap and requestSync treat rate-limited, behind, or invalid peer responses as success, aborting fallback peers

Closed · duplicate —claimed Medium web filed 2026-11-07 16:28 UTC by Ashev Ardiansyah

Report

Summary

When a node receives a gossiped statechain block ahead of its local tip (b.Index > localTip + 1), ResyncOnGap (statechain/sync.go:211-228) consumes the 30-second gapSyncBackoff cooldown (chain.gapSyncAllowed() at statechain/chain.go:296-306) and iterates through up to 3 connected peers, calling requestSync(h, pid, chain) and returning immediately on the first call that returns err == nil. However, requestSync (statechain/sync.go:144-197) returns nil even when zero blocks were added (added == 0).

Root Cause

In statechain/sync.go:66-73, 102-115, 168-197:

  1. Remote peer rate-limits the stream (inboundRL): If pid served a sync within the past 30s (syncCooldown = 30 * time.Second, e.g., on ConnectedF), pid's stream handler (statechain/sync.go:67-70) immediately returns and closes the stream. The requester reads io.EOF on the first dec.Decode(&resp) (statechain/sync.go:171-173), breaks out of the loop with added == 0, and returns nil.
  2. First peer is at or behind the requester's tip: If pid has tip.Index <= req.TipIndex, pid responds with syncResponse{HasMore: false} (statechain/sync.go:110-114). requestSync sees !resp.HasMore (statechain/sync.go:185-187) and returns nil (added == 0).
  3. Peer returns invalid blocks: If chain.AddBlock(b) fails on every block in resp.Blocks (statechain/sync.go:179-181), requestSync logs a warning and returns nil (added == 0).

Impact

Because requestSync returns nil with added == 0, ResyncOnGap immediately returns at line 225 without trying any remaining peers while consuming the 30s gapSyncBackoff cooldown. Since SetupSync has no periodic background sync ticker, a node that misses the latest statechain block can remain stuck on stale consensus/governance parameters (sys.phase, sys.representatives, sys.timekeepers, sys.activations, epoch.*) until a future statechain block is broadcast or a new peer connects.

Remediation

Change requestSync to return (added int, err error) (and return an error if io.EOF occurs before any response frame is decoded or if AddBlock fails), and in ResyncOnGap continue to the next peer whenever added == 0 or err != nil.

Thread

XE deskteam2026-11-14 22:53 UTCdesk

Thanks. This is the same finding as https://bounty.xe.network/XE-0260, which was filed first; the programme pays the first verifiable submission, so this one closes as a duplicate. If you believe it is a different bug, file a new report that links https://bounty.xe.network/XE-1126 and says what differs; it is read like any other.