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
937e417c
Unverified
Commit
937e417c
authored
Aug 04, 2022
by
Matthew Slipper
Committed by
GitHub
Aug 04, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3174 from ethereum-optimism/develop
Develop -> Master
parents
afdd0201
dc4f6a06
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
7 deletions
+21
-7
strong-meals-impress.md
.changeset/strong-meals-impress.md
+5
-0
rate_limit_test.go
proxyd/integration_tests/rate_limit_test.go
+0
-2
server.go
proxyd/server.go
+16
-5
No files found.
.changeset/strong-meals-impress.md
0 → 100644
View file @
937e417c
---
'
@eth-optimism/proxyd'
:
patch
---
Add logging/metrics
proxyd/integration_tests/rate_limit_test.go
View file @
937e417c
package
integration_tests
import
(
"fmt"
"net/http"
"os"
"testing"
...
...
@@ -68,7 +67,6 @@ func TestFrontendMaxRPSLimit(t *testing.T) {
h
.
Set
(
"Origin"
,
"exempt_origin"
)
client
:=
NewProxydClientWithHeaders
(
"http://127.0.0.1:8545"
,
h
)
_
,
codes
:=
spamReqs
(
t
,
client
,
429
)
fmt
.
Println
(
codes
)
require
.
Equal
(
t
,
3
,
codes
[
200
])
})
...
...
proxyd/server.go
View file @
937e417c
...
...
@@ -196,14 +196,16 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
ctx
,
cancel
=
context
.
WithTimeout
(
ctx
,
s
.
timeout
)
defer
cancel
()
exemptOrigin
:=
s
.
limExemptOrigins
[
strings
.
ToLower
(
r
.
Header
.
Get
(
"Origin"
))]
exemptUserAgent
:=
s
.
limExemptUserAgents
[
strings
.
ToLower
(
r
.
Header
.
Get
(
"User-Agent"
))]
origin
:=
r
.
Header
.
Get
(
"Origin"
)
userAgent
:=
r
.
Header
.
Get
(
"User-Agent"
)
exemptOrigin
:=
s
.
limExemptOrigins
[
strings
.
ToLower
(
origin
)]
exemptUserAgent
:=
s
.
limExemptUserAgents
[
strings
.
ToLower
(
userAgent
)]
// Use XFF in context since it will automatically be replaced by the remote IP
xff
:=
stripXFF
(
GetXForwardedFor
(
ctx
))
var
ok
bool
if
exemptOrigin
||
exemptUserAgent
{
ok
=
true
}
else
{
// Use XFF in context since it will automatically be replaced by the remote IP
xff
:=
stripXFF
(
GetXForwardedFor
(
ctx
))
if
xff
==
""
{
log
.
Warn
(
"rejecting request without XFF or remote IP"
)
ok
=
false
...
...
@@ -214,6 +216,15 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
if
!
ok
{
rpcErr
:=
ErrOverRateLimit
.
Clone
()
rpcErr
.
Message
=
s
.
limConfig
.
ErrorMessage
RecordRPCError
(
ctx
,
BackendProxyd
,
"unknown"
,
rpcErr
)
log
.
Warn
(
"rate limited request"
,
"req_id"
,
GetReqID
(
ctx
),
"auth"
,
GetAuthCtx
(
ctx
),
"user_agent"
,
userAgent
,
"origin"
,
origin
,
"remote_ip"
,
xff
,
)
writeRPCError
(
ctx
,
w
,
nil
,
rpcErr
)
return
}
...
...
@@ -222,7 +233,7 @@ func (s *Server) HandleRPC(w http.ResponseWriter, r *http.Request) {
"received RPC request"
,
"req_id"
,
GetReqID
(
ctx
),
"auth"
,
GetAuthCtx
(
ctx
),
"user_agent"
,
r
.
Header
.
Get
(
"user-agent"
)
,
"user_agent"
,
userAgent
,
)
body
,
err
:=
ioutil
.
ReadAll
(
io
.
LimitReader
(
r
.
Body
,
s
.
maxBodySize
))
...
...
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