statechain ResyncOnGap and requestSync treat rate-limited, behind, or invalid peer responses as success, aborting fallback peers
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:
- Remote peer rate-limits the stream (
inboundRL): Ifpidserved a sync within the past 30s (syncCooldown = 30 * time.Second, e.g., onConnectedF),pid's stream handler (statechain/sync.go:67-70) immediately returns and closes the stream. The requester readsio.EOFon the firstdec.Decode(&resp)(statechain/sync.go:171-173), breaks out of the loop withadded == 0, and returnsnil. - First peer is at or behind the requester's tip: If
pidhastip.Index <= req.TipIndex,pidresponds withsyncResponse{HasMore: false}(statechain/sync.go:110-114).requestSyncsees!resp.HasMore(statechain/sync.go:185-187) and returnsnil(added == 0). - Peer returns invalid blocks: If
chain.AddBlock(b)fails on every block inresp.Blocks(statechain/sync.go:179-181),requestSynclogs a warning and returnsnil(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
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.