Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: integrate autocli and reflection services with simapp legacy #13746

Merged
merged 6 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions runtime/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (b BaseAppOption) IsManyPerContainerType() {}
func init() {
appmodule.Register(&runtimev1alpha1.Module{},
appmodule.Provide(
ProvideCodecs,
Provide,
ProvideKVStoreKey,
ProvideTransientStoreKey,
ProvideMemoryStoreKey,
Expand All @@ -38,7 +38,7 @@ func init() {
)
}

func ProvideCodecs(moduleBasics map[string]AppModuleBasicWrapper) (
func Provide(moduleBasics map[string]AppModuleBasicWrapper) (
codectypes.InterfaceRegistry,
codec.Codec,
*codec.LegacyAmino,
Expand Down Expand Up @@ -75,18 +75,17 @@ func ProvideCodecs(moduleBasics map[string]AppModuleBasicWrapper) (
return interfaceRegistry, cdc, amino, app, cdc, msgServiceRouter
}

type appInputs struct {
type AppInputs struct {
depinject.In

AppConfig *appv1alpha1.Config
Config *runtimev1alpha1.Module
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
Expand All @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions runtime/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not related to this line specifically, but why didn't we make runtime a go.mod?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't yet because all modules depend on runtime and runtime depends on baseapp and types.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the downvote @julienrbrt ?

Copy link
Member

@julienrbrt julienrbrt Nov 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the split for tools, or things that needs to iterate faster than the SDK.
If we extract runtime, this means different modules could have different version of runtime.
This adds a variable of what a module must be compatible to. It makes for sense if you have modules compatible with SDK versions only and not additionally runtime. These (runtime + sdk types) seems so tight to each another anyway that I, personally, don't understand the added value.
Unless I am missing something.

moduleOptions := map[string]*autocliv1.ModuleOptions{}
for modName, mod := range appModules {
if autoCliMod, ok := mod.(interface {
Expand Down
11 changes: 11 additions & 0 deletions simapp/app_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -430,6 +433,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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

love it thank you!!


reflectionSvc, err := runtimeservices.NewReflectionService()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's maybe add a quick note in upgrading.md for v0.47

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @ilgooz for visibility on this feature

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{})

Expand Down