diff --git a/baseapp/grpcserver.go b/baseapp/grpcserver.go index d04f71d1abce..0b77d7c471e4 100644 --- a/baseapp/grpcserver.go +++ b/baseapp/grpcserver.go @@ -2,6 +2,7 @@ package baseapp import ( "context" + "fmt" "strconv" gogogrpc "github.com/cosmos/gogoproto/grpc" @@ -21,7 +22,7 @@ import ( func (app *BaseApp) GRPCQueryRouter() *GRPCQueryRouter { return app.grpcQueryRouter } // RegisterGRPCServer registers gRPC services directly with the gRPC server. -func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) { +func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server, logQueries 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) { @@ -65,6 +66,10 @@ func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) { app.logger.Error("failed to set gRPC header", "err", err) } + if logQueries { + app.logger.Info("gRPC query received of type: " + fmt.Sprintf("%#v", req)) + } + return handler(grpcCtx, req) } diff --git a/server/config/config.go b/server/config/config.go index 90dad0c943cb..cd9d814abe81 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -34,6 +34,10 @@ const ( // bytes the server can send. DefaultGRPCMaxSendMsgSize = math.MaxInt32 + // DefaultLogQueries defines the default value for the log_queries parameter. + // Should be set to false unless debugging. + DefaultLogQueries = false + // FileStreamer defines the store streaming type for file streaming. FileStreamer = "file" ) @@ -177,6 +181,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"` + + // LogQueries logs every gRPC query to the console as an info log. + LogQueries bool `mapstructure:"log-queries"` } // GRPCWebConfig defines configuration for the gRPC-web server. @@ -319,6 +326,7 @@ func DefaultConfig() *Config { Address: DefaultGRPCAddress, MaxRecvMsgSize: DefaultGRPCMaxRecvMsgSize, MaxSendMsgSize: DefaultGRPCMaxSendMsgSize, + LogQueries: DefaultLogQueries, }, Rosetta: RosettaConfig{ Enable: false, diff --git a/server/config/toml.go b/server/config/toml.go index 1ec7ce6a2e2d..5a560ccff51b 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -207,6 +207,11 @@ max-recv-msg-size = "{{ .GRPC.MaxRecvMsgSize }}" # The default value is math.MaxInt32. max-send-msg-size = "{{ .GRPC.MaxSendMsgSize }}" +# LogQueries if enabled will print an info log containing the query request +# that was submitted to this node on every submission. +# This is useful strictly for debugging purposes and should be disabled otherwise. +log-queries = "{{ .GRPC.LogQueries }}" + ############################################################################### ### gRPC Web Configuration ### ############################################################################### diff --git a/server/grpc/server.go b/server/grpc/server.go index 79a9be3dca24..b21d9afa629c 100644 --- a/server/grpc/server.go +++ b/server/grpc/server.go @@ -35,7 +35,7 @@ func StartGRPCServer(clientCtx client.Context, app types.Application, cfg config grpc.MaxRecvMsgSize(maxRecvMsgSize), ) - app.RegisterGRPCServer(grpcSrv) + app.RegisterGRPCServer(grpcSrv, cfg.LogQueries) // 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/types/app.go b/server/types/app.go index 727f767fc35e..eb8d4e78c83e 100644 --- a/server/types/app.go +++ b/server/types/app.go @@ -46,7 +46,7 @@ type ( // RegisterGRPCServer registers gRPC services directly with the gRPC // server. - RegisterGRPCServer(grpc.Server) + RegisterGRPCServer(grpc.Server, bool) // RegisterTxService registers the gRPC Query service for tx (such as tx // simulation, fetching txs by hash...).