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
This commit is contained in:
Raul Jordan 2020-06-03 13:11:43 -05:00 committed by GitHub
parent 75aaa5e07b
commit 80539d9028
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 21 deletions

View File

@ -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{

View File

@ -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 {

View File

@ -32,6 +32,7 @@ var appFlags = []cli.Flag{
flags.RPCPort,
flags.CertFlag,
flags.KeyFlag,
flags.DisableGRPCGateway,
flags.GRPCGatewayPort,
flags.MinSyncPeers,
flags.RPCMaxPageSize,

View File

@ -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 {

View File

@ -89,6 +89,7 @@ var appHelpFlagGroups = []flagGroup{
flags.RPCMaxPageSize,
flags.CertFlag,
flags.KeyFlag,
flags.DisableGRPCGateway,
flags.GRPCGatewayPort,
flags.HTTPWeb3ProviderFlag,
flags.SetGCPercent,