From bd886bb4b03fdfc52bdc1fa2f98e960316604f89 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Fri, 3 May 2024 15:40:14 +0200 Subject: [PATCH] feat(baseapp): expose grpc query router via depinject. (#20264) --- CHANGELOG.md | 5 +++++ baseapp/baseapp.go | 6 ++---- baseapp/grpcserver.go | 3 --- baseapp/options.go | 10 ++++++++++ runtime/app.go | 1 + runtime/builder.go | 1 + runtime/module.go | 5 ++++- 7 files changed, 23 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 36e3f2f0b184..7e280ccadb73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,8 +38,13 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements + +* (runtime) [#20264](https://github.com/cosmos/cosmos-sdk/pull/20264) Expose grpc query router via depinject. + ### Bug Fixes +* (baseapp) [#20144](https://github.com/cosmos/cosmos-sdk/pull/20144) Remove txs from mempool when antehandler fails in recheck. * (baseapp) [#20107](https://github.com/cosmos/cosmos-sdk/pull/20107) Avoid header height overwrite block height. * (cli) [#20020](https://github.com/cosmos/cosmos-sdk/pull/20020) Make bootstrap-state command support both new and legacy genesis format. diff --git a/baseapp/baseapp.go b/baseapp/baseapp.go index ebd53b4e4463..9df56b692fb8 100644 --- a/baseapp/baseapp.go +++ b/baseapp/baseapp.go @@ -277,10 +277,8 @@ func (app *BaseApp) Trace() bool { // MsgServiceRouter returns the MsgServiceRouter of a BaseApp. func (app *BaseApp) MsgServiceRouter() *MsgServiceRouter { return app.msgServiceRouter } -// SetMsgServiceRouter sets the MsgServiceRouter of a BaseApp. -func (app *BaseApp) SetMsgServiceRouter(msgServiceRouter *MsgServiceRouter) { - app.msgServiceRouter = msgServiceRouter -} +// GRPCQueryRouter returns the GRPCQueryRouter of a BaseApp. +func (app *BaseApp) GRPCQueryRouter() *GRPCQueryRouter { return app.grpcQueryRouter } // MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp // multistore. diff --git a/baseapp/grpcserver.go b/baseapp/grpcserver.go index 20ea6ecac1de..1e8f3a91d748 100644 --- a/baseapp/grpcserver.go +++ b/baseapp/grpcserver.go @@ -19,9 +19,6 @@ import ( grpctypes "github.com/cosmos/cosmos-sdk/types/grpc" ) -// GRPCQueryRouter returns the GRPCQueryRouter of a BaseApp. -func (app *BaseApp) GRPCQueryRouter() *GRPCQueryRouter { return app.grpcQueryRouter } - // RegisterGRPCServer registers gRPC services directly with the gRPC server. func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) { // Define an interceptor for all gRPC queries: this interceptor will create diff --git a/baseapp/options.go b/baseapp/options.go index 08cbf77ee297..84ff5d456227 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -372,3 +372,13 @@ func (app *BaseApp) SetStreamingManager(manager storetypes.StreamingManager) { func (app *BaseApp) SetDisableBlockGasMeter(disableBlockGasMeter bool) { app.disableBlockGasMeter = disableBlockGasMeter } + +// SetMsgServiceRouter sets the MsgServiceRouter of a BaseApp. +func (app *BaseApp) SetMsgServiceRouter(msgServiceRouter *MsgServiceRouter) { + app.msgServiceRouter = msgServiceRouter +} + +// SetGRPCQueryRouter sets the GRPCQueryRouter of the BaseApp. +func (app *BaseApp) SetGRPCQueryRouter(grpcQueryRouter *GRPCQueryRouter) { + app.grpcQueryRouter = grpcQueryRouter +} diff --git a/runtime/app.go b/runtime/app.go index 734a13006eb1..55b44aaa0d34 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -50,6 +50,7 @@ type App struct { basicManager module.BasicManager baseAppOptions []BaseAppOption msgServiceRouter *baseapp.MsgServiceRouter + grpcQueryRouter *baseapp.GRPCQueryRouter appConfig *appv1alpha1.Config logger log.Logger // initChainer is the init chainer function defined by the app config. diff --git a/runtime/builder.go b/runtime/builder.go index 72bf965f7082..bf645ae7a5d1 100644 --- a/runtime/builder.go +++ b/runtime/builder.go @@ -31,6 +31,7 @@ func (a *AppBuilder) Build(db dbm.DB, traceStore io.Writer, baseAppOptions ...fu bApp := baseapp.NewBaseApp(a.app.config.AppName, a.app.logger, db, nil, baseAppOptions...) bApp.SetMsgServiceRouter(a.app.msgServiceRouter) + bApp.SetGRPCQueryRouter(a.app.grpcQueryRouter) bApp.SetCommitMultiStoreTracer(traceStore) bApp.SetVersion(version.Version) bApp.SetInterfaceRegistry(a.app.interfaceRegistry) diff --git a/runtime/module.go b/runtime/module.go index cdc6a1a3a33f..9ab1bbf40816 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -86,6 +86,7 @@ func ProvideApp(interfaceRegistry codectypes.InterfaceRegistry) ( *codec.LegacyAmino, *AppBuilder, *baseapp.MsgServiceRouter, + *baseapp.GRPCQueryRouter, appmodule.AppModule, protodesc.Resolver, protoregistry.MessageTypeResolver, @@ -108,6 +109,7 @@ func ProvideApp(interfaceRegistry codectypes.InterfaceRegistry) ( cdc := codec.NewProtoCodec(interfaceRegistry) msgServiceRouter := baseapp.NewMsgServiceRouter() + grpcQueryRouter := baseapp.NewGRPCQueryRouter() app := &App{ storeKeys: nil, interfaceRegistry: interfaceRegistry, @@ -115,10 +117,11 @@ func ProvideApp(interfaceRegistry codectypes.InterfaceRegistry) ( amino: amino, basicManager: module.BasicManager{}, msgServiceRouter: msgServiceRouter, + grpcQueryRouter: grpcQueryRouter, } appBuilder := &AppBuilder{app} - return cdc, amino, appBuilder, msgServiceRouter, appModule{app}, protoFiles, protoTypes, nil + return cdc, amino, appBuilder, msgServiceRouter, grpcQueryRouter, appModule{app}, protoFiles, protoTypes, nil } type AppInputs struct {