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

Enable superfluous ws.port flag to fix some Hive RPC tests #8909

Merged
merged 4 commits into from
Dec 7, 2023
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
21 changes: 21 additions & 0 deletions cmd/rpcdaemon/cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,27 @@ func startRegularRpcServer(ctx context.Context, cfg *httpcfg.HttpCfg, rpcAPI []r
return err
}

// Separate Websocket handler if websocket port flag specified
if cfg.WebsocketEnabled && cfg.WebsocketPort != cfg.HttpPort {
wsEndpoint := fmt.Sprintf("tcp://%s:%d", cfg.HttpListenAddress, cfg.WebsocketPort)
wsApiHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if isWebsocket(r) {
wsHandler.ServeHTTP(w, r)
}
})
wsListener, wsAddr, err := node.StartHTTPEndpoint(wsEndpoint, &node.HttpEndpointConfig{Timeouts: cfg.HTTPTimeouts}, wsApiHandler)
if err != nil {
return fmt.Errorf("could not start separate Websocket RPC api at port %d: %w", cfg.WebsocketPort, err)
}
info = append(info, "websocket.url", wsAddr)
defer func() {
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
_ = wsListener.Shutdown(shutdownCtx)
logger.Info("HTTP endpoint closed", "url", wsAddr)
}()
}

if cfg.HttpServerEnabled {
httpEndpoint := fmt.Sprintf("tcp://%s:%d", cfg.HttpListenAddress, cfg.HttpPort)
if cfg.HttpURL != "" {
Expand Down
1 change: 1 addition & 0 deletions cmd/rpcdaemon/cli/httpcfg/http_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type HttpCfg struct {
API []string
Gascap uint64
MaxTraces uint64
WebsocketPort int
WebsocketEnabled bool
WebsocketCompression bool
RpcAllowListFilePath string
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ var DefaultFlags = []cli.Flag{
&utils.HTTPVirtualHostsFlag,
&utils.AuthRpcVirtualHostsFlag,
&utils.HTTPApiFlag,
&utils.WSPortFlag,
&utils.WSEnabledFlag,
&utils.WsCompressionFlag,
&utils.HTTPTraceFlag,
Expand Down
4 changes: 2 additions & 2 deletions turbo/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,8 @@ func setEmbeddedRpcDaemon(ctx *cli.Context, cfg *nodecfg.Config, logger log.Logg
WriteTimeout: ctx.Duration(AuthRpcWriteTimeoutFlag.Name),
IdleTimeout: ctx.Duration(HTTPIdleTimeoutFlag.Name),
},
EvmCallTimeout: ctx.Duration(EvmCallTimeoutFlag.Name),

EvmCallTimeout: ctx.Duration(EvmCallTimeoutFlag.Name),
WebsocketPort: ctx.Int(utils.WSPortFlag.Name),
WebsocketEnabled: ctx.IsSet(utils.WSEnabledFlag.Name),
RpcBatchConcurrency: ctx.Uint(utils.RpcBatchConcurrencyFlag.Name),
RpcStreamingDisable: ctx.Bool(utils.RpcStreamingDisableFlag.Name),
Expand Down
Loading