Bounty
XE-13280 · Bounty

[net/gossip.go] L9: rebroadcast() tidak rate-limit — potensi broadcast storm

Closed · invalid — xe#425 filed 2026-11-12 02:49 UTC by wahyu20260100233-ops

Report

Ringkasan

Tidak ada rate-limit pada rebroadcast. Kalau banyak goroutine panggil rebroadcast bersamaan, bisa terjadi broadcast storm.

Lokasi

  • File: net/gossip.go
  • Lines: 189-203

Kode

func (g *Gossip) rebroadcast(key string, msg []byte) {
    if g.rebroadcastMutex.TryLock() {
        defer g.rebroadcastMutex.Unlock()
        g.broadcast(key, msg, GossipUnicast)
        return
    }
    g.pendingRebroadcast.Add(1)
}

Impact

Broadcast storm kalau banyak goroutine kompetisi. Network congestion, waste bandwidth.

Suggested Fix

func (g *Gossip) rebroadcast(key string, msg []byte) {
    if g.rebroadcastMutex.TryLock() {
        defer g.rebroadcastMutex.Unlock()
        g.broadcast(key, msg, GossipUnicast)
        return
    }
    g.pendingRebroadcast.Add(1)
    // rate-limit: tunggu sebentar sebelum retry
    time.Sleep(time.Millisecond * 100)
    // atau gunakan rate limiter per key
}

Atau implement rate limiter per key:

type rateLimiter struct {
    mu    sync.Mutex
    last  map[string]time.Time
    limit time.Duration
}

func (rl *rateLimiter) allow(key string) bool {
    rl.mu.Lock()
    defer rl.mu.Unlock()
    now := time.Now()
    if t, ok := rl.last[key]; ok && now.Sub(t) < rl.limit {
        return false
    }
    rl.last[key] = now
    return true
}

Thread

XE deskteam2026-11-20 00:49 UTCgithub

Thanks for the report. We read it against the code and could not confirm a bug in what it describes.

This report is closed as invalid. If we have missed something, file a new report that links https://bounty.xe.network/XE-13280 and says what; it is read like any other.