diff --git a/baseapp/grpcserver.go b/baseapp/grpcserver.go index c162bebf1ee3..c14fcb06937b 100644 --- a/baseapp/grpcserver.go +++ b/baseapp/grpcserver.go @@ -23,6 +23,12 @@ import ( // RegisterGRPCServer registers gRPC services directly with the gRPC server. func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) { + app.RegisterGRPCServerWithSkipCheckHeader(server, false) +} + +// RegisterGRPCServerWithSkipCheckHeader registers gRPC services with the specified gRPC server +// and bypass check header flag. +func (app *BaseApp) RegisterGRPCServerWithSkipCheckHeader(server gogogrpc.Server, skipCheckHeader bool) { // Define an interceptor for all gRPC queries: this interceptor will create // a new sdk.Context, and pass it into the query handler. interceptor := func(grpcCtx context.Context, req interface{}, _ *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) { @@ -48,7 +54,7 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) { // Create the sdk.Context. Passing false as 2nd arg, as we can't // actually support proofs with gRPC right now. - sdkCtx, err := app.CreateQueryContext(height, false) + sdkCtx, err := app.CreateQueryContextWithCheckHeader(height, false, !skipCheckHeader) if err != nil { return nil, err } diff --git a/server/config/config.go b/server/config/config.go index b75b5bd87f8c..92f9bf41b13a 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -139,6 +139,9 @@ type GRPCConfig struct { // MaxSendMsgSize defines the max message size in bytes the server can send. // The default value is math.MaxInt32. MaxSendMsgSize int `mapstructure:"max-send-msg-size"` + + // SkipCheckHeader defines if the gRPC server should bypass check header. + SkipCheckHeader bool `mapstructure:"skip-check-header"` } // StateSyncConfig defines the state sync snapshot configuration. diff --git a/server/config/config.toml.tpl b/server/config/config.toml.tpl index 632fa8def933..92f898ece8e9 100644 --- a/server/config/config.toml.tpl +++ b/server/config/config.toml.tpl @@ -171,6 +171,9 @@ max-recv-msg-size = "{{ .GRPC.MaxRecvMsgSize }}" # The default value is math.MaxInt32. max-send-msg-size = "{{ .GRPC.MaxSendMsgSize }}" +# SkipCheckHeader defines if the gRPC server should bypass check header. +skip-check-header = {{ .GRPC.SkipCheckHeader }} + ############################################################################### ### State Sync Configuration ### ############################################################################### diff --git a/server/grpc/server.go b/server/grpc/server.go index ae4c376191d2..fe9061dde8da 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -20,7 +20,9 @@ import ( // NewGRPCServer returns a correctly configured and initialized gRPC server. // Note, the caller is responsible for starting the server. See StartGRPCServer. -func NewGRPCServer(clientCtx client.Context, app interface{ RegisterGRPCServer(gogogrpcserver.Server) }, cfg config.GRPCConfig) (*grpc.Server, error) { +func NewGRPCServer(clientCtx client.Context, app interface { + RegisterGRPCServerWithSkipCheckHeader(gogogrpcserver.Server, bool) +}, cfg config.GRPCConfig) (*grpc.Server, error) { maxSendMsgSize := cfg.MaxSendMsgSize if maxSendMsgSize == 0 { maxSendMsgSize = config.DefaultGRPCMaxSendMsgSize @@ -37,7 +39,7 @@ func NewGRPCServer(clientCtx client.Context, app interface{ RegisterGRPCServer(g grpc.MaxRecvMsgSize(maxRecvMsgSize), ) - app.RegisterGRPCServer(grpcSrv) + app.RegisterGRPCServerWithSkipCheckHeader(grpcSrv, cfg.SkipCheckHeader) // Reflection allows consumers to build dynamic clients that can write to any // Cosmos SDK application without relying on application packages at compile diff --git a/server/start.go b/server/start.go index 7c74255e6992..4c612dc5fc74 100644 --- a/server/start.go +++ b/server/start.go @@ -100,9 +100,10 @@ const ( // gRPC-related flags - flagGRPCOnly = "grpc-only" - flagGRPCEnable = "grpc.enable" - flagGRPCAddress = "grpc.address" + flagGRPCOnly = "grpc-only" + flagGRPCEnable = "grpc.enable" + flagGRPCAddress = "grpc.address" + flagGRPCSkipCheckHeader = "grpc.skip-check-header" // mempool flags @@ -1028,6 +1029,7 @@ func addStartNodeFlags[T types.Application](cmd *cobra.Command, opts StartCmdOpt cmd.Flags().Bool(flagGRPCOnly, false, "Start the node in gRPC query only mode (no CometBFT process is started)") cmd.Flags().Bool(flagGRPCEnable, true, "Define if the gRPC server should be enabled") cmd.Flags().String(flagGRPCAddress, serverconfig.DefaultGRPCAddress, "the gRPC server address to listen on") + cmd.Flags().Bool(flagGRPCSkipCheckHeader, false, "Define if the gRPC server should bypass check header") cmd.Flags().Uint64(FlagStateSyncSnapshotInterval, 0, "State sync snapshot interval") cmd.Flags().Uint32(FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep") cmd.Flags().Bool(FlagDisableIAVLFastNode, false, "Disable fast node for IAVL tree") diff --git a/server/types/app.go b/server/types/app.go index c1a67b2ceec3..40f4e7e57988 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -38,9 +38,9 @@ type ( RegisterAPIRoutes(*api.Server, config.APIConfig) - // RegisterGRPCServer registers gRPC services directly with the gRPC - // server. - RegisterGRPCServer(grpc.Server) + // RegisterGRPCServerWithSkipCheckHeader registers gRPC services directly with the gRPC + // server and bypass check header flag. + RegisterGRPCServerWithSkipCheckHeader(grpc.Server, bool) // RegisterTxService registers the gRPC Query service for tx (such as tx // simulation, fetching txs by hash...). diff --git a/server/v2/api/grpc/config.go b/server/v2/api/grpc/config.go index 4e9cabc7a418..6b09dd7a7978 100644 --- a/server/v2/api/grpc/config.go +++ b/server/v2/api/grpc/config.go @@ -26,6 +26,9 @@ type Config struct { // MaxSendMsgSize defines the max message size in bytes the server can send. // The default value is math.MaxInt32. MaxSendMsgSize int `mapstructure:"max-send-msg-size" toml:"max-send-msg-size" comment:"MaxSendMsgSize defines the max message size in bytes the server can send.\nThe default value is math.MaxInt32."` + + // SkipCheckHeader defines if the gRPC server should bypass check header. + SkipCheckHeader bool `mapstructure:"skip-check-header" toml:"skip-check-header" comment:"SkipCheckHeader defines if the gRPC server should bypass check header."` } // CfgOption is a function that allows to overwrite the default server configuration. diff --git a/server/v2/testdata/app.toml b/server/v2/testdata/app.toml index be2f82566692..f91b717c328d 100644 --- a/server/v2/testdata/app.toml +++ b/server/v2/testdata/app.toml @@ -9,6 +9,8 @@ max-recv-msg-size = 10485760 # MaxSendMsgSize defines the max message size in bytes the server can send. # The default value is math.MaxInt32. max-send-msg-size = 2147483647 +# SkipCheckHeader defines if the gRPC server should bypass check header. +skip-check-header = false [mock-server-1] # Mock field diff --git a/tools/confix/data/v2-app.toml b/tools/confix/data/v2-app.toml index 7d136a84c2c6..c74264b00047 100644 --- a/tools/confix/data/v2-app.toml +++ b/tools/confix/data/v2-app.toml @@ -44,6 +44,8 @@ max-recv-msg-size = 10485760 # MaxSendMsgSize defines the max message size in bytes the server can send. # The default value is math.MaxInt32. max-send-msg-size = 2147483647 +# SkipCheckHeader defines if the gRPC server should bypass check header. +skip-check-header = false [grpc-gateway] # Enable defines if the gRPC-gateway should be enabled.