diff --git a/internal/app/app.go b/internal/app/app.go index 38fdaa4..d00ef40 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -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) @@ -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) diff --git a/internal/app/flags.go b/internal/app/flags.go index 4e3763e..a0e2ccc 100644 --- a/internal/app/flags.go +++ b/internal/app/flags.go @@ -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"}, @@ -212,6 +218,7 @@ func NewFlags() []cli.Flag { logLevelFlag, wsRPCFlag, httpRPCFlag, + rpcRequestTimeoutFlag, sanityNodeRPCFlag, sanityCheckIntervalFlag, }