Expose eth API on the same ports as engine API (#3633)

* Expose port 8551 (authenticated Engine API)

* Expose eth API on the same ports as engine API
This commit is contained in:
Andrew Ashikhmin 2022-03-02 14:58:46 +01:00 committed by GitHub
parent 47df98a499
commit f58e80bd56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 27 additions and 22 deletions

View File

@ -21,7 +21,7 @@ RUN chown -R erigon:erigon /home/erigon
USER erigon USER erigon
EXPOSE 8545 8550 8546 30303 30303/udp 30304 30304/udp 8080 9090 6060 EXPOSE 8545 8550 8551 8546 30303 30303/udp 30304 30304/udp 8080 9090 6060
# https://github.com/opencontainers/image-spec/blob/main/annotations.md # https://github.com/opencontainers/image-spec/blob/main/annotations.md
ARG BUILD_DATE ARG BUILD_DATE

View File

@ -322,14 +322,14 @@ internally for rpcdaemon or other connections, (e.g. rpcdaemon -> erigon)
#### `rpcdaemon` ports #### `rpcdaemon` ports
| Port | Protocol | Purpose | Expose | | Port | Protocol | Purpose | Expose |
|:-----:|:---------:|:-----------------:|:-------:| |:-----:|:---------:|:------------------:|:-------:|
| 8545 | TCP | HTTP & WebSockets | Private | | 8545 | TCP | HTTP & WebSockets | Private |
|:-----:|:---------:|:-----------------:|:-------:| | 8550 | TCP | HTTP | Private |
| 8550 | TCP | HTTP | Private | | 8551 | TCP | HTTP with JWS auth | Private |
Typically 8545 is exposed only internally for JSON-RPC queries. Both HTTP and WebSocket connections are on the same port. Typically 8545 is exposed only internally for JSON-RPC queries. Both HTTP and WebSocket connections are on the same port.
Typically 8550 is exposed only internally for the engineApi JSON-RPC queries Typically 8550 (unauthenticated) and 8551 (authenticated) are exposed only internally for the Engine API JSON-RPC queries.
#### `sentry` ports #### `sentry` ports

View File

@ -382,7 +382,7 @@ func RemoteServices(ctx context.Context, cfg httpcfg.HttpCfg, logger log.Logger,
func StartRpcServer(ctx context.Context, cfg httpcfg.HttpCfg, rpcAPI []rpc.API) error { func StartRpcServer(ctx context.Context, cfg httpcfg.HttpCfg, rpcAPI []rpc.API) error {
var engineListener *http.Server var engineListener *http.Server
var engineListenerAuth *http.Server var engineListenerAuth *http.Server
var enginesrv *rpc.Server var engineSrv *rpc.Server
var engineHttpEndpoint string var engineHttpEndpoint string
// register apis and create handler stack // register apis and create handler stack
@ -407,14 +407,19 @@ func StartRpcServer(ctx context.Context, cfg httpcfg.HttpCfg, rpcAPI []rpc.API)
} }
} }
var apiFlags []string if len(engineAPI) != 0 {
var engineFlag []string // eth API should also be exposed on the same port as engine API
for _, api := range rpcAPI {
if api.Namespace == "eth" {
engineAPI = append(engineAPI, api)
}
}
}
var apiFlags []string
for _, flag := range cfg.API { for _, flag := range cfg.API {
if flag != "engine" { if flag != "engine" {
apiFlags = append(apiFlags, flag) apiFlags = append(apiFlags, flag)
} else {
engineFlag = append(engineFlag, flag)
} }
} }
@ -441,7 +446,7 @@ func StartRpcServer(ctx context.Context, cfg httpcfg.HttpCfg, rpcAPI []rpc.API)
"ws.compression", cfg.WebsocketCompression, "grpc", cfg.GRPCServerEnabled} "ws.compression", cfg.WebsocketCompression, "grpc", cfg.GRPCServerEnabled}
if len(engineAPI) > 0 { if len(engineAPI) > 0 {
engineListener, engineListenerAuth, enginesrv, engineHttpEndpoint, err = createEngineListener(cfg, engineAPI, engineFlag) engineListener, engineListenerAuth, engineSrv, engineHttpEndpoint, err = createEngineListener(cfg, engineAPI)
if err != nil { if err != nil {
return fmt.Errorf("could not start RPC api for engine: %w", err) return fmt.Errorf("could not start RPC api for engine: %w", err)
} }
@ -471,8 +476,8 @@ func StartRpcServer(ctx context.Context, cfg httpcfg.HttpCfg, rpcAPI []rpc.API)
defer func() { defer func() {
srv.Stop() srv.Stop()
if enginesrv != nil { if engineSrv != nil {
enginesrv.Stop() engineSrv.Stop()
} }
shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) shutdownCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel() defer cancel()
@ -580,23 +585,23 @@ func createHandler(cfg httpcfg.HttpCfg, apiList []rpc.API, httpHandler http.Hand
return handler, nil return handler, nil
} }
func createEngineListener(cfg httpcfg.HttpCfg, engineApi []rpc.API, engineFlag []string) (*http.Server, *http.Server, *rpc.Server, string, error) { func createEngineListener(cfg httpcfg.HttpCfg, engineApi []rpc.API) (*http.Server, *http.Server, *rpc.Server, string, error) {
engineHttpEndpoint := fmt.Sprintf("%s:%d", cfg.EngineHTTPListenAddress, cfg.EnginePort) engineHttpEndpoint := fmt.Sprintf("%s:%d", cfg.EngineHTTPListenAddress, cfg.EnginePort)
engineHttpEndpointAuth := fmt.Sprintf("%s:%d", cfg.EngineHTTPListenAddress, cfg.EnginePort+1) engineHttpEndpointAuth := fmt.Sprintf("%s:%d", cfg.EngineHTTPListenAddress, cfg.EnginePort+1)
enginesrv := rpc.NewServer(cfg.RpcBatchConcurrency) engineSrv := rpc.NewServer(cfg.RpcBatchConcurrency)
allowListForRPC, err := parseAllowListForRPC(cfg.RpcAllowListFilePath) allowListForRPC, err := parseAllowListForRPC(cfg.RpcAllowListFilePath)
if err != nil { if err != nil {
return nil, nil, nil, "", err return nil, nil, nil, "", err
} }
enginesrv.SetAllowList(allowListForRPC) engineSrv.SetAllowList(allowListForRPC)
if err := node.RegisterApisFromWhitelist(engineApi, engineFlag, enginesrv, false); err != nil { if err := node.RegisterApisFromWhitelist(engineApi, nil, engineSrv, true); err != nil {
return nil, nil, nil, "", fmt.Errorf("could not start register RPC engine api: %w", err) return nil, nil, nil, "", fmt.Errorf("could not start register RPC engine api: %w", err)
} }
engineHttpHandler := node.NewHTTPHandlerStack(enginesrv, cfg.HttpCORSDomain, cfg.HttpVirtualHost, cfg.HttpCompression) engineHttpHandler := node.NewHTTPHandlerStack(engineSrv, cfg.HttpCORSDomain, cfg.HttpVirtualHost, cfg.HttpCompression)
engineApiHandler, err := createHandler(cfg, engineApi, engineHttpHandler, nil, false) engineApiHandler, err := createHandler(cfg, engineApi, engineHttpHandler, nil, false)
if err != nil { if err != nil {
return nil, nil, nil, "", err return nil, nil, nil, "", err
@ -622,6 +627,5 @@ func createEngineListener(cfg httpcfg.HttpCfg, engineApi []rpc.API, engineFlag [
engineInfoAuth := []interface{}{"url", engineHttpEndpointAuth} engineInfoAuth := []interface{}{"url", engineHttpEndpointAuth}
log.Info("HTTP endpoint opened for auth engine", engineInfoAuth...) log.Info("HTTP endpoint opened for auth engine", engineInfoAuth...)
return engineListener, engineListenerAuth, enginesrv, engineHttpEndpoint, nil return engineListener, engineListenerAuth, engineSrv, engineHttpEndpoint, nil
} }

View File

@ -53,6 +53,7 @@ services:
ports: ports:
- "8545:8545" - "8545:8545"
- "8550:8550" - "8550:8550"
- "8551:8551"
restart: unless-stopped restart: unless-stopped
downloader: # Service to download/seed historical data (need only if you use --experimental.snapshot) downloader: # Service to download/seed historical data (need only if you use --experimental.snapshot)