diff --git a/server/config/config.go b/server/config/config.go index f817efb8e9f1..34e6e61365f7 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -21,6 +21,14 @@ const ( // DefaultGRPCWebAddress defines the default address to bind the gRPC-web server to. DefaultGRPCWebAddress = "0.0.0.0:9091" + + // DefaultGRPCMaxRecvMsgSize defines the default gRPC max message size in + // bytes the server can receive. + DefaultGRPCMaxRecvMsgSize = 1024 * 1024 * 10 + + // DefaultGRPCMaxSendMsgSize defines the default gRPC max message size in + // bytes the server can send. + DefaultGRPCMaxSendMsgSize = math.MaxInt32 ) // BaseConfig defines the server's basic configuration @@ -235,8 +243,8 @@ func DefaultConfig() *Config { GRPC: GRPCConfig{ Enable: true, Address: DefaultGRPCAddress, - MaxRecvMsgSize: 1024 * 1024 * 10, - MaxSendMsgSize: math.MaxInt32, + MaxRecvMsgSize: DefaultGRPCMaxRecvMsgSize, + MaxSendMsgSize: DefaultGRPCMaxSendMsgSize, }, Rosetta: RosettaConfig{ Enable: false, diff --git a/server/grpc/server.go b/server/grpc/server.go index 105f55d4751f..1e44b0d6099a 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -17,9 +17,19 @@ import ( // StartGRPCServer starts a gRPC server on the given address. func StartGRPCServer(clientCtx client.Context, app types.Application, cfg config.GRPCConfig) (*grpc.Server, error) { + maxSendMsgSize := cfg.MaxSendMsgSize + if maxSendMsgSize == 0 { + maxSendMsgSize = config.DefaultGRPCMaxSendMsgSize + } + + maxRecvMsgSize := cfg.MaxRecvMsgSize + if maxRecvMsgSize == 0 { + maxRecvMsgSize = config.DefaultGRPCMaxRecvMsgSize + } + grpcSrv := grpc.NewServer( - grpc.MaxSendMsgSize(cfg.MaxSendMsgSize), - grpc.MaxRecvMsgSize(cfg.MaxRecvMsgSize), + grpc.MaxSendMsgSize(maxSendMsgSize), + grpc.MaxRecvMsgSize(maxRecvMsgSize), ) app.RegisterGRPCServer(grpcSrv) diff --git a/server/start.go b/server/start.go index 3750bc975cae..2c918edebd74 100644 --- a/server/start.go +++ b/server/start.go @@ -29,6 +29,7 @@ import ( pruningtypes "github.com/cosmos/cosmos-sdk/pruning/types" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" + serverconfig "github.com/cosmos/cosmos-sdk/server/config" servergrpc "github.com/cosmos/cosmos-sdk/server/grpc" "github.com/cosmos/cosmos-sdk/server/rosetta" crgserver "github.com/cosmos/cosmos-sdk/server/rosetta/lib/server" @@ -155,10 +156,10 @@ which accepts a path for the resulting pprof file. cmd.Flags().Uint64(FlagMinRetainBlocks, 0, "Minimum block height offset during ABCI commit to prune Tendermint blocks") cmd.Flags().Bool(flagGRPCEnable, true, "Define if the gRPC server should be enabled") - cmd.Flags().String(flagGRPCAddress, config.DefaultGRPCAddress, "the gRPC server address to listen on") + cmd.Flags().String(flagGRPCAddress, serverconfig.DefaultGRPCAddress, "the gRPC server address to listen on") cmd.Flags().Bool(flagGRPCWebEnable, true, "Define if the gRPC-Web server should be enabled. (Note: gRPC must also be enabled.)") - cmd.Flags().String(flagGRPCWebAddress, config.DefaultGRPCWebAddress, "The gRPC-Web server address to listen on") + cmd.Flags().String(flagGRPCWebAddress, serverconfig.DefaultGRPCWebAddress, "The gRPC-Web server address to listen on") cmd.Flags().Uint64(FlagStateSyncSnapshotInterval, 0, "State sync snapshot interval") cmd.Flags().Uint32(FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep") @@ -304,15 +305,27 @@ func startInProcess(ctx *Context, clientCtx client.Context, appCreator types.App if err != nil { return err } + + maxSendMsgSize := config.GRPC.MaxSendMsgSize + if maxSendMsgSize == 0 { + maxSendMsgSize = serverconfig.DefaultGRPCMaxSendMsgSize + } + + maxRecvMsgSize := config.GRPC.MaxRecvMsgSize + if maxRecvMsgSize == 0 { + maxRecvMsgSize = serverconfig.DefaultGRPCMaxRecvMsgSize + } + grpcAddress := fmt.Sprintf("127.0.0.1:%s", port) + // If grpc is enabled, configure grpc client for grpc gateway. grpcClient, err := grpc.Dial( grpcAddress, grpc.WithInsecure(), grpc.WithDefaultCallOptions( grpc.ForceCodec(encoding.GetCodec(proto.Name)), - grpc.MaxCallRecvMsgSize(config.GRPC.MaxRecvMsgSize), - grpc.MaxCallSendMsgSize(config.GRPC.MaxSendMsgSize), + grpc.MaxCallRecvMsgSize(maxRecvMsgSize), + grpc.MaxCallSendMsgSize(maxSendMsgSize), ), ) if err != nil {