Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
05b7cf02
Unverified
Commit
05b7cf02
authored
Oct 17, 2022
by
mergify[bot]
Committed by
GitHub
Oct 17, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3700 from ethereum-optimism/feat/proxyd-allow-backend-lim-disable
proxyd: Allow disabling backend rate limiting
parents
4d9c7adc
462f4c12
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
59 additions
and
14 deletions
+59
-14
flat-windows-trade.md
.changeset/flat-windows-trade.md
+5
-0
backend_rate_limiter.go
proxyd/backend_rate_limiter.go
+27
-1
config.go
proxyd/config.go
+8
-7
backend_rate_limit.toml
proxyd/integration_tests/testdata/backend_rate_limit.toml
+4
-1
out_of_service_interval.toml
...d/integration_tests/testdata/out_of_service_interval.toml
+4
-1
ws.toml
proxyd/integration_tests/testdata/ws.toml
+3
-0
proxyd.go
proxyd/proxyd.go
+8
-4
No files found.
.changeset/flat-windows-trade.md
0 → 100644
View file @
05b7cf02
---
'
@eth-optimism/proxyd'
:
minor
---
Allow disabling backend rate limiter
proxyd/backend_rate_limiter.go
View file @
05b7cf02
...
...
@@ -5,6 +5,7 @@ import (
"crypto/rand"
"encoding/hex"
"fmt"
"math"
"sync"
"time"
...
...
@@ -256,5 +257,30 @@ func randStr(l int) string {
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
}
proxyd/config.go
View file @
05b7cf02
...
...
@@ -42,13 +42,14 @@ type MetricsConfig struct {
}
type
RateLimitConfig
struct
{
UseRedis
bool
`toml:"use_redis"`
BaseRate
int
`toml:"base_rate"`
BaseInterval
TOMLDuration
`toml:"base_interval"`
ExemptOrigins
[]
string
`toml:"exempt_origins"`
ExemptUserAgents
[]
string
`toml:"exempt_user_agents"`
ErrorMessage
string
`toml:"error_message"`
MethodOverrides
map
[
string
]
*
RateLimitMethodOverride
`toml:"method_overrides"`
UseRedis
bool
`toml:"use_redis"`
EnableBackendRateLimiter
bool
`toml:"enable_backend_rate_limiter"`
BaseRate
int
`toml:"base_rate"`
BaseInterval
TOMLDuration
`toml:"base_interval"`
ExemptOrigins
[]
string
`toml:"exempt_origins"`
ExemptUserAgents
[]
string
`toml:"exempt_user_agents"`
ErrorMessage
string
`toml:"error_message"`
MethodOverrides
map
[
string
]
*
RateLimitMethodOverride
`toml:"method_overrides"`
}
type
RateLimitMethodOverride
struct
{
...
...
proxyd/integration_tests/testdata/backend_rate_limit.toml
View file @
05b7cf02
...
...
@@ -15,4 +15,7 @@ max_rps = 2
backends
=
["good"]
[rpc_method_mappings]
eth_chainId
=
"main"
\ No newline at end of file
eth_chainId
=
"main"
[rate_limit]
enable_backend_rate_limiter
=
true
\ No newline at end of file
proxyd/integration_tests/testdata/out_of_service_interval.toml
View file @
05b7cf02
...
...
@@ -19,4 +19,7 @@ ws_url = "$BAD_BACKEND_RPC_URL"
backends
=
[
"bad"
,
"good"
]
[rpc_method_mappings]
eth_chainId
=
"main"
\ No newline at end of file
eth_chainId
=
"main"
[rate_limit]
enable_backend_rate_limiter
=
true
\ No newline at end of file
proxyd/integration_tests/testdata/ws.toml
View file @
05b7cf02
...
...
@@ -26,3 +26,6 @@ backends = ["good"]
[rpc_method_mappings]
eth_chainId
=
"main"
[rate_limit]
enable_backend_rate_limiter
=
true
\ No newline at end of file
proxyd/proxyd.go
View file @
05b7cf02
...
...
@@ -53,11 +53,15 @@ func Start(config *Config) (func(), error) {
var
lim
BackendRateLimiter
var
err
error
if
redisClient
==
nil
{
log
.
Warn
(
"redis is not configured, using local rate limiter"
)
lim
=
NewLocalBackendRateLimiter
()
if
config
.
RateLimit
.
EnableBackendRateLimiter
{
if
redisClient
!=
nil
{
lim
=
NewRedisRateLimiter
(
redisClient
)
}
else
{
log
.
Warn
(
"redis is not configured, using local rate limiter"
)
lim
=
NewLocalBackendRateLimiter
()
}
}
else
{
lim
=
NewRedisRateLimiter
(
redisClient
)
lim
=
noopBackendRateLimiter
}
// While modifying shared globals is a bad practice, the alternative
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment