-
Notifications
You must be signed in to change notification settings - Fork 680
Add trace-level logging of RPC requests #1441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
d91f86a
a4f8d6f
4b7b80a
d721711
41b01eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ import ( | |
| "github.com/ethereum/go-ethereum/metrics" | ||
| "github.com/ethereum/go-ethereum/metrics/exp" | ||
| "github.com/ethereum/go-ethereum/node" | ||
| "github.com/ethereum/go-ethereum/rpc" | ||
|
|
||
| "github.com/offchainlabs/nitro/arbnode" | ||
| "github.com/offchainlabs/nitro/cmd/conf" | ||
|
|
@@ -564,6 +565,27 @@ func (c *NodeConfig) Validate() error { | |
| return c.Node.Validate() | ||
| } | ||
|
|
||
| type RpcLogger struct{} | ||
|
|
||
| func (l RpcLogger) OnRequest(request interface{}) rpc.ResultHook { | ||
| log.Trace("sending L1 RPC request", "request", request) | ||
| return RpcResultLogger{request} | ||
| } | ||
|
|
||
| type RpcResultLogger struct { | ||
| request interface{} | ||
| } | ||
|
|
||
| func (l RpcResultLogger) OnResult(response interface{}, err error) { | ||
| if err != nil { | ||
| // The request might not've been logged if the log level is debug not trace, so we log it again here | ||
| log.Debug("received error response from L1 RPC", "request", l.request, "response", response, "err", err) | ||
| } else { | ||
| // The request was already logged and can be cross-referenced by JSON-RPC id | ||
| log.Trace("received response from L1 RPC", "response", response, "err", err) | ||
|
||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To log all l1 - we should also add a print in HeaderReader when receiving events from SubscribeNewHead, same loglevel as OnResult. I think that's the only subscribe in nitro node.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added a log line there |
||
|
|
||
| func ParseNode(ctx context.Context, args []string) (*NodeConfig, *genericconf.WalletConfig, *genericconf.WalletConfig, *ethclient.Client, *big.Int, error) { | ||
| f := flag.NewFlagSet("", flag.ContinueOnError) | ||
|
|
||
|
|
@@ -584,8 +606,9 @@ func ParseNode(ctx context.Context, args []string) (*NodeConfig, *genericconf.Wa | |
| maxConnectionAttempts = math.MaxInt | ||
| } | ||
| for i := 1; i <= maxConnectionAttempts; i++ { | ||
| l1Client, err = ethclient.DialContext(ctx, l1URL) | ||
| rawRpc, err := rpc.DialContextWithRequestHook(ctx, l1URL, RpcLogger{}) | ||
| if err == nil { | ||
| l1Client = ethclient.NewClient(rawRpc) | ||
| l1ChainId, err = l1Client.ChainID(ctx) | ||
| if err == nil { | ||
| // Successfully got chain ID | ||
|
|
||
| +9 −0 | metrics/sample.go | |
| +22 −2 | rpc/client.go | |
| +50 −0 | rpc/client_arbitrum.go |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A warning or at least info seems in place?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just not sure under what conditions this might appear, and don't want to concern users unnecessarily. But I'll make it an info 👍