{"id":"XE-13295","kind":"bounty","visibility":"public","source":"github","source_repo":"xeprotocol/xe","source_ref":"440","source_url":"https://github.com/xeprotocol/xe/issues/440","reporter_id":2483,"title":"[net/sync.go] M9: SyncTo() tidak rate-limit — sync berulang bisa menyebabkan network congestion","area":"p2p-sync","claimed_tier":null,"assessed_tier":null,"verdict":"invalid","duplicate_of":null,"tracked":false,"internal_ref":"","internal_url":"","status":"closed","closed_reason":"invalid","github_state":"closed","disclosed_at":null,"award_xe":null,"award_approved":false,"paid_ref":"","created_at":"2026-11-14T20:42:08.648829+00:00","updated_at":"2026-11-20T00:51:16.633476+00:00","source_created_at":"2026-11-12T02:52:08+00:00","told_at":"2026-11-20T00:49:40+00:00","status_changed_at":"2026-11-20T00:33:26.147375+00:00","url":"https://bounty.xe.network/XE-13295","body":"## Ringkasan\n`SyncTo` dipanggil dari `SyncAll` (periodik) dan `peerSyncWorker` (background). Tidak ada rate-limit antara sync attempt. Kalau sync sering gagal, bisa menyebabkan network congestion.\n\n## Lokasi\n- File: `net/sync.go`\n- Lines: 124-143, 383-404\n\n## Kode\n```go\nfunc (t *tracker) SyncTo(ctx context.Context, h host.Host, pid peer.ID, opts ...SyncOption) error {\n    ...\n    if err := t.syncPeer(ctx, h, pid, opts...); err != nil {\n        return err\n    }\n    return nil\n}\n\nfunc (t *tracker) peerSyncWorker(ctx context.Context, h host.Host, pid peer.ID) {\n    ...\n    for {\n        select {\n        case <-ctx.Done():\n            return\n        case <-t.syncCh[pid]:\n            if err := t.SyncTo(ctx, h, pid); err != nil {\n                logging.Warnf(\"sync: failed to sync with %s: %v\", pid, err)\n            }\n        }\n    }\n}\n```\n\n## Impact\nSync berulang tanpa jeda bisa menyebabkan network congestion, waste bandwidth.\n\n## Suggested Fix\n```go\nfunc (t *tracker) peerSyncWorker(ctx context.Context, h host.Host, pid peer.ID) {\n    ...\n    for {\n        select {\n        case <-ctx.Done():\n            return\n        case <-t.syncCh[pid]:\n            if err := t.SyncTo(ctx, h, pid); err != nil {\n                logging.Warnf(\"sync: failed to sync with %s: %v\", pid, err)\n            }\n            time.Sleep(t.syncInterval)  // tambah jeda\n        }\n    }\n}\n```\n\nAtau gunakan rate limiter per peer:\n```go\ntype rateLimiter struct {\n    mu    sync.Mutex\n    last  map[peer.ID]time.Time\n    limit time.Duration\n}\n\nfunc (rl *rateLimiter) allow(pid peer.ID) bool {\n    rl.mu.Lock()\n    defer rl.mu.Unlock()\n    now := time.Now()\n    if t, ok := rl.last[pid]; ok && now.Sub(t) < rl.limit {\n        return false\n    }\n    rl.last[pid] = now\n    return true\n}\n```","patch_refs":[],"thread":[{"id":13379,"source":"github","source_ref":"7026796285","author":"XE desk","team":true,"body":"Thanks for the report. We read it against the code and could not confirm a bug in what it describes.\n\nThis report is closed as invalid. If we have missed something, file a new report that links\nhttps://bounty.xe.network/XE-13295 and says what; it is read like any other.","created_at":"2026-11-20T00:49:40+00:00"}]}