Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/poor-seahorses-ring.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/proxyd': patch
---

Use canned response for eth_accounts
12 changes: 12 additions & 0 deletions proxyd/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,18 @@ func (w *WSProxier) clientPump(ctx context.Context, errC chan error) {
continue
}

// Send eth_accounts requests directly to the client
if req.Method == "eth_accounts" {
msg = mustMarshalJSON(NewRPCRes(req.ID, emptyArrayResponse))
RecordRPCForward(ctx, BackendProxyd, "eth_accounts", RPCRequestSourceWS)
err = w.writeClientConn(msgType, msg)
if err != nil {
errC <- err
return
}
continue
}

RecordRPCForward(ctx, w.backend.Name, req.Method, RPCRequestSourceWS)
log.Info(
"forwarded WS message to backend",
Expand Down
15 changes: 15 additions & 0 deletions proxyd/integration_tests/batching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ func TestBatching(t *testing.T) {
netVersionResponse1 := `{"jsonrpc": "2.0", "result": "1.0", "id": 1}`
callResponse1 := `{"jsonrpc": "2.0", "result": "ekans1", "id": 1}`

ethAccountsResponse2 := `{"jsonrpc": "2.0", "result": [], "id": 2}`

type mockResult struct {
method string
id string
Expand Down Expand Up @@ -98,6 +100,19 @@ func TestBatching(t *testing.T) {
maxBatchSize: 2,
numExpectedForwards: 3,
},
{
name: "eth_accounts does not get forwarded",
mocks: []mockResult{
callMock1,
},
reqs: []*proxyd.RPCReq{
NewRPCReq("1", "eth_call", nil),
NewRPCReq("2", "eth_accounts", nil),
},
expectedRes: asArray(callResponse1, ethAccountsResponse2),
maxBatchSize: 2,
numExpectedForwards: 1,
},
}

for _, tt := range tests {
Expand Down
3 changes: 2 additions & 1 deletion proxyd/integration_tests/testdata/ws.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
ws_backend_group = "main"

ws_method_whitelist = [
"eth_subscribe"
"eth_subscribe",
"eth_accounts"
]

[server]
Expand Down
6 changes: 6 additions & 0 deletions proxyd/integration_tests/ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ func TestWS(t *testing.T) {
"{\"jsonrpc\":\"2.0\",\"error\":{\"code\":-32700,\"message\":\"parse error\"},\"id\":null}",
"{\"jsonrpc\": \"2.0\", \"method\": true}",
},
{
"eth_accounts",
"{}",
"{\"jsonrpc\":\"2.0\",\"result\":[],\"id\":1}",
"{\"jsonrpc\": \"2.0\", \"method\": \"eth_accounts\", \"id\": 1}",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions proxyd/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ func NewRPCErrorRes(id json.RawMessage, err error) *RPCRes {
}
}

func NewRPCRes(id json.RawMessage, result interface{}) *RPCRes {
return &RPCRes{
JSONRPC: JSONRPCVersion,
Result: result,
ID: id,
}
}

func IsBatch(raw []byte) bool {
for _, c := range raw {
// skip insignificant whitespace (http://www.ietf.org/rfc/rfc4627.txt)
Expand Down
8 changes: 8 additions & 0 deletions proxyd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (
defaultMaxUpstreamBatchSize = 10
)

var emptyArrayResponse = json.RawMessage("[]")

type Server struct {
backendGroups map[string]*BackendGroup
wsBackendGroup *BackendGroup
Expand Down Expand Up @@ -248,6 +250,12 @@ func (s *Server) handleBatchRPC(ctx context.Context, reqs []json.RawMessage, isB
continue
}

if parsedReq.Method == "eth_accounts" {
RecordRPCForward(ctx, BackendProxyd, "eth_accounts", RPCRequestSourceHTTP)
responses[i] = NewRPCRes(parsedReq.ID, emptyArrayResponse)
continue
}

group := s.rpcMethodMappings[parsedReq.Method]
if group == "" {
// use unknown below to prevent DOS vector that fills up memory
Expand Down