From f02a1246678f2f0391574ea32a45b800ca7b45ef Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Thu, 16 May 2024 10:04:40 +0200 Subject: [PATCH] refactor(runtime,core): split router service (#20401) --- UPGRADING.md | 2 +- core/appmodule/v2/environment.go | 3 +- core/router/service.go | 10 +--- runtime/environment.go | 13 +++-- runtime/module.go | 3 +- runtime/router.go | 51 ++++++----------- runtime/router_test.go | 19 ++++--- runtime/v2/module.go | 3 +- server/v2/stf/core_router_service.go | 57 +++++++------------ simapp/ante.go | 4 -- simapp/app.go | 17 +++--- .../auth/keeper/msg_server_test.go | 2 +- .../distribution/keeper/msg_server_test.go | 2 +- .../evidence/keeper/infraction_test.go | 4 +- tests/integration/gov/keeper/keeper_test.go | 2 +- .../slashing/keeper/keeper_test.go | 8 +-- .../integration/staking/keeper/common_test.go | 4 +- testutil/integration/router.go | 2 +- x/accounts/keeper.go | 6 +- x/accounts/utils_test.go | 5 +- x/auth/ante/setup.go | 2 +- x/auth/ante/testutil_test.go | 2 +- x/authz/keeper/genesis_test.go | 2 +- x/authz/keeper/keeper.go | 2 +- x/authz/keeper/keeper_test.go | 2 +- x/authz/keeper/msg_server.go | 2 +- x/authz/module/abci_test.go | 2 +- x/evidence/keeper/infraction.go | 2 +- x/gov/keeper/abci.go | 4 +- x/gov/keeper/abci_internal_test.go | 10 ++-- x/gov/keeper/common_test.go | 4 +- x/gov/keeper/msg_server.go | 4 +- x/gov/keeper/proposal.go | 2 +- x/group/keeper/genesis_test.go | 2 +- x/group/keeper/grpc_query_test.go | 2 +- x/group/keeper/keeper_test.go | 2 +- x/group/keeper/proposal_executor.go | 2 +- x/staking/keeper/keeper_test.go | 2 +- x/staking/keeper/msg_server.go | 2 +- x/upgrade/keeper/abci.go | 2 +- x/upgrade/keeper/abci_test.go | 2 +- 41 files changed, 117 insertions(+), 156 deletions(-) diff --git a/UPGRADING.md b/UPGRADING.md index 3ae40ff633..6c079ac1ce 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -176,7 +176,7 @@ If your module requires a message server or query server, it should be passed in ```diff -govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewKVStoreService(keys[govtypes.StoreKey]), app.AuthKeeper, app.BankKeeper,app.StakingKeeper, app.PoolKeeper, app.MsgServiceRouter(), govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String()) -+govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[govtypes.StoreKey]), logger.With(log.ModuleKey, "x/circuit"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String()) ++govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[govtypes.StoreKey]), logger.With(log.ModuleKey, "x/circuit"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String()) ``` The signature of the extension interface `HasRegisterInterfaces` has been changed to accept a `cosmossdk.io/core/registry.InterfaceRegistrar` instead of a `codec.InterfaceRegistry`. `HasRegisterInterfaces` is now a part of `cosmossdk.io/core/appmodule`. Modules should update their `HasRegisterInterfaces` implementation to accept a `cosmossdk.io/core/registry.InterfaceRegistrar` interface. diff --git a/core/appmodule/v2/environment.go b/core/appmodule/v2/environment.go index e3592eb210..e8af3b3bae 100644 --- a/core/appmodule/v2/environment.go +++ b/core/appmodule/v2/environment.go @@ -19,7 +19,8 @@ type Environment struct { EventService event.Service GasService gas.Service HeaderService header.Service - RouterService router.Service + QueryRouterService router.Service + MsgRouterService router.Service TransactionService transaction.Service KVStoreService store.KVStoreService diff --git a/core/router/service.go b/core/router/service.go index d4f13d21b2..caf5891e53 100644 --- a/core/router/service.go +++ b/core/router/service.go @@ -6,15 +6,9 @@ import ( "google.golang.org/protobuf/runtime/protoiface" ) -// Service embeds a QueryRouterService and MessageRouterService. -// Each router allows to invoke messages and queries via the corresponding router. +// Service is the interface that wraps the basic methods for a router. +// A router can be a query router or a message router. type Service interface { - QueryRouterService() Router - MessageRouterService() Router -} - -// Router is the interface that wraps the basic methods for a router. -type Router interface { // CanInvoke returns an error if the given request cannot be invoked. CanInvoke(ctx context.Context, typeURL string) error // InvokeTyped execute a message or query. It should be used when the called knows the type of the response. diff --git a/runtime/environment.go b/runtime/environment.go index b8814df0b7..27607b4967 100644 --- a/runtime/environment.go +++ b/runtime/environment.go @@ -35,12 +35,15 @@ func NewEnvironment( type EnvOption func(*appmodule.Environment) -func EnvWithRouterService( - queryServiceRouter *baseapp.GRPCQueryRouter, - msgServiceRouter *baseapp.MsgServiceRouter, -) EnvOption { +func EnvWithMsgRouterService(msgServiceRouter *baseapp.MsgServiceRouter) EnvOption { return func(env *appmodule.Environment) { - env.RouterService = NewRouterService(env.KVStoreService, queryServiceRouter, msgServiceRouter) + env.MsgRouterService = NewMsgRouterService(msgServiceRouter) + } +} + +func EnvWithQueryRouterService(queryServiceRouter *baseapp.GRPCQueryRouter) EnvOption { + return func(env *appmodule.Environment) { + env.QueryRouterService = NewQueryRouterService(queryServiceRouter) } } diff --git a/runtime/module.go b/runtime/module.go index 9e82cf6c30..0c0baa1a8e 100644 --- a/runtime/module.go +++ b/runtime/module.go @@ -247,7 +247,8 @@ func ProvideEnvironment( return kvService, memStoreService, NewEnvironment( kvService, logger.With(log.ModuleKey, fmt.Sprintf("x/%s", key.Name())), - EnvWithRouterService(queryServiceRouter, msgServiceRouter), + EnvWithMsgRouterService(msgServiceRouter), + EnvWithQueryRouterService(queryServiceRouter), EnvWithMemStoreService(memStoreService), ) } diff --git a/runtime/router.go b/runtime/router.go index 5e2a8a8e9b..d99c71252b 100644 --- a/runtime/router.go +++ b/runtime/router.go @@ -11,47 +11,22 @@ import ( "google.golang.org/protobuf/runtime/protoiface" "cosmossdk.io/core/router" - "cosmossdk.io/core/store" "github.com/cosmos/cosmos-sdk/baseapp" ) -// NewRouterService creates a router.Service which allows to invoke messages and queries using the msg router. -func NewRouterService(storeService store.KVStoreService, queryRouter *baseapp.GRPCQueryRouter, msgRouter baseapp.MessageRouter) router.Service { - return &routerService{ - queryRouterService: &queryRouterService{ - storeService: storeService, // TODO: this will be used later on as authenticating modules before routing - router: queryRouter, - }, - msgRouterService: &msgRouterService{ - storeService: storeService, // TODO: this will be used later on as authenticating modules before routing - router: msgRouter, - }, +// NewMsgRouterService implements router.Service. +func NewMsgRouterService(msgRouter baseapp.MessageRouter) router.Service { + return &msgRouterService{ + router: msgRouter, } } -var _ router.Service = (*routerService)(nil) - -type routerService struct { - queryRouterService router.Router - msgRouterService router.Router -} - -// MessageRouterService implements router.Service. -func (r *routerService) MessageRouterService() router.Router { - return r.msgRouterService -} - -// QueryRouterService implements router.Service. -func (r *routerService) QueryRouterService() router.Router { - return r.queryRouterService -} - -var _ router.Router = (*msgRouterService)(nil) +var _ router.Service = (*msgRouterService)(nil) type msgRouterService struct { - storeService store.KVStoreService - router baseapp.MessageRouter + // TODO: eventually authenticate modules to use the message router + router baseapp.MessageRouter } // CanInvoke returns an error if the given message cannot be invoked. @@ -104,11 +79,17 @@ func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.Mes return msgResp, m.InvokeTyped(ctx, msg, msgResp) } -var _ router.Router = (*queryRouterService)(nil) +// NewQueryRouterService implements router.Service. +func NewQueryRouterService(queryRouter *baseapp.GRPCQueryRouter) router.Service { + return &queryRouterService{ + router: queryRouter, + } +} + +var _ router.Service = (*queryRouterService)(nil) type queryRouterService struct { - storeService store.KVStoreService - router *baseapp.GRPCQueryRouter + router *baseapp.GRPCQueryRouter } // CanInvoke returns an error if the given request cannot be invoked. diff --git a/runtime/router_test.go b/runtime/router_test.go index 56783bfe23..54b123fd04 100644 --- a/runtime/router_test.go +++ b/runtime/router_test.go @@ -31,18 +31,19 @@ func TestRouterService(t *testing.T) { countertypes.RegisterMsgServer(msgRouter, counterKeeper) countertypes.RegisterQueryServer(queryRouter, counterKeeper) - routerService := runtime.NewRouterService(storeService, queryRouter, msgRouter) + messageRouterService := runtime.NewMsgRouterService(msgRouter) + queryRouterService := runtime.NewQueryRouterService(queryRouter) testCtx := testutil.DefaultContextWithDB(t, key, storetypes.NewTransientStoreKey("transient_test")) // Messages t.Run("invalid msg", func(t *testing.T) { - _, err := routerService.MessageRouterService().InvokeUntyped(testCtx.Ctx, &bankv1beta1.MsgSend{}) + _, err := messageRouterService.InvokeUntyped(testCtx.Ctx, &bankv1beta1.MsgSend{}) require.ErrorContains(t, err, "could not find response type for message cosmos.bank.v1beta1.MsgSend") }) t.Run("invoke untyped: valid msg (proto v1)", func(t *testing.T) { - resp, err := routerService.MessageRouterService().InvokeUntyped(testCtx.Ctx, &countertypes.MsgIncreaseCounter{ + resp, err := messageRouterService.InvokeUntyped(testCtx.Ctx, &countertypes.MsgIncreaseCounter{ Signer: "cosmos1", Count: 42, }) @@ -52,7 +53,7 @@ func TestRouterService(t *testing.T) { t.Run("invoke typed: valid msg (proto v1)", func(t *testing.T) { resp := &countertypes.MsgIncreaseCountResponse{} - err := routerService.MessageRouterService().InvokeTyped(testCtx.Ctx, &countertypes.MsgIncreaseCounter{ + err := messageRouterService.InvokeTyped(testCtx.Ctx, &countertypes.MsgIncreaseCounter{ Signer: "cosmos1", Count: 42, }, resp) @@ -62,7 +63,7 @@ func TestRouterService(t *testing.T) { t.Run("invoke typed: valid msg (proto v2)", func(t *testing.T) { resp := &counterv1.MsgIncreaseCountResponse{} - err := routerService.MessageRouterService().InvokeTyped(testCtx.Ctx, &counterv1.MsgIncreaseCounter{ + err := messageRouterService.InvokeTyped(testCtx.Ctx, &counterv1.MsgIncreaseCounter{ Signer: "cosmos1", Count: 42, }, resp) @@ -73,7 +74,7 @@ func TestRouterService(t *testing.T) { // Queries t.Run("invalid query", func(t *testing.T) { - err := routerService.QueryRouterService().InvokeTyped(testCtx.Ctx, &bankv1beta1.QueryBalanceRequest{}, &bankv1beta1.QueryBalanceResponse{}) + err := queryRouterService.InvokeTyped(testCtx.Ctx, &bankv1beta1.QueryBalanceRequest{}, &bankv1beta1.QueryBalanceResponse{}) require.ErrorContains(t, err, "unknown request: cosmos.bank.v1beta1.QueryBalanceRequest") }) @@ -81,7 +82,7 @@ func TestRouterService(t *testing.T) { _ = counterKeeper.CountStore.Set(testCtx.Ctx, 42) resp := &countertypes.QueryGetCountResponse{} - err := routerService.QueryRouterService().InvokeTyped(testCtx.Ctx, &countertypes.QueryGetCountRequest{}, resp) + err := queryRouterService.InvokeTyped(testCtx.Ctx, &countertypes.QueryGetCountRequest{}, resp) require.NoError(t, err) require.NotNil(t, resp) require.Equal(t, int64(42), resp.TotalCount) @@ -91,7 +92,7 @@ func TestRouterService(t *testing.T) { _ = counterKeeper.CountStore.Set(testCtx.Ctx, 42) resp := &counterv1.QueryGetCountResponse{} - err := routerService.QueryRouterService().InvokeTyped(testCtx.Ctx, &counterv1.QueryGetCountRequest{}, resp) + err := queryRouterService.InvokeTyped(testCtx.Ctx, &counterv1.QueryGetCountRequest{}, resp) require.NoError(t, err) require.NotNil(t, resp) require.Equal(t, int64(42), resp.TotalCount) @@ -100,7 +101,7 @@ func TestRouterService(t *testing.T) { t.Run("invoke untyped: valid query (proto v1)", func(t *testing.T) { _ = counterKeeper.CountStore.Set(testCtx.Ctx, 42) - resp, err := routerService.QueryRouterService().InvokeUntyped(testCtx.Ctx, &countertypes.QueryGetCountRequest{}) + resp, err := queryRouterService.InvokeUntyped(testCtx.Ctx, &countertypes.QueryGetCountRequest{}) require.NoError(t, err) require.NotNil(t, resp) respVal, ok := resp.(*countertypes.QueryGetCountResponse) diff --git a/runtime/v2/module.go b/runtime/v2/module.go index c18dc42cab..6ae880662b 100644 --- a/runtime/v2/module.go +++ b/runtime/v2/module.go @@ -248,7 +248,8 @@ func ProvideEnvironment(logger log.Logger, config *runtimev2.Module, key depinje EventService: stf.NewEventService(), GasService: stf.NewGasMeterService(), HeaderService: stf.HeaderService{}, - RouterService: stf.NewRouterService(appBuilder.app.queryRouterBuilder, appBuilder.app.msgRouterBuilder), + QueryRouterService: stf.NewQueryRouterService(appBuilder.app.queryRouterBuilder), + MsgRouterService: stf.NewMsgRouterService(appBuilder.app.msgRouterBuilder), TransactionService: services.NewContextAwareTransactionService(), KVStoreService: kvService, MemStoreService: memService, diff --git a/server/v2/stf/core_router_service.go b/server/v2/stf/core_router_service.go index 0408f7dfa4..f64e90cc28 100644 --- a/server/v2/stf/core_router_service.go +++ b/server/v2/stf/core_router_service.go @@ -12,48 +12,20 @@ import ( "cosmossdk.io/core/router" ) -// NewRouterService creates a router.Service which allows to invoke messages and queries using the msg router. -func NewRouterService(queryRouterBuilder, msgRouterBuilder *MsgRouterBuilder) router.Service { - queryRouter, err := queryRouterBuilder.Build() - if err != nil { - panic("cannot create queryRouter") - } - +// NewMsgRouterService implements router.Service. +func NewMsgRouterService(msgRouterBuilder *MsgRouterBuilder) router.Service { msgRouter, err := msgRouterBuilder.Build() if err != nil { - panic("cannot create msgRouter") + panic(fmt.Errorf("cannot create msgRouter: %w", err)) } - return &routerService{ - queryRouterService: &queryRouterService{ - builder: queryRouterBuilder, - handler: queryRouter, - }, - msgRouterService: &msgRouterService{ - builder: msgRouterBuilder, - handler: msgRouter, - }, + return &msgRouterService{ + builder: msgRouterBuilder, + handler: msgRouter, } } -var _ router.Service = (*routerService)(nil) - -type routerService struct { - queryRouterService router.Router - msgRouterService router.Router -} - -// MessageRouterService implements router.Service. -func (r *routerService) MessageRouterService() router.Router { - return r.msgRouterService -} - -// QueryRouterService implements router.Service. -func (r *routerService) QueryRouterService() router.Router { - return r.queryRouterService -} - -var _ router.Router = (*msgRouterService)(nil) +var _ router.Service = (*msgRouterService)(nil) type msgRouterService struct { builder *MsgRouterBuilder @@ -87,7 +59,20 @@ func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.Mes return m.handler(ctx, msg) } -var _ router.Router = (*queryRouterService)(nil) +// NewQueryRouterService implements router.Service. +func NewQueryRouterService(queryRouterBuilder *MsgRouterBuilder) router.Service { + queryRouter, err := queryRouterBuilder.Build() + if err != nil { + panic(fmt.Errorf("cannot create queryRouter: %w", err)) + } + + return &queryRouterService{ + builder: queryRouterBuilder, + handler: queryRouter, + } +} + +var _ router.Service = (*queryRouterService)(nil) type queryRouterService struct { builder *MsgRouterBuilder diff --git a/simapp/ante.go b/simapp/ante.go index 359494d91f..7fa4cac702 100644 --- a/simapp/ante.go +++ b/simapp/ante.go @@ -33,10 +33,6 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { return nil, errors.New("sign mode handler is required for ante builder") } - if options.Environment.RouterService == nil { - return nil, errors.New("router service is required for ante builder") - } - anteDecorators := []sdk.AnteDecorator{ ante.NewSetUpContextDecorator(options.Environment), // outermost AnteDecorator. SetUpContext must be called first circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper), diff --git a/simapp/app.go b/simapp/app.go index e1c2254b15..13dea74795 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -290,7 +290,7 @@ func NewSimApp( // add keepers accountsKeeper, err := accounts.NewKeeper( appCodec, - runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), logger.With(log.ModuleKey, "x/accounts"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), + runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), logger.With(log.ModuleKey, "x/accounts"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), signingCtx.AddressCodec(), appCodec.InterfaceRegistry(), // TESTING: do not add @@ -343,7 +343,8 @@ func NewSimApp( runtime.NewEnvironment( runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), logger.With(log.ModuleKey, "x/staking"), - runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), + runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), + runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), app.AuthKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), @@ -373,7 +374,7 @@ func NewSimApp( app.CircuitKeeper = circuitkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[circuittypes.StoreKey]), logger.With(log.ModuleKey, "x/circuit")), appCodec, authtypes.NewModuleAddress(govtypes.ModuleName).String(), app.AuthKeeper.AddressCodec()) app.BaseApp.SetCircuitBreaker(&app.CircuitKeeper) - app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), logger.With(log.ModuleKey, "x/authz"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), appCodec, app.AuthKeeper) + app.AuthzKeeper = authzkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[authzkeeper.StoreKey]), logger.With(log.ModuleKey, "x/authz"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), appCodec, app.AuthKeeper) groupConfig := group.DefaultConfig() /* @@ -383,7 +384,7 @@ func NewSimApp( config.MaxProposalTitleLen = 255 // example max title length in characters config.MaxProposalSummaryLen = 10200 // example max summary length in characters */ - app.GroupKeeper = groupkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[group.StoreKey]), logger.With(log.ModuleKey, "x/group"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), appCodec, app.AuthKeeper, groupConfig) + app.GroupKeeper = groupkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[group.StoreKey]), logger.With(log.ModuleKey, "x/group"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), appCodec, app.AuthKeeper, groupConfig) // get skipUpgradeHeights from the app options skipUpgradeHeights := map[int64]bool{} @@ -392,7 +393,7 @@ func NewSimApp( } homePath := cast.ToString(appOpts.Get(flags.FlagHome)) // set the governance module account as the authority for conducting upgrades - app.UpgradeKeeper = upgradekeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), logger.With(log.ModuleKey, "x/upgrade"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), skipUpgradeHeights, appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.UpgradeKeeper = upgradekeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[upgradetypes.StoreKey]), logger.With(log.ModuleKey, "x/upgrade"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), skipUpgradeHeights, appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(govtypes.ModuleName).String()) // Register the proposal types // Deprecated: Avoid adding new handlers, instead use the new proposal flow @@ -404,7 +405,7 @@ func NewSimApp( Example of setting gov params: govConfig.MaxMetadataLen = 10000 */ - govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[govtypes.StoreKey]), logger.With(log.ModuleKey, "x/gov"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + govKeeper := govkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[govtypes.StoreKey]), logger.With(log.ModuleKey, "x/gov"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String()) // Set legacy router for backwards compatibility with gov v1beta1 govKeeper.SetLegacyRouter(govRouter) @@ -419,7 +420,7 @@ func NewSimApp( // create evidence keeper with router evidenceKeeper := evidencekeeper.NewKeeper( - appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), logger.With(log.ModuleKey, "x/evidence"), runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), app.StakingKeeper, app.SlashingKeeper, app.AuthKeeper.AddressCodec(), + appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), logger.With(log.ModuleKey, "x/evidence"), runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), app.StakingKeeper, app.SlashingKeeper, app.AuthKeeper.AddressCodec(), ) // If evidence needs to be handled for the app, set routes in router here and seal app.EvidenceKeeper = *evidenceKeeper @@ -610,7 +611,7 @@ func (app *SimApp) setAnteHandler(txConfig client.TxConfig) { anteHandler, err := NewAnteHandler( HandlerOptions{ ante.HandlerOptions{ - Environment: runtime.NewEnvironment(nil, app.logger, runtime.EnvWithRouterService(app.GRPCQueryRouter(), app.MsgServiceRouter())), // nil is set as the kvstoreservice to avoid module access + Environment: runtime.NewEnvironment(nil, app.logger, runtime.EnvWithMsgRouterService(app.MsgServiceRouter()), runtime.EnvWithQueryRouterService(app.GRPCQueryRouter())), // nil is set as the kvstoreservice to avoid module access AccountAbstractionKeeper: app.AccountsKeeper, AccountKeeper: app.AuthKeeper, BankKeeper: app.BankKeeper, diff --git a/tests/integration/auth/keeper/msg_server_test.go b/tests/integration/auth/keeper/msg_server_test.go index 1078d85040..fc93288c50 100644 --- a/tests/integration/auth/keeper/msg_server_test.go +++ b/tests/integration/auth/keeper/msg_server_test.go @@ -81,7 +81,7 @@ func initFixture(t *testing.T) *fixture { account := baseaccount.NewAccount("base", signing.NewHandlerMap(handler)) accountsKeeper, err := accounts.NewKeeper( cdc, - runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, router)), + runtime.NewEnvironment(runtime.NewKVStoreService(keys[accounts.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(router)), addresscodec.NewBech32Codec("cosmos"), cdc.InterfaceRegistry(), account, diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index d8565c1e5e..c9181c7035 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -124,7 +124,7 @@ func initFixture(t *testing.T) *fixture { grpcRouter := baseapp.NewGRPCQueryRouter() cometService := runtime.NewContextAwareCometInfoService() - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), cometService) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(grpcRouter), runtime.EnvWithMsgRouterService(msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), cometService) require.NoError(t, stakingKeeper.Params.Set(newCtx, stakingtypes.DefaultParams())) poolKeeper := poolkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, stakingKeeper, authority.String()) diff --git a/tests/integration/evidence/keeper/infraction_test.go b/tests/integration/evidence/keeper/infraction_test.go index 3578b47484..5ff02d0c1f 100644 --- a/tests/integration/evidence/keeper/infraction_test.go +++ b/tests/integration/evidence/keeper/infraction_test.go @@ -139,13 +139,13 @@ func initFixture(tb testing.TB) *fixture { assert.NilError(tb, bankKeeper.SetParams(newCtx, banktypes.DefaultParams())) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(grpcQueryRouter), runtime.EnvWithMsgRouterService(msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger()), cdc, codec.NewLegacyAmino(), stakingKeeper, authority.String()) stakingKeeper.SetHooks(stakingtypes.NewMultiStakingHooks(slashingKeeper.Hooks())) - evidenceKeeper := keeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)), stakingKeeper, slashingKeeper, addresscodec.NewBech32Codec(sdk.Bech32PrefixAccAddr)) + evidenceKeeper := keeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[evidencetypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(grpcQueryRouter), runtime.EnvWithMsgRouterService(msgRouter)), stakingKeeper, slashingKeeper, addresscodec.NewBech32Codec(sdk.Bech32PrefixAccAddr)) router := evidencetypes.NewRouter() router = router.AddRoute(evidencetypes.RouteEquivocation, testEquivocationHandler(evidenceKeeper)) evidenceKeeper.SetRouter(router) diff --git a/tests/integration/gov/keeper/keeper_test.go b/tests/integration/gov/keeper/keeper_test.go index b2d3ef7a5d..dfd89f42f1 100644 --- a/tests/integration/gov/keeper/keeper_test.go +++ b/tests/integration/gov/keeper/keeper_test.go @@ -119,7 +119,7 @@ func initFixture(tb testing.TB) *fixture { govKeeper := keeper.NewKeeper( cdc, - runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, router)), + runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(router)), accountKeeper, bankKeeper, stakingKeeper, diff --git a/tests/integration/slashing/keeper/keeper_test.go b/tests/integration/slashing/keeper/keeper_test.go index cd396d6264..d5eefc7315 100644 --- a/tests/integration/slashing/keeper/keeper_test.go +++ b/tests/integration/slashing/keeper/keeper_test.go @@ -85,7 +85,7 @@ func initFixture(tb testing.TB) *fixture { acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) accountKeeper := authkeeper.NewAccountKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), + runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)), cdc, authtypes.ProtoBaseAccount, acctsModKeeper, @@ -99,7 +99,7 @@ func initFixture(tb testing.TB) *fixture { accountKeeper.GetAuthority(): false, } bankKeeper := bankkeeper.NewBaseKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), + runtime.NewEnvironment(runtime.NewKVStoreService(keys[banktypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)), cdc, accountKeeper, blockedAddresses, @@ -110,9 +110,9 @@ func initFixture(tb testing.TB) *fixture { cometInfoService := runtime.NewContextAwareCometInfoService() - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), cometInfoService) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), cometInfoService) - slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), cdc, &codec.LegacyAmino{}, stakingKeeper, authority.String()) + slashingKeeper := slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)), cdc, &codec.LegacyAmino{}, stakingKeeper, authority.String()) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) stakingModule := staking.NewAppModule(cdc, stakingKeeper, accountKeeper, bankKeeper) diff --git a/tests/integration/staking/keeper/common_test.go b/tests/integration/staking/keeper/common_test.go index 1c6e0cd126..b9075c8ad9 100644 --- a/tests/integration/staking/keeper/common_test.go +++ b/tests/integration/staking/keeper/common_test.go @@ -138,7 +138,7 @@ func initFixture(tb testing.TB) *fixture { acctsModKeeper := authtestutil.NewMockAccountsModKeeper(ctrl) accountKeeper := authkeeper.NewAccountKeeper( - runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), + runtime.NewEnvironment(runtime.NewKVStoreService(keys[authtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)), cdc, authtypes.ProtoBaseAccount, acctsModKeeper, @@ -161,7 +161,7 @@ func initFixture(tb testing.TB) *fixture { assert.NilError(tb, bankKeeper.SetParams(newCtx, banktypes.DefaultParams())) - stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(queryRouter, msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) + stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[types.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), runtime.NewContextAwareCometInfoService()) authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper) diff --git a/testutil/integration/router.go b/testutil/integration/router.go index c3f0c95401..48159bcc9d 100644 --- a/testutil/integration/router.go +++ b/testutil/integration/router.go @@ -90,7 +90,7 @@ func NewIntegrationApp( if keys[consensusparamtypes.StoreKey] != nil { // set baseApp param store - consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithRouterService(grpcRouter, msgRouter)), authtypes.NewModuleAddress("gov").String()) + consensusParamsKeeper := consensusparamkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[consensusparamtypes.StoreKey]), log.NewNopLogger(), runtime.EnvWithQueryRouterService(grpcRouter), runtime.EnvWithMsgRouterService(msgRouter)), authtypes.NewModuleAddress("gov").String()) bApp.SetParamStore(consensusParamsKeeper.ParamsStore) consensusparamtypes.RegisterQueryServer(grpcRouter, consensusParamsKeeper) diff --git a/x/accounts/keeper.go b/x/accounts/keeper.go index 68725959f1..8c50fce6fc 100644 --- a/x/accounts/keeper.go +++ b/x/accounts/keeper.go @@ -335,7 +335,7 @@ func (k Keeper) SendModuleMessageUntyped(ctx context.Context, sender []byte, msg if !bytes.Equal(sender, wantSenders[0]) { return nil, fmt.Errorf("%w: sender does not match expected sender", ErrUnauthorized) } - resp, err := k.RouterService.MessageRouterService().InvokeUntyped(ctx, msg) + resp, err := k.MsgRouterService.InvokeUntyped(ctx, msg) if err != nil { return nil, err } @@ -358,14 +358,14 @@ func (k Keeper) sendModuleMessage(ctx context.Context, sender []byte, msg, msgRe if !bytes.Equal(sender, wantSenders[0]) { return fmt.Errorf("%w: sender does not match expected sender", ErrUnauthorized) } - return k.RouterService.MessageRouterService().InvokeTyped(ctx, msg, msgResp) + return k.MsgRouterService.InvokeTyped(ctx, msg, msgResp) } // queryModule is the entrypoint for an account to query a module. // It will try to find the query handler for the given query and execute it. // If multiple query handlers are found, it will return an error. func (k Keeper) queryModule(ctx context.Context, queryReq, queryResp implementation.ProtoMsg) error { - return k.RouterService.QueryRouterService().InvokeTyped(ctx, queryReq, queryResp) + return k.QueryRouterService.InvokeTyped(ctx, queryReq, queryResp) } // maybeSendFunds will send the provided coins between the provided addresses, if amt diff --git a/x/accounts/utils_test.go b/x/accounts/utils_test.go index 3b07c7686f..2362088c67 100644 --- a/x/accounts/utils_test.go +++ b/x/accounts/utils_test.go @@ -74,10 +74,7 @@ func newKeeper(t *testing.T, accounts ...implementation.AccountCreatorFunc) (Kee msgRouter.RegisterService(&bankv1beta1.Msg_ServiceDesc, &bankMsgServer{}) ss, ctx := colltest.MockStore() - env := runtime.NewEnvironment(ss, log.NewNopLogger(), runtime.EnvWithRouterService( - queryRouter, - msgRouter, - )) + env := runtime.NewEnvironment(ss, log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryRouter), runtime.EnvWithMsgRouterService(msgRouter)) env.EventService = eventService{} m, err := NewKeeper(codec.NewProtoCodec(ir), env, addressCodec, ir, accounts...) require.NoError(t, err) diff --git a/x/auth/ante/setup.go b/x/auth/ante/setup.go index 799e3bef02..f048bb1393 100644 --- a/x/auth/ante/setup.go +++ b/x/auth/ante/setup.go @@ -47,7 +47,7 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, // TODO: possibly cache the result of this query for other antehandlers to use var res consensusv1.QueryParamsResponse - if err := sud.env.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := sud.env.QueryRouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { return newCtx, err } diff --git a/x/auth/ante/testutil_test.go b/x/auth/ante/testutil_test.go index 6549169267..d9c23f5294 100644 --- a/x/auth/ante/testutil_test.go +++ b/x/auth/ante/testutil_test.go @@ -98,7 +98,7 @@ func SetupTestSuite(t *testing.T, isCheckTx bool) *AnteTestSuite { }, nil).AnyTimes() consensustypes.RegisterQueryServer(grpcQueryRouter, suite.consensusKeeper) - suite.env = runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger(), runtime.EnvWithRouterService(grpcQueryRouter, msgRouter)) + suite.env = runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger(), runtime.EnvWithQueryRouterService(grpcQueryRouter), runtime.EnvWithMsgRouterService(msgRouter)) suite.accountKeeper = keeper.NewAccountKeeper( runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger()), suite.encCfg.Codec, types.ProtoBaseAccount, suite.acctsModKeeper, maccPerms, authcodec.NewBech32Codec("cosmos"), sdk.Bech32MainPrefix, types.NewModuleAddress("gov").String(), diff --git a/x/authz/keeper/genesis_test.go b/x/authz/keeper/genesis_test.go index a4a4003351..42d289a5a1 100644 --- a/x/authz/keeper/genesis_test.go +++ b/x/authz/keeper/genesis_test.go @@ -68,7 +68,7 @@ func (suite *GenesisTestSuite) SetupTest() { msr := suite.baseApp.MsgServiceRouter() msr.SetInterfaceRegistry(suite.encCfg.InterfaceRegistry) - env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(nil, msr)) + env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithMsgRouterService(msr)) suite.keeper = keeper.NewKeeper(env, suite.encCfg.Codec, suite.accountKeeper) } diff --git a/x/authz/keeper/keeper.go b/x/authz/keeper/keeper.go index 2d9b39db49..426959939d 100644 --- a/x/authz/keeper/keeper.go +++ b/x/authz/keeper/keeper.go @@ -142,7 +142,7 @@ func (k Keeper) DispatchActions(ctx context.Context, grantee sdk.AccAddress, msg } // no need to use the branch service here, as if the transaction fails, the transaction will be reverted - _, err = k.RouterService.MessageRouterService().InvokeUntyped(ctx, msg) + _, err = k.MsgRouterService.InvokeUntyped(ctx, msg) if err != nil { return nil, fmt.Errorf("failed to execute message %d; message %v: %w", i, msg, err) } diff --git a/x/authz/keeper/keeper_test.go b/x/authz/keeper/keeper_test.go index c1e18ea48a..a10c4289e7 100644 --- a/x/authz/keeper/keeper_test.go +++ b/x/authz/keeper/keeper_test.go @@ -75,7 +75,7 @@ func (s *TestSuite) SetupTest() { banktypes.RegisterInterfaces(s.encCfg.InterfaceRegistry) banktypes.RegisterMsgServer(s.baseApp.MsgServiceRouter(), s.bankKeeper) - env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(s.baseApp.GRPCQueryRouter(), s.baseApp.MsgServiceRouter())) + env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithQueryRouterService(s.baseApp.GRPCQueryRouter()), runtime.EnvWithMsgRouterService(s.baseApp.MsgServiceRouter())) s.authzKeeper = authzkeeper.NewKeeper(env, s.encCfg.Codec, s.accountKeeper) queryHelper := baseapp.NewQueryServerTestHelper(s.ctx, s.encCfg.InterfaceRegistry) diff --git a/x/authz/keeper/msg_server.go b/x/authz/keeper/msg_server.go index efc53c449e..b7c0e7d664 100644 --- a/x/authz/keeper/msg_server.go +++ b/x/authz/keeper/msg_server.go @@ -40,7 +40,7 @@ func (k Keeper) Grant(ctx context.Context, msg *authz.MsgGrant) (*authz.MsgGrant } t := authorization.MsgTypeURL() - if err := k.RouterService.MessageRouterService().CanInvoke(ctx, t); err != nil { + if err := k.MsgRouterService.CanInvoke(ctx, t); err != nil { return nil, sdkerrors.ErrInvalidType.Wrapf("%s doesn't exist", t) } diff --git a/x/authz/module/abci_test.go b/x/authz/module/abci_test.go index 53f0701f28..e241edb3c6 100644 --- a/x/authz/module/abci_test.go +++ b/x/authz/module/abci_test.go @@ -66,7 +66,7 @@ func TestExpiredGrantsQueue(t *testing.T) { accountKeeper.EXPECT().AddressCodec().Return(address.NewBech32Codec("cosmos")).AnyTimes() - env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(baseApp.GRPCQueryRouter(), baseApp.MsgServiceRouter())) + env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithQueryRouterService(baseApp.GRPCQueryRouter()), runtime.EnvWithMsgRouterService(baseApp.MsgServiceRouter())) authzKeeper := keeper.NewKeeper(env, encCfg.Codec, accountKeeper) save := func(grantee sdk.AccAddress, exp *time.Time) { diff --git a/x/evidence/keeper/infraction.go b/x/evidence/keeper/infraction.go index 97b49c95a4..713d21ad62 100644 --- a/x/evidence/keeper/infraction.go +++ b/x/evidence/keeper/infraction.go @@ -74,7 +74,7 @@ func (k Keeper) handleEquivocationEvidence(ctx context.Context, evidence *types. // if the difference in time and number of blocks is greater than the allowed // parameters defined. var res consensusv1.QueryParamsResponse - if err := k.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := k.QueryRouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { return fmt.Errorf("failed to query consensus params: %w", err) } if res.Params.Evidence != nil { diff --git a/x/gov/keeper/abci.go b/x/gov/keeper/abci.go index 1a5f9fa033..02183342d5 100644 --- a/x/gov/keeper/abci.go +++ b/x/gov/keeper/abci.go @@ -196,7 +196,7 @@ func (k Keeper) EndBlocker(ctx context.Context) error { if err := k.BranchService.Execute(ctx, func(ctx context.Context) error { // execute all messages for idx, msg = range messages { - if _, err := safeExecuteHandler(ctx, msg, k.RouterService.MessageRouterService()); err != nil { + if _, err := safeExecuteHandler(ctx, msg, k.MsgRouterService); err != nil { // `idx` and `err` are populated with the msg index and error. proposal.Status = v1.StatusFailed proposal.FailedReason = err.Error() @@ -283,7 +283,7 @@ func (k Keeper) EndBlocker(ctx context.Context) error { } // executes route(msg) and recovers from panic. -func safeExecuteHandler(ctx context.Context, msg sdk.Msg, router router.Router) (res protoiface.MessageV1, err error) { +func safeExecuteHandler(ctx context.Context, msg sdk.Msg, router router.Service) (res protoiface.MessageV1, err error) { defer func() { if r := recover(); r != nil { err = fmt.Errorf("handling x/gov proposal msg [%s] PANICKED: %v", msg, r) diff --git a/x/gov/keeper/abci_internal_test.go b/x/gov/keeper/abci_internal_test.go index 62c2c3403a..768a09b9ff 100644 --- a/x/gov/keeper/abci_internal_test.go +++ b/x/gov/keeper/abci_internal_test.go @@ -10,13 +10,13 @@ import ( "cosmossdk.io/core/router" ) -type mockRouter struct { - router.Router +type mockRouterService struct { + router.Service panic bool } -func (m *mockRouter) InvokeUntyped(ctx context.Context, req protoiface.MessageV1) (res protoiface.MessageV1, err error) { +func (m *mockRouterService) InvokeUntyped(ctx context.Context, req protoiface.MessageV1) (res protoiface.MessageV1, err error) { if m.panic { panic("test-fail") } @@ -30,10 +30,10 @@ func TestSafeExecuteHandler(t *testing.T) { require := require.New(t) ctx := context.Background() - r, err := safeExecuteHandler(ctx, nil, &mockRouter{panic: true}) + r, err := safeExecuteHandler(ctx, nil, &mockRouterService{panic: true}) require.ErrorContains(err, "test-fail") require.Nil(r) - _, err = safeExecuteHandler(ctx, nil, &mockRouter{panic: false}) + _, err = safeExecuteHandler(ctx, nil, &mockRouterService{panic: false}) require.Nil(err) } diff --git a/x/gov/keeper/common_test.go b/x/gov/keeper/common_test.go index fced8554ff..fb79521eee 100644 --- a/x/gov/keeper/common_test.go +++ b/x/gov/keeper/common_test.go @@ -133,7 +133,7 @@ func setupGovKeeper(t *testing.T, expectations ...func(sdk.Context, mocks)) ( baseApp.SetCMS(testCtx.CMS) baseApp.SetInterfaceRegistry(encCfg.InterfaceRegistry) - environment := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(baseApp.GRPCQueryRouter(), baseApp.MsgServiceRouter())) + environment := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithQueryRouterService(baseApp.GRPCQueryRouter()), runtime.EnvWithMsgRouterService(baseApp.MsgServiceRouter())) // gomock initializations ctrl := gomock.NewController(t) @@ -199,7 +199,7 @@ func setupGovKeeperWithMaxVoteOptionsLen(t *testing.T, maxVoteOptionsLen uint64, baseApp.SetCMS(testCtx.CMS) baseApp.SetInterfaceRegistry(encCfg.InterfaceRegistry) - environment := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(baseApp.GRPCQueryRouter(), baseApp.MsgServiceRouter())) + environment := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithQueryRouterService(baseApp.GRPCQueryRouter()), runtime.EnvWithMsgRouterService(baseApp.MsgServiceRouter())) // gomock initializations ctrl := gomock.NewController(t) diff --git a/x/gov/keeper/msg_server.go b/x/gov/keeper/msg_server.go index 4178a4dc55..811d99c618 100644 --- a/x/gov/keeper/msg_server.go +++ b/x/gov/keeper/msg_server.go @@ -378,11 +378,11 @@ func (k msgServer) SudoExec(ctx context.Context, msg *v1.MsgSudoExec) (*v1.MsgSu var msgResp protoiface.MessageV1 if err := k.BranchService.Execute(ctx, func(ctx context.Context) error { // TODO add route check here - if err := k.RouterService.MessageRouterService().CanInvoke(ctx, sdk.MsgTypeURL(sudoedMsg)); err != nil { + if err := k.MsgRouterService.CanInvoke(ctx, sdk.MsgTypeURL(sudoedMsg)); err != nil { return errors.Wrapf(govtypes.ErrInvalidProposal, err.Error()) } - msgResp, err = k.RouterService.MessageRouterService().InvokeUntyped(ctx, sudoedMsg) + msgResp, err = k.MsgRouterService.InvokeUntyped(ctx, sudoedMsg) if err != nil { return errors.Wrapf(err, "failed to execute sudo-ed message; message %v", sudoedMsg) } diff --git a/x/gov/keeper/proposal.go b/x/gov/keeper/proposal.go index 91f97b0a7b..1e15ebb85d 100644 --- a/x/gov/keeper/proposal.go +++ b/x/gov/keeper/proposal.go @@ -87,7 +87,7 @@ func (k Keeper) SubmitProposal(ctx context.Context, messages []sdk.Msg, metadata return v1.Proposal{}, errorsmod.Wrapf(types.ErrInvalidSigner, addr) } - if err := k.RouterService.MessageRouterService().CanInvoke(ctx, sdk.MsgTypeURL(msg)); err != nil { + if err := k.MsgRouterService.CanInvoke(ctx, sdk.MsgTypeURL(msg)); err != nil { return v1.Proposal{}, errorsmod.Wrap(types.ErrUnroutableProposalMsg, err.Error()) } diff --git a/x/group/keeper/genesis_test.go b/x/group/keeper/genesis_test.go index 9e61244079..a508ae96b7 100644 --- a/x/group/keeper/genesis_test.go +++ b/x/group/keeper/genesis_test.go @@ -77,7 +77,7 @@ func (s *GenesisTestSuite) SetupTest() { s.ctx = s.sdkCtx s.addressCodec = address.NewBech32Codec("cosmos") - env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(bApp.GRPCQueryRouter(), bApp.MsgServiceRouter())) + env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithQueryRouterService(bApp.GRPCQueryRouter()), runtime.EnvWithMsgRouterService(bApp.MsgServiceRouter())) s.keeper = keeper.NewKeeper(env, s.cdc, accountKeeper, group.DefaultConfig()) } diff --git a/x/group/keeper/grpc_query_test.go b/x/group/keeper/grpc_query_test.go index d8da1ad1fc..e0cce15884 100644 --- a/x/group/keeper/grpc_query_test.go +++ b/x/group/keeper/grpc_query_test.go @@ -75,7 +75,7 @@ func initKeeper(t *testing.T) *fixture { accountKeeper.EXPECT().NewAccount(gomock.Any(), gomock.Any()).Return(nil).AnyTimes() accountKeeper.EXPECT().SetAccount(gomock.Any(), gomock.Any()).AnyTimes() - env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger(), runtime.EnvWithRouterService(bApp.GRPCQueryRouter(), bApp.MsgServiceRouter())) + env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger(), runtime.EnvWithQueryRouterService(bApp.GRPCQueryRouter()), runtime.EnvWithMsgRouterService(bApp.MsgServiceRouter())) groupKeeper = groupkeeper.NewKeeper(env, encCfg.Codec, accountKeeper, group.DefaultConfig()) queryHelper := baseapp.NewQueryServerTestHelper(ctx, interfaceRegistry) diff --git a/x/group/keeper/keeper_test.go b/x/group/keeper/keeper_test.go index fa44f4f729..498b3d81bf 100644 --- a/x/group/keeper/keeper_test.go +++ b/x/group/keeper/keeper_test.go @@ -82,7 +82,7 @@ func (s *TestSuite) SetupTest() { bApp.SetInterfaceRegistry(encCfg.InterfaceRegistry) banktypes.RegisterMsgServer(bApp.MsgServiceRouter(), s.bankKeeper) - env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger(), runtime.EnvWithRouterService(bApp.GRPCQueryRouter(), bApp.MsgServiceRouter())) + env := runtime.NewEnvironment(runtime.NewKVStoreService(key), log.NewNopLogger(), runtime.EnvWithQueryRouterService(bApp.GRPCQueryRouter()), runtime.EnvWithMsgRouterService(bApp.MsgServiceRouter())) config := group.DefaultConfig() s.groupKeeper = keeper.NewKeeper(env, encCfg.Codec, s.accountKeeper, config) s.ctx = testCtx.Ctx.WithHeaderInfo(header.Info{Time: s.blockTime}) diff --git a/x/group/keeper/proposal_executor.go b/x/group/keeper/proposal_executor.go index 484807c502..cad16eba4f 100644 --- a/x/group/keeper/proposal_executor.go +++ b/x/group/keeper/proposal_executor.go @@ -45,7 +45,7 @@ func (k Keeper) doExecuteMsgs(ctx context.Context, proposal group.Proposal, grou } for i, msg := range msgs { - if _, err := k.RouterService.MessageRouterService().InvokeUntyped(ctx, msg); err != nil { + if _, err := k.MsgRouterService.InvokeUntyped(ctx, msg); err != nil { return errorsmod.Wrapf(err, "message %s at position %d", sdk.MsgTypeURL(msg), i) } } diff --git a/x/staking/keeper/keeper_test.go b/x/staking/keeper/keeper_test.go index 8acc1b8ae5..b8b76cdcd0 100644 --- a/x/staking/keeper/keeper_test.go +++ b/x/staking/keeper/keeper_test.go @@ -87,7 +87,7 @@ func (s *KeeperTestSuite) SetupTest() { consensustypes.RegisterQueryServer(queryHelper, ck) bankKeeper := stakingtestutil.NewMockBankKeeper(ctrl) - env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(queryHelper.GRPCQueryRouter, s.baseApp.MsgServiceRouter())) + env := runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithQueryRouterService(queryHelper.GRPCQueryRouter), runtime.EnvWithMsgRouterService(s.baseApp.MsgServiceRouter())) authority, err := accountKeeper.AddressCodec().BytesToString(authtypes.NewModuleAddress(stakingtypes.GovModuleName)) s.Require().NoError(err) keeper := stakingkeeper.NewKeeper( diff --git a/x/staking/keeper/msg_server.go b/x/staking/keeper/msg_server.go index 3b7cc951ef..7cc198270d 100644 --- a/x/staking/keeper/msg_server.go +++ b/x/staking/keeper/msg_server.go @@ -69,7 +69,7 @@ func (k msgServer) CreateValidator(ctx context.Context, msg *types.MsgCreateVali } res := consensusv1.QueryParamsResponse{} - if err := k.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := k.QueryRouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { return nil, errorsmod.Wrapf(sdkerrors.ErrInvalidRequest, "failed to query consensus params: %s", err) } if res.Params.Validator != nil { diff --git a/x/upgrade/keeper/abci.go b/x/upgrade/keeper/abci.go index e46348791c..ce1a418ea2 100644 --- a/x/upgrade/keeper/abci.go +++ b/x/upgrade/keeper/abci.go @@ -49,7 +49,7 @@ func (k Keeper) PreBlocker(ctx context.Context) error { var appVersion uint64 var res consensusv1.QueryParamsResponse - if err := k.RouterService.QueryRouterService().InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { + if err := k.QueryRouterService.InvokeTyped(ctx, &consensusv1.QueryParamsRequest{}, &res); err != nil { return errors.New("failed to query consensus params") } if res.Params.Version != nil { diff --git a/x/upgrade/keeper/abci_test.go b/x/upgrade/keeper/abci_test.go index ab6a3c2b8d..bfbae87cbb 100644 --- a/x/upgrade/keeper/abci_test.go +++ b/x/upgrade/keeper/abci_test.go @@ -129,7 +129,7 @@ func setupTest(t *testing.T, height int64, skip map[int64]bool) *TestSuite { ) storeService := runtime.NewKVStoreService(key) - s.env = runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithRouterService(s.baseApp.GRPCQueryRouter(), s.baseApp.MsgServiceRouter())) + s.env = runtime.NewEnvironment(storeService, log.NewNopLogger(), runtime.EnvWithMsgRouterService(s.baseApp.MsgServiceRouter()), runtime.EnvWithQueryRouterService(s.baseApp.GRPCQueryRouter())) s.baseApp.SetParamStore(¶mStore{params: cmtproto.ConsensusParams{Version: &cmtproto.VersionParams{App: 1}}})