Commit 2a062b11 authored by Murphy Law's avatar Murphy Law Committed by GitHub

proxyd: Log sanitized RPC requests (#2470)

parent a4bfd9e7
---
'@eth-optimism/proxyd': patch
---
proxyd: Log ssanitized RPC requests
...@@ -27,6 +27,7 @@ const ( ...@@ -27,6 +27,7 @@ const (
MaxBatchRPCCalls = 100 MaxBatchRPCCalls = 100
cacheStatusHdr = "X-Proxyd-Cache-Status" cacheStatusHdr = "X-Proxyd-Cache-Status"
defaultServerTimeout = time.Second * 10 defaultServerTimeout = time.Second * 10
maxLogLength = 1000
) )
type Server struct { type Server struct {
...@@ -237,6 +238,12 @@ func (s *Server) handleSingleRPC(ctx context.Context, req *RPCReq) (*RPCRes, boo ...@@ -237,6 +238,12 @@ func (s *Server) handleSingleRPC(ctx context.Context, req *RPCReq) (*RPCRes, boo
return NewRPCErrorRes(req.ID, ErrMethodNotWhitelisted), false return NewRPCErrorRes(req.ID, ErrMethodNotWhitelisted), false
} }
log.Info("RPC request",
"method", req.Method,
"params", truncate(string(req.Params)),
"id", truncate(string(req.ID)),
)
var backendRes *RPCRes var backendRes *RPCRes
backendRes, err := s.cache.GetRPC(ctx, req) backendRes, err := s.cache.GetRPC(ctx, req)
if err != nil { if err != nil {
...@@ -457,3 +464,11 @@ func (n *NoopRPCCache) GetRPC(context.Context, *RPCReq) (*RPCRes, error) { ...@@ -457,3 +464,11 @@ func (n *NoopRPCCache) GetRPC(context.Context, *RPCReq) (*RPCRes, error) {
func (n *NoopRPCCache) PutRPC(context.Context, *RPCReq, *RPCRes) error { func (n *NoopRPCCache) PutRPC(context.Context, *RPCReq, *RPCRes) error {
return nil return nil
} }
func truncate(str string) string {
if len(str) > maxLogLength {
return str[:maxLogLength] + "..."
} else {
return str
}
}
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