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 JSON-HTTP Gateway by Default on Port 3000 #6090

Merged
merged 7 commits into from
Jun 3, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions beacon-chain/flags/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ var (
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{
Expand Down
8 changes: 5 additions & 3 deletions beacon-chain/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
33 changes: 15 additions & 18 deletions beacon-chain/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -592,24 +592,21 @@ 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),
),
)
}
return nil
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 {
Expand Down