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

### Context
**Websocket port flag**
Hive tests for RPC suite depend on the (geth) default 8546 port. So,
opening one more listener for this additional port if `ws.port` was
specified. This flag isn't used in Erigon, as it shares port with http
listener. Normally, one may not specify and it offers no other benefit.
This commit is contained in:
Somnath 2023-12-07 14:59:22 +04:00 committed by GitHub
parent f3822b17d4
commit 5987d4ef72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 2 deletions

View File

@ -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 != "" {

View File

@ -43,6 +43,7 @@ type HttpCfg struct {
API []string
Gascap uint64
MaxTraces uint64
WebsocketPort int
WebsocketEnabled bool
WebsocketCompression bool
RpcAllowListFilePath string

View File

@ -63,6 +63,7 @@ var DefaultFlags = []cli.Flag{
&utils.HTTPVirtualHostsFlag,
&utils.AuthRpcVirtualHostsFlag,
&utils.HTTPApiFlag,
&utils.WSPortFlag,
&utils.WSEnabledFlag,
&utils.WsCompressionFlag,
&utils.HTTPTraceFlag,

View File

@ -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),