Skip to content
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

feat: support custom RPC request timeout through env #116

Merged
merged 2 commits into from
May 30, 2024
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
11 changes: 8 additions & 3 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,18 @@ func redisConfigFromCli(c *cli.Context) redis.Config {
func NewListener(c *cli.Context) (*listener.Listener, error) {
l := zap.S()

rpcRequestTimeout := c.Duration(rpcRequestTimeoutFlag.Name)
if rpcRequestTimeout == 0 {
rpcRequestTimeout = defaultRequestTimeout
}

httpClient := &http.Client{
Timeout: defaultRequestTimeout,
Timeout: rpcRequestTimeout,
}
wsRPC := c.String(wsRPCFlag.Name)
l.Infow("Connect to node websocket rpc", "rpc", wsRPC)
wsEVMClient, err := evmclient.DialContextWithTimeout(
context.Background(), wsRPC, httpClient, defaultRequestTimeout)
context.Background(), wsRPC, httpClient, rpcRequestTimeout)
if err != nil {
l.Errorw("Fail to connect to node", "rpc", wsRPC, "error", err)

Expand All @@ -67,7 +72,7 @@ func NewListener(c *cli.Context) (*listener.Listener, error) {
httpRPC := c.String(httpRPCFlag.Name)
l.Infow("Connect to node http rpc", "rpc", httpRPC)
httpEVMClient, err := evmclient.DialContextWithTimeout(
context.Background(), httpRPC, httpClient, defaultRequestTimeout)
context.Background(), httpRPC, httpClient, rpcRequestTimeout)
if err != nil {
l.Errorw("Fail to connect to node", "rpc", httpRPC, "error", err)

Expand Down
7 changes: 7 additions & 0 deletions internal/app/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ var (
Value: "http://localhost:8545",
Usage: "HTTP RPC to connect to blockchain node, default: http://localhost:8545",
}
rpcRequestTimeoutFlag = &cli.DurationFlag{
Name: "rpc-request-timeout",
EnvVars: []string{"RPC_REQUEST_TIMEOUT"},
Value: 10 * time.Second, // nolint:gomnd
Usage: "Timeout for RPC request",
}
sanityNodeRPCFlag = &cli.StringFlag{
Name: "sanity-node-rpc",
EnvVars: []string{"SANITY_NODE_RPC"},
Expand Down Expand Up @@ -212,6 +218,7 @@ func NewFlags() []cli.Flag {
logLevelFlag,
wsRPCFlag,
httpRPCFlag,
rpcRequestTimeoutFlag,
sanityNodeRPCFlag,
sanityCheckIntervalFlag,
}
Expand Down
Loading