{"id":"XE-1126","kind":"bounty","visibility":"public","source":"web","source_repo":"","source_ref":"","source_url":"","reporter_id":242,"title":"statechain ResyncOnGap and requestSync treat rate-limited, behind, or invalid peer responses as success, aborting fallback peers","area":"p2p-sync","claimed_tier":"medium","assessed_tier":null,"verdict":"duplicate","duplicate_of":"XE-0260","tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"duplicate","github_state":"","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-07T16:28:14.035129+00:00","updated_at":"2026-11-14T22:53:11.586805+00:00","source_created_at":null,"told_at":"2026-11-14T22:53:12.745152+00:00","status_changed_at":"2026-11-08T20:32:07.687783+00:00","url":"https://bounty.xe.network/XE-1126","body":"### Summary\nWhen 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`).\n\n### Root Cause\nIn `statechain/sync.go:66-73, 102-115, 168-197`:\n1. **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`.\n2. **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`).\n3. **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`).\n\n### Impact\nBecause `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.\n\n### Remediation\nChange `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`.","patch_refs":[],"thread":[{"id":3742,"source":"desk","source_ref":"reply:2484","author":"XE desk","team":true,"body":"Thanks. This is the same finding as https://bounty.xe.network/XE-0260, which was filed first; the programme pays the\nfirst verifiable submission, so this one closes as a duplicate. If you believe it is a different\nbug, file a new report that links https://bounty.xe.network/XE-1126 and says what differs; it is read like any other.","created_at":"2026-11-14T22:53:11.586805+00:00"}]}