Skip to content

Commit 38f2ec6

Browse files
Update gateway max resv size to 16MB (#5756)
* Update max resv size to 16MB * Merge refs/heads/master into 5752 * Use GrpcMaxCallRecvMsgSizeFlag for beacon node * Merge branch '5752' of github.com:prysmaticlabs/prysm into 5752 * Typo * Fix server * Merge refs/heads/master into 5752 * Merge refs/heads/master into 5752 * Merge refs/heads/master into 5752 * Merge refs/heads/master into 5752 * Update beacon-chain/gateway/server/main.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Merge refs/heads/master into 5752
1 parent ef4dead commit 38f2ec6

File tree

10 files changed

+32
-13
lines changed

10 files changed

+32
-13
lines changed

beacon-chain/gateway/gateway.go

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type Gateway struct {
3232
allowedOrigins []string
3333
startFailure error
3434
enableDebugRPCEndpoints bool
35+
maxCallRecvMsgSize uint64
3536
}
3637

3738
// Start the gateway service. This serves the HTTP JSON traffic on the specified
@@ -42,7 +43,7 @@ func (g *Gateway) Start() {
4243

4344
log.WithField("address", g.gatewayAddr).Info("Starting gRPC gateway.")
4445

45-
conn, err := dial(ctx, "tcp", g.remoteAddr)
46+
conn, err := g.dial(ctx, "tcp", g.remoteAddr)
4647
if err != nil {
4748
log.WithError(err).Error("Failed to connect to gRPC server")
4849
g.startFailure = err
@@ -125,6 +126,7 @@ func New(
125126
mux *http.ServeMux,
126127
allowedOrigins []string,
127128
enableDebugRPCEndpoints bool,
129+
maxCallRecvMsgSize uint64,
128130
) *Gateway {
129131
if mux == nil {
130132
mux = http.NewServeMux()
@@ -137,14 +139,15 @@ func New(
137139
mux: mux,
138140
allowedOrigins: allowedOrigins,
139141
enableDebugRPCEndpoints: enableDebugRPCEndpoints,
142+
maxCallRecvMsgSize: maxCallRecvMsgSize,
140143
}
141144
}
142145

143146
// dial the gRPC server.
144-
func dial(ctx context.Context, network, addr string) (*grpc.ClientConn, error) {
147+
func (g *Gateway) dial(ctx context.Context, network, addr string) (*grpc.ClientConn, error) {
145148
switch network {
146149
case "tcp":
147-
return dialTCP(ctx, addr)
150+
return g.dialTCP(ctx, addr)
148151
case "unix":
149152
return dialUnix(ctx, addr)
150153
default:
@@ -154,8 +157,18 @@ func dial(ctx context.Context, network, addr string) (*grpc.ClientConn, error) {
154157

155158
// dialTCP creates a client connection via TCP.
156159
// "addr" must be a valid TCP address with a port number.
157-
func dialTCP(ctx context.Context, addr string) (*grpc.ClientConn, error) {
158-
return grpc.DialContext(ctx, addr, grpc.WithInsecure())
160+
func (g *Gateway) dialTCP(ctx context.Context, addr string) (*grpc.ClientConn, error) {
161+
opts := []grpc.DialOption{grpc.WithInsecure()}
162+
163+
if g.enableDebugRPCEndpoints {
164+
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(int(g.maxCallRecvMsgSize))))
165+
}
166+
167+
return grpc.DialContext(
168+
ctx,
169+
addr,
170+
opts...,
171+
)
159172
}
160173

161174
// dialUnix creates a client connection via a unix domain socket.

beacon-chain/gateway/server/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121
debug = flag.Bool("debug", false, "Enable debug logging")
2222
allowedOrigins = flag.String("corsdomain", "", "A comma separated list of CORS domains to allow")
2323
enableDebugRPCEndpoints = flag.Bool("enable-debug-rpc-endpoints", false, "Enable debug rpc endpoints such as /eth/v1alpha1/beacon/state")
24+
grpcMaxMsgSize = flag.Int("grpc-max-msg-size", 1<<22, "Integer to define max recieve message call size")
2425
)
2526

2627
func init() {
@@ -43,6 +44,7 @@ func main() {
4344
mux,
4445
strings.Split(*allowedOrigins, ","),
4546
*enableDebugRPCEndpoints,
47+
uint64(*grpcMaxMsgSize),
4648
)
4749
mux.HandleFunc("/swagger/", gateway.SwaggerServer())
4850
mux.HandleFunc("/healthz", healthzServer(gw))

beacon-chain/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ var appFlags = []cli.Flag{
8888
cmd.EnableUPnPFlag,
8989
cmd.ConfigFileFlag,
9090
cmd.ChainConfigFileFlag,
91+
cmd.GrpcMaxCallRecvMsgSizeFlag,
9192
}
9293

9394
func init() {

beacon-chain/node/node.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ func (b *BeaconNode) registerGRPCGateway() error {
594594
nil, /*optional mux*/
595595
allowedOrigins,
596596
enableDebugRPCEndpoints,
597+
b.cliCtx.Uint64(cmd.GrpcMaxCallRecvMsgSizeFlag.Name),
597598
),
598599
)
599600
}

beacon-chain/usage.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ var appHelpFlagGroups = []flagGroup{
6262
cmd.ClearDB,
6363
cmd.ConfigFileFlag,
6464
cmd.ChainConfigFileFlag,
65+
cmd.GrpcMaxCallRecvMsgSizeFlag,
6566
},
6667
},
6768
{

shared/cmd/flags.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,4 +179,10 @@ var (
179179
Name: "chain-config-file",
180180
Usage: "The path to a YAML file with chain config values",
181181
}
182+
// GrpcMaxCallRecvMsgSizeFlag defines the max call message size for GRPC
183+
GrpcMaxCallRecvMsgSizeFlag = &cli.IntFlag{
184+
Name: "grpc-max-msg-size",
185+
Usage: "Integer to define max recieve message call size (default: 4194304 (for 40MB))",
186+
Value: 1 << 22,
187+
}
182188
)

validator/flags/flags.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ var (
3333
Name: "graffiti",
3434
Usage: "String to include in proposed blocks",
3535
}
36-
// GrpcMaxCallRecvMsgSizeFlag defines the max call message size for GRPC
37-
GrpcMaxCallRecvMsgSizeFlag = &cli.IntFlag{
38-
Name: "grpc-max-msg-size",
39-
Usage: "Integer to define max recieve message call size (default: 52428800 (for 50Mb)).",
40-
}
4136
// GrpcRetriesFlag defines the number of times to retry a failed gRPC request.
4237
GrpcRetriesFlag = &cli.UintFlag{
4338
Name: "grpc-retries",

validator/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ var appFlags = []cli.Flag{
4747
flags.UnencryptedKeysFlag,
4848
flags.InteropStartIndex,
4949
flags.InteropNumValidators,
50-
flags.GrpcMaxCallRecvMsgSizeFlag,
5150
flags.GrpcRetriesFlag,
5251
flags.GrpcHeadersFlag,
5352
flags.KeyManager,
@@ -72,6 +71,7 @@ var appFlags = []cli.Flag{
7271
cmd.LogFileName,
7372
cmd.ConfigFileFlag,
7473
cmd.ChainConfigFileFlag,
74+
cmd.GrpcMaxCallRecvMsgSizeFlag,
7575
}
7676

7777
func init() {

validator/node/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func (s *ValidatorClient) registerClientService(ctx *cli.Context, keyManager key
183183
emitAccountMetrics := ctx.Bool(flags.AccountMetricsFlag.Name)
184184
cert := ctx.String(flags.CertFlag.Name)
185185
graffiti := ctx.String(flags.GraffitiFlag.Name)
186-
maxCallRecvMsgSize := ctx.Int(flags.GrpcMaxCallRecvMsgSizeFlag.Name)
186+
maxCallRecvMsgSize := ctx.Int(cmd.GrpcMaxCallRecvMsgSizeFlag.Name)
187187
grpcRetries := ctx.Uint(flags.GrpcRetriesFlag.Name)
188188
v, err := client.NewValidatorService(context.Background(), &client.Config{
189189
Endpoint: endpoint,

validator/usage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ var appHelpFlagGroups = []flagGroup{
5757
cmd.LogFileName,
5858
cmd.ConfigFileFlag,
5959
cmd.ChainConfigFileFlag,
60+
cmd.GrpcMaxCallRecvMsgSizeFlag,
6061
},
6162
},
6263
{
@@ -82,7 +83,6 @@ var appHelpFlagGroups = []flagGroup{
8283
flags.DisablePenaltyRewardLogFlag,
8384
flags.UnencryptedKeysFlag,
8485
flags.GraffitiFlag,
85-
flags.GrpcMaxCallRecvMsgSizeFlag,
8686
flags.GrpcRetriesFlag,
8787
flags.GrpcHeadersFlag,
8888
flags.AccountMetricsFlag,

0 commit comments

Comments
 (0)