Commit 05b7cf02 authored by mergify[bot]'s avatar mergify[bot] Committed by GitHub

Merge pull request #3700 from ethereum-optimism/feat/proxyd-allow-backend-lim-disable

proxyd: Allow disabling backend rate limiting
parents 4d9c7adc 462f4c12
---
'@eth-optimism/proxyd': minor
---
Allow disabling backend rate limiter
...@@ -5,6 +5,7 @@ import ( ...@@ -5,6 +5,7 @@ import (
"crypto/rand" "crypto/rand"
"encoding/hex" "encoding/hex"
"fmt" "fmt"
"math"
"sync" "sync"
"time" "time"
...@@ -256,5 +257,30 @@ func randStr(l int) string { ...@@ -256,5 +257,30 @@ func randStr(l int) string {
return hex.EncodeToString(b) return hex.EncodeToString(b)
} }
type ServerRateLimiter struct { type NoopBackendRateLimiter struct{}
var noopBackendRateLimiter = &NoopBackendRateLimiter{}
func (n *NoopBackendRateLimiter) IsBackendOnline(name string) (bool, error) {
return true, nil
}
func (n *NoopBackendRateLimiter) SetBackendOffline(name string, duration time.Duration) error {
return nil
}
func (n *NoopBackendRateLimiter) IncBackendRPS(name string) (int, error) {
return math.MaxInt, nil
}
func (n *NoopBackendRateLimiter) IncBackendWSConns(name string, max int) (bool, error) {
return true, nil
}
func (n *NoopBackendRateLimiter) DecBackendWSConns(name string) error {
return nil
}
func (n *NoopBackendRateLimiter) FlushBackendWSConns(names []string) error {
return nil
} }
...@@ -43,6 +43,7 @@ type MetricsConfig struct { ...@@ -43,6 +43,7 @@ type MetricsConfig struct {
type RateLimitConfig struct { type RateLimitConfig struct {
UseRedis bool `toml:"use_redis"` UseRedis bool `toml:"use_redis"`
EnableBackendRateLimiter bool `toml:"enable_backend_rate_limiter"`
BaseRate int `toml:"base_rate"` BaseRate int `toml:"base_rate"`
BaseInterval TOMLDuration `toml:"base_interval"` BaseInterval TOMLDuration `toml:"base_interval"`
ExemptOrigins []string `toml:"exempt_origins"` ExemptOrigins []string `toml:"exempt_origins"`
......
...@@ -16,3 +16,6 @@ backends = ["good"] ...@@ -16,3 +16,6 @@ backends = ["good"]
[rpc_method_mappings] [rpc_method_mappings]
eth_chainId = "main" eth_chainId = "main"
[rate_limit]
enable_backend_rate_limiter = true
\ No newline at end of file
...@@ -20,3 +20,6 @@ backends = ["bad", "good"] ...@@ -20,3 +20,6 @@ backends = ["bad", "good"]
[rpc_method_mappings] [rpc_method_mappings]
eth_chainId = "main" eth_chainId = "main"
[rate_limit]
enable_backend_rate_limiter = true
\ No newline at end of file
...@@ -26,3 +26,6 @@ backends = ["good"] ...@@ -26,3 +26,6 @@ backends = ["good"]
[rpc_method_mappings] [rpc_method_mappings]
eth_chainId = "main" eth_chainId = "main"
[rate_limit]
enable_backend_rate_limiter = true
\ No newline at end of file
...@@ -53,11 +53,15 @@ func Start(config *Config) (func(), error) { ...@@ -53,11 +53,15 @@ func Start(config *Config) (func(), error) {
var lim BackendRateLimiter var lim BackendRateLimiter
var err error var err error
if redisClient == nil { if config.RateLimit.EnableBackendRateLimiter {
if redisClient != nil {
lim = NewRedisRateLimiter(redisClient)
} else {
log.Warn("redis is not configured, using local rate limiter") log.Warn("redis is not configured, using local rate limiter")
lim = NewLocalBackendRateLimiter() lim = NewLocalBackendRateLimiter()
}
} else { } else {
lim = NewRedisRateLimiter(redisClient) lim = noopBackendRateLimiter
} }
// While modifying shared globals is a bad practice, the alternative // While modifying shared globals is a bad practice, the alternative
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment