Skip to content

Commit

Permalink
chore: remove legacy appmodule boiler plate (#12725)
Browse files Browse the repository at this point in the history
* remove legacy appmodule boiler plate

* remove legacy code

* remove legacy gov rest routes

* remove staking querier

* fix legacy

* remove unused test

* add upgrading and changelog entry

* Update UPGRADING.md

Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>

* fix tests

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 28, 2022
1 parent 09553f1 commit 3a09701
Show file tree
Hide file tree
Showing 53 changed files with 90 additions and 3,707 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
The information can now be accessed using the BankKeeper.
Setting can be done using MsgSetSendEnabled as a governance proposal.
A SendEnabled query has been added to both GRPC and CLI.
* (appModule) Remove `Route`, `QuerierRoute` and `LegacyQuerierHandler` from AppModule Interface.
* (x/modules) Remove all LegacyQueries and related code from modules

### CLI Breaking Changes

Expand Down
6 changes: 6 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This guide provides instructions for upgrading to specific versions of Cosmos SD

## [Unreleased]

### AppModule Interface

Remove `Querier`, `Route` and `LegacyQuerier` from the app module interface. This removes and fully deprecates all legacy queriers. All modules no longer support the REST API previously known as the LCD, and the `sdk.Msg#Route` method won't be used anymore.



### SimApp

SimApp's `app.go` is using App Wiring, the dependency injection framework of the Cosmos SDK.
Expand Down
1 change: 0 additions & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ func NewSimApp(
// app.ModuleManager.SetOrderMigrations(custom order)

app.ModuleManager.RegisterInvariants(app.CrisisKeeper)
app.ModuleManager.RegisterRoutes(app.Router(), app.QueryRouter(), app.legacyAmino)

// RegisterUpgradeHandlers is used for registering any on-chain upgrades.
// Make sure it's called after `app.ModuleManager` and `app.configurator` are set.
Expand Down
1 change: 0 additions & 1 deletion simapp/app_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ func NewSimApp(
// app.ModuleManager.SetOrderMigrations(custom order)

app.ModuleManager.RegisterInvariants(app.CrisisKeeper)
app.ModuleManager.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
app.ModuleManager.RegisterServices(app.configurator)

Expand Down
21 changes: 0 additions & 21 deletions types/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,6 @@ type AppModule interface {
// registers
RegisterInvariants(sdk.InvariantRegistry)

// Deprecated: use RegisterServices
Route() sdk.Route

// Deprecated: use RegisterServices
QuerierRoute() string

// Deprecated: use RegisterServices
LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier

// RegisterServices allows a module to register services
RegisterServices(Configurator)

Expand Down Expand Up @@ -288,18 +279,6 @@ func (m *Manager) RegisterInvariants(ir sdk.InvariantRegistry) {
}
}

// RegisterRoutes registers all module routes and module querier routes
func (m *Manager) RegisterRoutes(router sdk.Router, queryRouter sdk.QueryRouter, legacyQuerierCdc *codec.LegacyAmino) {
for _, module := range m.Modules {
if r := module.Route(); !r.Empty() {
router.AddRoute(r)
}
if r := module.QuerierRoute(); r != "" {
queryRouter.AddRoute(r, module.LegacyQuerierHandler(legacyQuerierCdc))
}
}
}

// RegisterServices registers all module services
func (m *Manager) RegisterServices(cfg Configurator) {
for _, module := range m.Modules {
Expand Down
35 changes: 0 additions & 35 deletions types/module/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ func TestGenesisOnlyAppModule(t *testing.T) {
mockInvariantRegistry := mocks.NewMockInvariantRegistry(mockCtrl)
goam := module.NewGenesisOnlyAppModule(mockModule)

require.True(t, goam.Route().Empty())
require.Empty(t, goam.QuerierRoute())
require.Nil(t, goam.LegacyQuerierHandler(nil))

// no-op
goam.RegisterInvariants(mockInvariantRegistry)
}
Expand Down Expand Up @@ -129,37 +125,6 @@ func TestManager_RegisterInvariants(t *testing.T) {
mm.RegisterInvariants(mockInvariantRegistry)
}

func TestManager_RegisterRoutes(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)

mockAppModule1 := mocks.NewMockAppModule(mockCtrl)
mockAppModule2 := mocks.NewMockAppModule(mockCtrl)
mockAppModule1.EXPECT().Name().Times(2).Return("module1")
mockAppModule2.EXPECT().Name().Times(2).Return("module2")
mm := module.NewManager(mockAppModule1, mockAppModule2)
require.NotNil(t, mm)
require.Equal(t, 2, len(mm.Modules))

router := mocks.NewMockRouter(mockCtrl)
noopHandler := sdk.Handler(func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { return nil, nil })
route1 := sdk.NewRoute("route1", noopHandler)
route2 := sdk.NewRoute("", noopHandler)
mockAppModule1.EXPECT().Route().Times(1).Return(route1)
mockAppModule2.EXPECT().Route().Times(1).Return(route2)
router.EXPECT().AddRoute(gomock.Any()).Times(1) // Use of Any due to limitations to compare Functions as the sdk.Handler

queryRouter := mocks.NewMockQueryRouter(mockCtrl)
mockAppModule1.EXPECT().QuerierRoute().Times(1).Return("querierRoute1")
mockAppModule2.EXPECT().QuerierRoute().Times(1).Return("")
handler3 := sdk.Querier(nil)
amino := codec.NewLegacyAmino()
mockAppModule1.EXPECT().LegacyQuerierHandler(amino).Times(1).Return(handler3)
queryRouter.EXPECT().AddRoute(gomock.Eq("querierRoute1"), gomock.Eq(handler3)).Times(1)

mm.RegisterRoutes(router, queryRouter, amino)
}

func TestManager_RegisterQueryServices(t *testing.T) {
mockCtrl := gomock.NewController(t)
t.Cleanup(mockCtrl.Finish)
Expand Down
61 changes: 0 additions & 61 deletions x/auth/keeper/querier.go

This file was deleted.

62 changes: 0 additions & 62 deletions x/auth/keeper/querier_test.go

This file was deleted.

15 changes: 0 additions & 15 deletions x/auth/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,21 +118,6 @@ func (AppModule) Name() string {
// RegisterInvariants performs a no-op.
func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}

// Deprecated: Route returns the message routing key for the auth module.
func (AppModule) Route() sdk.Route {
return sdk.Route{}
}

// QuerierRoute returns the auth module's querier route name.
func (AppModule) QuerierRoute() string {
return types.QuerierRoute
}

// LegacyQuerierHandler returns the auth module sdk.Querier.
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return keeper.NewQuerier(am.accountKeeper, legacyQuerierCdc)
}

// RegisterServices registers a GRPC query service to respond to the
// module-specific GRPC queries.
func (am AppModule) RegisterServices(cfg module.Configurator) {
Expand Down
3 changes: 0 additions & 3 deletions x/auth/types/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ const (

// FeeCollectorName the root string for the fee collector account address
FeeCollectorName = "fee_collector"

// QuerierRoute is the querier route for auth
QuerierRoute = ModuleName
)

var (
Expand Down
14 changes: 0 additions & 14 deletions x/auth/vesting/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,25 +92,11 @@ func NewAppModule(ak keeper.AccountKeeper, bk types.BankKeeper) AppModule {
// RegisterInvariants performs a no-op; there are no invariants to enforce.
func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}

// Deprecated: Route returns the module's message router and handler.
func (am AppModule) Route() sdk.Route {
return sdk.Route{}
}

// QuerierRoute returns an empty string as the module contains no query
// functionality.
func (AppModule) QuerierRoute() string { return "" }

// RegisterServices registers module services.
func (am AppModule) RegisterServices(cfg module.Configurator) {
types.RegisterMsgServer(cfg.MsgServer(), NewMsgServerImpl(am.accountKeeper, am.bankKeeper))
}

// LegacyQuerierHandler performs a no-op.
func (am AppModule) LegacyQuerierHandler(_ *codec.LegacyAmino) sdk.Querier {
return nil
}

// InitGenesis performs a no-op.
func (am AppModule) InitGenesis(_ sdk.Context, _ codec.JSONCodec, _ json.RawMessage) []abci.ValidatorUpdate {
return []abci.ValidatorUpdate{}
Expand Down
13 changes: 0 additions & 13 deletions x/authz/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,23 +128,10 @@ func (AppModule) Name() string {
// RegisterInvariants does nothing, there are no invariants to enforce
func (AppModule) RegisterInvariants(_ sdk.InvariantRegistry) {}

// Deprecated: Route returns the message routing key for the authz module.
func (am AppModule) Route() sdk.Route {
return sdk.Route{}
}

func (am AppModule) NewHandler() sdk.Handler {
return nil
}

// QuerierRoute returns the route we respond to for abci queries
func (AppModule) QuerierRoute() string { return "" }

// LegacyQuerierHandler returns the authz module sdk.Querier.
func (am AppModule) LegacyQuerierHandler(legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return nil
}

// InitGenesis performs genesis initialization for the authz module. It returns
// no validator updates.
func (am AppModule) InitGenesis(ctx sdk.Context, cdc codec.JSONCodec, data json.RawMessage) []abci.ValidatorUpdate {
Expand Down
Loading

0 comments on commit 3a09701

Please sign in to comment.