From 74e9d542d254a2005f211ed1923dd36b0f582ab8 Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Tue, 8 Nov 2022 07:32:49 -0500 Subject: [PATCH] feat!: integrate autocli and reflection services with simapp legacy (#13746) * feat!: integrate autocli and reflection services with simapp legacy * rename alias * update UPGRADING.md Co-authored-by: Julien Robert --- UPGRADING.md | 10 ++++++++++ runtime/app.go | 3 --- runtime/module.go | 10 ++++------ runtime/services.go | 4 ++-- runtime/{internal => }/services/app.go | 0 runtime/{internal => }/services/autocli.go | 5 +++-- runtime/{internal => }/services/reflection.go | 0 simapp/app_legacy.go | 11 +++++++++++ 8 files changed, 30 insertions(+), 13 deletions(-) rename runtime/{internal => }/services/app.go (100%) rename runtime/{internal => }/services/autocli.go (86%) rename runtime/{internal => }/services/reflection.go (100%) diff --git a/UPGRADING.md b/UPGRADING.md index b7ece57a3..2af2239be 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -29,6 +29,16 @@ The `simapp` package **should not be imported in your own app**. Instead, you sh SimApp's `app.go` is now using [App Wiring](https://docs.cosmos.network/main/building-apps/app-go), the dependency injection framework of the Cosmos SDK. This means that modules are injected directly into SimApp thanks to a [configuration file](https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_config.go). The old behavior is preserved and can still be used, without the dependency injection framework, as shows [`app_legacy.go`](https://github.com/cosmos/cosmos-sdk/blob/main/simapp/app_legacy.go). +If you are using a legacy `app.go` without dependency injection, add the following lines to your `app.go` in order to provide newer gRPC services: +```go +autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules)) + +reflectionSvc, err := runtimeservices.NewReflectionService() +if err != nil { + panic(err) +} +reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc) +``` #### Constructor diff --git a/runtime/app.go b/runtime/app.go index 4cfa6d527..26b4fa555 100644 --- a/runtime/app.go +++ b/runtime/app.go @@ -8,8 +8,6 @@ import ( "golang.org/x/exp/slices" runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1" - "cosmossdk.io/core/appmodule" - appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1" "github.com/cosmos/cosmos-sdk/baseapp" @@ -50,7 +48,6 @@ type App struct { baseAppOptions []BaseAppOption msgServiceRouter *baseapp.MsgServiceRouter appConfig *appv1alpha1.Config - appModules map[string]appmodule.AppModule } // RegisterModules registers the provided modules with the module manager and diff --git a/runtime/module.go b/runtime/module.go index 0f858b0bb..cff6092a8 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -28,7 +28,7 @@ func (b BaseAppOption) IsManyPerContainerType() {} func init() { appmodule.Register(&runtimev1alpha1.Module{}, appmodule.Provide( - ProvideCodecs, + Provide, ProvideKVStoreKey, ProvideTransientStoreKey, ProvideMemoryStoreKey, @@ -38,7 +38,7 @@ func init() { ) } -func ProvideCodecs(moduleBasics map[string]AppModuleBasicWrapper) ( +func Provide(moduleBasics map[string]AppModuleBasicWrapper) ( codectypes.InterfaceRegistry, codec.Codec, *codec.LegacyAmino, @@ -75,7 +75,7 @@ func ProvideCodecs(moduleBasics map[string]AppModuleBasicWrapper) ( return interfaceRegistry, cdc, amino, app, cdc, msgServiceRouter } -type appInputs struct { +type AppInputs struct { depinject.In AppConfig *appv1alpha1.Config @@ -83,10 +83,9 @@ type appInputs struct { AppBuilder *AppBuilder Modules map[string]AppModuleWrapper BaseAppOptions []BaseAppOption - AppModules map[string]appmodule.AppModule } -func SetupAppBuilder(inputs appInputs) { +func SetupAppBuilder(inputs AppInputs) { mm := &module.Manager{Modules: map[string]module.AppModule{}} for name, wrapper := range inputs.Modules { mm.Modules[name] = wrapper.AppModule @@ -96,7 +95,6 @@ func SetupAppBuilder(inputs appInputs) { app.config = inputs.Config app.ModuleManager = mm app.appConfig = inputs.AppConfig - app.appModules = inputs.AppModules } func registerStoreKey(wrapper *AppBuilder, key storetypes.StoreKey) { diff --git a/runtime/services.go b/runtime/services.go index 491b29263..bece4a4ab 100644 --- a/runtime/services.go +++ b/runtime/services.go @@ -5,12 +5,12 @@ import ( autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" - "github.com/cosmos/cosmos-sdk/runtime/internal/services" + "github.com/cosmos/cosmos-sdk/runtime/services" ) func (a *App) registerRuntimeServices() error { appv1alpha1.RegisterQueryServer(a.GRPCQueryRouter(), services.NewAppQueryService(a.appConfig)) - autocliv1.RegisterQueryServer(a.GRPCQueryRouter(), services.NewAutoCLIQueryService(a.appModules)) + autocliv1.RegisterQueryServer(a.GRPCQueryRouter(), services.NewAutoCLIQueryService(a.ModuleManager.Modules)) reflectionSvc, err := services.NewReflectionService() if err != nil { diff --git a/runtime/internal/services/app.go b/runtime/services/app.go similarity index 100% rename from runtime/internal/services/app.go rename to runtime/services/app.go diff --git a/runtime/internal/services/autocli.go b/runtime/services/autocli.go similarity index 86% rename from runtime/internal/services/autocli.go rename to runtime/services/autocli.go index 65b2ee550..5f684e550 100644 --- a/runtime/internal/services/autocli.go +++ b/runtime/services/autocli.go @@ -4,7 +4,8 @@ import ( "context" autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" - "cosmossdk.io/core/appmodule" + + "github.com/cosmos/cosmos-sdk/types/module" ) // AutoCLIQueryService implements the cosmos.autocli.v1.Query service. @@ -14,7 +15,7 @@ type AutoCLIQueryService struct { moduleOptions map[string]*autocliv1.ModuleOptions } -func NewAutoCLIQueryService(appModules map[string]appmodule.AppModule) *AutoCLIQueryService { +func NewAutoCLIQueryService(appModules map[string]module.AppModule) *AutoCLIQueryService { moduleOptions := map[string]*autocliv1.ModuleOptions{} for modName, mod := range appModules { if autoCliMod, ok := mod.(interface { diff --git a/runtime/internal/services/reflection.go b/runtime/services/reflection.go similarity index 100% rename from runtime/internal/services/reflection.go rename to runtime/services/reflection.go diff --git a/simapp/app_legacy.go b/simapp/app_legacy.go index 4b57f79a1..5cdc60d8f 100644 --- a/simapp/app_legacy.go +++ b/simapp/app_legacy.go @@ -9,6 +9,8 @@ import ( "os" "path/filepath" + autocliv1 "cosmossdk.io/api/cosmos/autocli/v1" + reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1" "github.com/spf13/cast" abci "github.com/tendermint/tendermint/abci/types" "github.com/tendermint/tendermint/libs/log" @@ -23,6 +25,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/runtime" + runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services" "github.com/cosmos/cosmos-sdk/server" "github.com/cosmos/cosmos-sdk/server/api" "github.com/cosmos/cosmos-sdk/server/config" @@ -435,6 +438,14 @@ func NewSimApp( app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter()) app.ModuleManager.RegisterServices(app.configurator) + autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.ModuleManager.Modules)) + + reflectionSvc, err := runtimeservices.NewReflectionService() + if err != nil { + panic(err) + } + reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc) + // add test gRPC service for testing gRPC queries in isolation testdata_pulsar.RegisterQueryServer(app.GRPCQueryRouter(), testdata_pulsar.QueryImpl{})