Skip to content

Commit

Permalink
chore: renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
kaichaosun committed Dec 3, 2024
1 parent 37affd2 commit 4908959
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions waku/v2/api/publish/rln_rate_limiting.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ const RlnLimiterRefillInterval = 10 * time.Minute
// RlnRateLimiter is used to rate limit the outgoing messages,
// The capacity and refillAfter comes from RLN contract configuration.
type RlnRateLimiter struct {
mu sync.Mutex
capacity int
tokens int
refillAfter time.Duration
lastRefill time.Time
mu sync.Mutex
capacity int
tokens int
refillInterval time.Duration
lastRefill time.Time
}

// NewRlnPublishRateLimiter creates a new rate limiter, starts with a full capacity bucket.
func NewRlnRateLimiter(capacity int, refillAfter time.Duration) *RlnRateLimiter {
func NewRlnRateLimiter(capacity int, refillInterval time.Duration) *RlnRateLimiter {
return &RlnRateLimiter{
capacity: capacity,
tokens: capacity, // Start with a full bucket
refillAfter: refillAfter,
lastRefill: time.Now(),
capacity: capacity,
tokens: capacity, // Start with a full bucket
refillInterval: refillInterval,
lastRefill: time.Now(),
}
}

Expand All @@ -41,7 +41,7 @@ func (rl *RlnRateLimiter) Allow() bool {

// Refill tokens if the refill interval has passed
now := time.Now()
if now.Sub(rl.lastRefill) >= rl.refillAfter {
if now.Sub(rl.lastRefill) >= rl.refillInterval {
rl.tokens = rl.capacity // Refill the bucket
rl.lastRefill = now
}
Expand Down

0 comments on commit 4908959

Please sign in to comment.