<!-- XE-1126 · statechain ResyncOnGap and requestSync treat rate-limited, behind, or invalid peer responses as success, aborting fallback peers · testnet -->
*Markdown view of <https://bounty.xe.network/XE-1126>. The page is the record; this is the same page for reading.*

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

Verdict
:   Duplicate

Tier
:   —

Claimed
:   Medium

Area
:   P2P / sync

Duplicate of
:   [XE-0260](https://bounty.xe.network/XE-0260) triaging

Tracked
:   —

Updated
:   2026-11-14 22:53 UTC

Told
:   2026-11-14 22:53 UTC

### Patches

None linked.

### History

- [209914](https://bounty.xe.network/log/209914) 2026-11-14 22:53 UTC reply.sent
- [44668](https://bounty.xe.network/log/44668) 2026-11-08 20:32 UTC proposal.adopted
- [44667](https://bounty.xe.network/log/44667) 2026-11-08 20:32 UTC ticket.status new → closed
- [31149](https://bounty.xe.network/log/31149) 2026-11-08 11:43 UTC proposal.adopted
- [31148](https://bounty.xe.network/log/31148) 2026-11-08 11:43 UTC ticket.facts area
- [31147](https://bounty.xe.network/log/31147) 2026-11-08 11:43 UTC proposal.adopted
- [31146](https://bounty.xe.network/log/31146) 2026-11-08 11:43 UTC ticket.facts
- [31145](https://bounty.xe.network/log/31145) 2026-11-08 11:43 UTC proposal.adopted
- [31144](https://bounty.xe.network/log/31144) 2026-11-08 11:43 UTC ticket.facts
- [31143](https://bounty.xe.network/log/31143) 2026-11-08 11:43 UTC proposal.adopted
- [30677](https://bounty.xe.network/log/30677) 2026-11-08 11:36 UTC proposal.created
- [30676](https://bounty.xe.network/log/30676) 2026-11-08 11:36 UTC proposal.created

[Full history](https://bounty.xe.network/log?ref=XE-1126) · [JSON](https://bounty.xe.network/v1/tickets/XE-1126) · [markdown](https://bounty.xe.network/XE-1126.md)

### 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 desk**team2026-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.
