chore: renaming

This commit is contained in:
kaichaosun 2024-12-03 15:24:47 +08:00
parent e42defcfef
commit 9385c1e2f9
No known key found for this signature in database
GPG Key ID: 223E0F992F4F03BF

View File

@ -17,20 +17,20 @@ const RlnLimiterRefillInterval = 10 * time.Minute
// RlnRateLimiter is used to rate limit the outgoing messages, // RlnRateLimiter is used to rate limit the outgoing messages,
// The capacity and refillAfter comes from RLN contract configuration. // The capacity and refillAfter comes from RLN contract configuration.
type RlnRateLimiter struct { type RlnRateLimiter struct {
mu sync.Mutex mu sync.Mutex
capacity int capacity int
tokens int tokens int
refillAfter time.Duration refillInterval time.Duration
lastRefill time.Time lastRefill time.Time
} }
// NewRlnPublishRateLimiter creates a new rate limiter, starts with a full capacity bucket. // 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{ return &RlnRateLimiter{
capacity: capacity, capacity: capacity,
tokens: capacity, // Start with a full bucket tokens: capacity, // Start with a full bucket
refillAfter: refillAfter, refillInterval: refillInterval,
lastRefill: time.Now(), lastRefill: time.Now(),
} }
} }
@ -41,7 +41,7 @@ func (rl *RlnRateLimiter) Allow() bool {
// Refill tokens if the refill interval has passed // Refill tokens if the refill interval has passed
now := time.Now() 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.tokens = rl.capacity // Refill the bucket
rl.lastRefill = now rl.lastRefill = now
} }