From 80539d9028db7a94db0da64b9ed47fb9393d6773 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Wed, 3 Jun 2020 13:11:43 -0500 Subject: [PATCH] Enable JSON-HTTP Gateway by Default on Port 3000 (#6090) * default port 3000 http gateway * Merge refs/heads/master into default-gateway * Merge refs/heads/master into default-gateway * fix broken node test * disable grpc gateway * Merge refs/heads/master into default-gateway * Merge refs/heads/master into default-gateway --- beacon-chain/flags/base.go | 6 ++++++ beacon-chain/gateway/gateway.go | 8 +++++--- beacon-chain/main.go | 1 + beacon-chain/node/node.go | 36 ++++++++++++++++----------------- beacon-chain/usage.go | 1 + 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/beacon-chain/flags/base.go b/beacon-chain/flags/base.go index 5d552fc53..f6fcf874d 100644 --- a/beacon-chain/flags/base.go +++ b/beacon-chain/flags/base.go @@ -60,10 +60,16 @@ var ( Name: "tls-key", Usage: "Key for secure gRPC. Pass this and the tls-cert flag in order to use gRPC securely.", } + // DisableGRPCGateway for JSON-HTTP requests to the beacon node. + DisableGRPCGateway = &cli.BoolFlag{ + Name: "disable-grpc-gateway", + Usage: "Disable the gRPC gateway for JSON-HTTP requests", + } // GRPCGatewayPort enables a gRPC gateway to be exposed for Prysm. GRPCGatewayPort = &cli.IntFlag{ Name: "grpc-gateway-port", Usage: "Enable gRPC gateway for JSON requests", + Value: 3000, } // GPRCGatewayCorsDomain serves preflight requests when serving gRPC JSON gateway. GPRCGatewayCorsDomain = &cli.StringFlag{ diff --git a/beacon-chain/gateway/gateway.go b/beacon-chain/gateway/gateway.go index 1bdce237d..5c71dff29 100644 --- a/beacon-chain/gateway/gateway.go +++ b/beacon-chain/gateway/gateway.go @@ -41,7 +41,7 @@ func (g *Gateway) Start() { ctx, cancel := context.WithCancel(g.ctx) g.cancel = cancel - log.WithField("address", g.gatewayAddr).Info("Starting gRPC gateway.") + log.WithField("address", g.gatewayAddr).Info("Starting JSON-HTTP API") conn, err := g.dial(ctx, "tcp", g.remoteAddr) if err != nil { @@ -106,8 +106,10 @@ func (g *Gateway) Status() error { // Stop the gateway with a graceful shutdown. func (g *Gateway) Stop() error { - if err := g.server.Shutdown(g.ctx); err != nil { - log.WithError(err).Error("Failed to shut down server") + if g.server != nil { + if err := g.server.Shutdown(g.ctx); err != nil { + log.WithError(err).Error("Failed to shut down server") + } } if g.cancel != nil { diff --git a/beacon-chain/main.go b/beacon-chain/main.go index 5b71aa9d8..96222e25c 100644 --- a/beacon-chain/main.go +++ b/beacon-chain/main.go @@ -32,6 +32,7 @@ var appFlags = []cli.Flag{ flags.RPCPort, flags.CertFlag, flags.KeyFlag, + flags.DisableGRPCGateway, flags.GRPCGatewayPort, flags.MinSyncPeers, flags.RPCMaxPageSize, diff --git a/beacon-chain/node/node.go b/beacon-chain/node/node.go index 2e3d70cb0..e8bf483a5 100644 --- a/beacon-chain/node/node.go +++ b/beacon-chain/node/node.go @@ -591,25 +591,25 @@ func (b *BeaconNode) registerPrometheusService() error { } func (b *BeaconNode) registerGRPCGateway() error { - gatewayPort := b.cliCtx.Int(flags.GRPCGatewayPort.Name) - if gatewayPort > 0 { - selfAddress := fmt.Sprintf("127.0.0.1:%d", b.cliCtx.Int(flags.RPCPort.Name)) - gatewayAddress := fmt.Sprintf("0.0.0.0:%d", gatewayPort) - allowedOrigins := strings.Split(b.cliCtx.String(flags.GPRCGatewayCorsDomain.Name), ",") - enableDebugRPCEndpoints := b.cliCtx.Bool(flags.EnableDebugRPCEndpoints.Name) - return b.services.RegisterService( - gateway.New( - b.ctx, - selfAddress, - gatewayAddress, - nil, /*optional mux*/ - allowedOrigins, - enableDebugRPCEndpoints, - b.cliCtx.Uint64(cmd.GrpcMaxCallRecvMsgSizeFlag.Name), - ), - ) + if b.cliCtx.Bool(flags.DisableGRPCGateway.Name) { + return nil } - return nil + gatewayPort := b.cliCtx.Int(flags.GRPCGatewayPort.Name) + selfAddress := fmt.Sprintf("127.0.0.1:%d", b.cliCtx.Int(flags.RPCPort.Name)) + gatewayAddress := fmt.Sprintf("0.0.0.0:%d", gatewayPort) + allowedOrigins := strings.Split(b.cliCtx.String(flags.GPRCGatewayCorsDomain.Name), ",") + enableDebugRPCEndpoints := b.cliCtx.Bool(flags.EnableDebugRPCEndpoints.Name) + return b.services.RegisterService( + gateway.New( + b.ctx, + selfAddress, + gatewayAddress, + nil, /*optional mux*/ + allowedOrigins, + enableDebugRPCEndpoints, + b.cliCtx.Uint64(cmd.GrpcMaxCallRecvMsgSizeFlag.Name), + ), + ) } func (b *BeaconNode) registerInteropServices() error { diff --git a/beacon-chain/usage.go b/beacon-chain/usage.go index 0d0b36284..918562776 100644 --- a/beacon-chain/usage.go +++ b/beacon-chain/usage.go @@ -89,6 +89,7 @@ var appHelpFlagGroups = []flagGroup{ flags.RPCMaxPageSize, flags.CertFlag, flags.KeyFlag, + flags.DisableGRPCGateway, flags.GRPCGatewayPort, flags.HTTPWeb3ProviderFlag, flags.SetGCPercent,