refactor(core,stf): complete gas service + simplify deps (#21166)

This commit is contained in:
Julien Robert
2024-08-08 07:30:09 +00:00
committed by GitHub
parent 7dacef600f
commit 7040177316
42 changed files with 98 additions and 131 deletions
+8 -2
View File
@@ -425,7 +425,7 @@ func (m *MM[T]) RunMigrations(ctx context.Context, fromVM appmodulev2.VersionMap
func (m *MM[T]) RegisterServices(app *App[T]) error {
for _, module := range m.modules {
// register msg + query
if services, ok := module.(appmodule.HasServices); ok {
if services, ok := module.(hasServicesV1); ok {
if err := registerServices(services, app, protoregistry.GlobalFiles); err != nil {
return err
}
@@ -554,7 +554,7 @@ func (m *MM[T]) assertNoForgottenModules(
return nil
}
func registerServices[T transaction.Tx](s appmodule.HasServices, app *App[T], registry *protoregistry.Files) error {
func registerServices[T transaction.Tx](s hasServicesV1, app *App[T], registry *protoregistry.Files) error {
c := &configurator{
grpcQueryDecoders: map[string]func() gogoproto.Message{},
stfQueryRouter: app.queryRouterBuilder,
@@ -710,3 +710,9 @@ func defaultMigrationsOrder(modules []string) []string {
}
return out
}
// hasServicesV1 is the interface for registering service in baseapp Cosmos SDK.
// This API is part of core/appmodule but commented out for dependencies.
type hasServicesV1 interface {
RegisterServices(grpc.ServiceRegistrar) error
}
+7 -3
View File
@@ -16,7 +16,6 @@ import (
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/core/app"
"cosmossdk.io/core/appmodule"
appmodulev2 "cosmossdk.io/core/appmodule/v2"
"cosmossdk.io/core/comet"
"cosmossdk.io/core/genesis"
@@ -33,7 +32,7 @@ import (
var (
_ appmodulev2.AppModule = appModule[transaction.Tx]{}
_ appmodule.HasServices = appModule[transaction.Tx]{}
_ hasServicesV1 = appModule[transaction.Tx]{}
)
type appModule[T transaction.Tx] struct {
@@ -176,7 +175,12 @@ func ProvideModuleManager[T transaction.Tx](
}
// ProvideEnvironment provides the environment for keeper modules, while maintaining backward compatibility and provide services directly as well.
func ProvideEnvironment[T transaction.Tx](logger log.Logger, config *runtimev2.Module, key depinject.ModuleKey, appBuilder *AppBuilder[T]) (
func ProvideEnvironment[T transaction.Tx](
logger log.Logger,
config *runtimev2.Module,
key depinject.ModuleKey,
appBuilder *AppBuilder[T],
) (
appmodulev2.Environment,
store.KVStoreService,
store.MemoryStoreService,
+4 -1
View File
@@ -51,7 +51,10 @@ func ExtractAutoCLIOptions(appModules map[string]appmodule.AppModule) (map[strin
// try to auto-discover options based on the last msg and query
// services registered for the module
if mod, ok := mod.(appmodule.HasServices); ok {
// this supports the legacy core/appmodule v1 service registration
if mod, ok := mod.(interface {
RegisterServices(grpc.ServiceRegistrar) error
}); ok {
err := mod.RegisterServices(autoCliRegistrar)
if err != nil {
return nil, err