Skip to content

Commit

Permalink
refactor(app): remove dead code in app setup (#1560)
Browse files Browse the repository at this point in the history
* clean imports

* remove dead code
  • Loading branch information
k-yang authored Aug 31, 2023
1 parent c37abdd commit d0bc884
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 102 deletions.
21 changes: 8 additions & 13 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ import (
"os"
"path/filepath"

"github.com/NibiruChain/nibiru/x/genmsg"

"github.com/NibiruChain/nibiru/x/sudo/keeper"

sudotypes "github.com/NibiruChain/nibiru/x/sudo/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
dbm "github.com/cometbft/cometbft-db"
Expand Down Expand Up @@ -96,18 +90,17 @@ import (
"github.com/spf13/cast"

"github.com/NibiruChain/nibiru/x/common"
devgas "github.com/NibiruChain/nibiru/x/devgas/v1"
devgaskeeper "github.com/NibiruChain/nibiru/x/devgas/v1/keeper"
devgastypes "github.com/NibiruChain/nibiru/x/devgas/v1/types"
"github.com/NibiruChain/nibiru/x/epochs"
epochskeeper "github.com/NibiruChain/nibiru/x/epochs/keeper"
epochstypes "github.com/NibiruChain/nibiru/x/epochs/types"
"github.com/NibiruChain/nibiru/x/genmsg"
"github.com/NibiruChain/nibiru/x/inflation"
inflationkeeper "github.com/NibiruChain/nibiru/x/inflation/keeper"
inflationtypes "github.com/NibiruChain/nibiru/x/inflation/types"
"github.com/NibiruChain/nibiru/x/oracle"

devgas "github.com/NibiruChain/nibiru/x/devgas/v1"
devgaskeeper "github.com/NibiruChain/nibiru/x/devgas/v1/keeper"
devgastypes "github.com/NibiruChain/nibiru/x/devgas/v1/types"

oraclekeeper "github.com/NibiruChain/nibiru/x/oracle/keeper"
oracletypes "github.com/NibiruChain/nibiru/x/oracle/types"
perpkeeperv2 "github.com/NibiruChain/nibiru/x/perp/v2/keeper"
Expand All @@ -120,6 +113,8 @@ import (
stablecoinkeeper "github.com/NibiruChain/nibiru/x/stablecoin/keeper"
stablecointypes "github.com/NibiruChain/nibiru/x/stablecoin/types"
"github.com/NibiruChain/nibiru/x/sudo"
"github.com/NibiruChain/nibiru/x/sudo/keeper"
sudotypes "github.com/NibiruChain/nibiru/x/sudo/types"
wasmbinding "github.com/NibiruChain/nibiru/x/wasm/binding"
)

Expand Down Expand Up @@ -343,7 +338,7 @@ func NewNibiruApp(
bApp.SetInterfaceRegistry(interfaceRegistry)
bApp.SetTxEncoder(txConfig.TxEncoder())

keys, tkeys, memKeys := GetStoreKeys()
keys, tkeys, memKeys := initStoreKeys()
app := &NibiruApp{
BaseApp: bApp,
legacyAmino: legacyAmino,
Expand All @@ -363,7 +358,7 @@ func NewNibiruApp(
skipGenesisInvariants := cast.ToBool(
appOpts.Get(crisis.FlagSkipGenesisInvariants))

app.InitModuleManager(encodingConfig, skipGenesisInvariants)
app.initModuleManager(encodingConfig, skipGenesisInvariants)

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
Expand Down
110 changes: 36 additions & 74 deletions app/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@ package app
import (
"path/filepath"

"github.com/NibiruChain/nibiru/x/genmsg"

"github.com/NibiruChain/nibiru/x/sudo/keeper"

sudotypes "github.com/NibiruChain/nibiru/x/sudo/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
_ "github.com/cosmos/cosmos-sdk/client/docs/statik"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -80,41 +76,34 @@ import (
ibcmock "github.com/cosmos/ibc-go/v7/testing/mock"
"github.com/spf13/cast"

"github.com/NibiruChain/nibiru/x/devgas/v1"
devgaskeeper "github.com/NibiruChain/nibiru/x/devgas/v1/keeper"
devgastypes "github.com/NibiruChain/nibiru/x/devgas/v1/types"
"github.com/NibiruChain/nibiru/x/epochs"
epochskeeper "github.com/NibiruChain/nibiru/x/epochs/keeper"
epochstypes "github.com/NibiruChain/nibiru/x/epochs/types"

"github.com/NibiruChain/nibiru/x/sudo"

"github.com/NibiruChain/nibiru/x/genmsg"
"github.com/NibiruChain/nibiru/x/inflation"
inflationkeeper "github.com/NibiruChain/nibiru/x/inflation/keeper"
inflationtypes "github.com/NibiruChain/nibiru/x/inflation/types"

oracle "github.com/NibiruChain/nibiru/x/oracle"
oraclekeeper "github.com/NibiruChain/nibiru/x/oracle/keeper"
oracletypes "github.com/NibiruChain/nibiru/x/oracle/types"

perpv2keeper "github.com/NibiruChain/nibiru/x/perp/v2/keeper"
perpv2 "github.com/NibiruChain/nibiru/x/perp/v2/module"
perpv2types "github.com/NibiruChain/nibiru/x/perp/v2/types"

"github.com/NibiruChain/nibiru/x/devgas/v1"
devgaskeeper "github.com/NibiruChain/nibiru/x/devgas/v1/keeper"
devgastypes "github.com/NibiruChain/nibiru/x/devgas/v1/types"

"github.com/NibiruChain/nibiru/x/spot"
spotkeeper "github.com/NibiruChain/nibiru/x/spot/keeper"
spottypes "github.com/NibiruChain/nibiru/x/spot/types"

"github.com/NibiruChain/nibiru/x/stablecoin"
stablecoinkeeper "github.com/NibiruChain/nibiru/x/stablecoin/keeper"
stablecointypes "github.com/NibiruChain/nibiru/x/stablecoin/types"

"github.com/CosmWasm/wasmd/x/wasm"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/NibiruChain/nibiru/x/sudo"
"github.com/NibiruChain/nibiru/x/sudo/keeper"
sudotypes "github.com/NibiruChain/nibiru/x/sudo/types"
)

func GetStoreKeys() (
func initStoreKeys() (
keys map[string]*types.KVStoreKey,
tkeys map[string]*types.TransientStoreKey,
memKeys map[string]*types.MemoryStoreKey,
Expand Down Expand Up @@ -209,7 +198,7 @@ func (app *NibiruApp) InitKeepers(
appCodec,
keys[banktypes.StoreKey],
app.AccountKeeper,
BlockedAddresses(),
blockedAddresses(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.stakingKeeper = stakingkeeper.NewKeeper(
Expand Down Expand Up @@ -489,29 +478,14 @@ func (app *NibiruApp) InitKeepers(
return wasmConfig
}

func (app *NibiruApp) AppModules(
func (app *NibiruApp) initAppModules(
encodingConfig EncodingConfig,
skipGenesisInvariants bool,
) []module.AppModule {
appCodec := app.appCodec
spotModule := spot.NewAppModule(
appCodec, app.SpotKeeper, app.AccountKeeper, app.BankKeeper)
oracleModule := oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper)
epochsModule := epochs.NewAppModule(appCodec, app.EpochsKeeper)
stablecoinModule := stablecoin.NewAppModule(
appCodec, app.StablecoinKeeper, app.AccountKeeper, app.BankKeeper,
nil,
)
perpv2Module := perpv2.NewAppModule(
appCodec, app.PerpKeeperV2, app.AccountKeeper, app.BankKeeper, app.OracleKeeper,
)
inflationModule := inflation.NewAppModule(
app.InflationKeeper, app.AccountKeeper, *app.stakingKeeper,
)
sudoModule := sudo.NewAppModule(appCodec, app.SudoKeeper)
genMsgModule := genmsg.NewAppModule(app.MsgServiceRouter())

return []module.AppModule{
// core modules
genutil.NewAppModule(
app.AccountKeeper, app.stakingKeeper, app.BaseApp.DeliverTx,
encodingConfig.TxConfig,
Expand All @@ -522,24 +496,22 @@ func (app *NibiruApp) AppModules(
capability.NewAppModule(appCodec, *app.capabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
// TODO dont we have mint module?
slashing.NewAppModule(appCodec, app.slashingKeeper, app.AccountKeeper, app.BankKeeper, app.stakingKeeper, app.GetSubspace(slashingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.stakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
staking.NewAppModule(appCodec, app.stakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
upgrade.NewAppModule(&app.upgradeKeeper),
params.NewAppModule(app.paramsKeeper),
authzmodule.NewAppModule(appCodec, app.authzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),

// native x/
spotModule,
stablecoinModule,
oracleModule,
epochsModule,
perpv2Module,
inflationModule,
sudoModule,
perpv2Module,
genMsgModule,
// Nibiru modules
spot.NewAppModule(appCodec, app.SpotKeeper, app.AccountKeeper, app.BankKeeper),
stablecoin.NewAppModule(appCodec, app.StablecoinKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper),
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
epochs.NewAppModule(appCodec, app.EpochsKeeper),
perpv2.NewAppModule(appCodec, app.PerpKeeperV2, app.AccountKeeper, app.BankKeeper, app.OracleKeeper),
inflation.NewAppModule(app.InflationKeeper, app.AccountKeeper, *app.stakingKeeper),
sudo.NewAppModule(appCodec, app.SudoKeeper),
genmsg.NewAppModule(app.MsgServiceRouter()),

// ibc
evidence.NewAppModule(app.evidenceKeeper),
Expand All @@ -555,12 +527,13 @@ func (app *NibiruApp) AppModules(
devgas.NewAppModule(
app.DevGasKeeper, app.AccountKeeper,
app.GetSubspace(devgastypes.ModuleName)),

crisis.NewAppModule(&app.crisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)), // always be last to make sure that it checks for all invariants and not only part of them
}
}

// OrderedModuleNames: Module names ordered for the begin and end block hooks
func OrderedModuleNames() []string {
// orderedModuleNames: Module names ordered for the begin and end block hooks
func orderedModuleNames() []string {
return []string{
// --------------------------------------------------------------------
// Cosmos-SDK modules
Expand Down Expand Up @@ -622,22 +595,10 @@ func OrderedModuleNames() []string {
}
}

// GetMaccPerms returns a copy of the module account permissions
//
// NOTE: This is solely to be used for testing purposes.
func GetMaccPerms() map[string][]string {
dupMaccPerms := make(map[string][]string)
for k, v := range maccPerms {
dupMaccPerms[k] = v
}

return dupMaccPerms
}

// BlockedAddresses returns all the app's blocked account addresses.
func BlockedAddresses() map[string]bool {
// blockedAddresses returns all the app's blocked account addresses.
func blockedAddresses() map[string]bool {
modAccAddrs := make(map[string]bool)
for acc := range GetMaccPerms() {
for acc := range maccPerms {
modAccAddrs[authtypes.NewModuleAddress(acc).String()] = true
}

Expand All @@ -647,22 +608,23 @@ func BlockedAddresses() map[string]bool {
return modAccAddrs
}

// InitModuleManager Load all the modules and stores them in the module manager
// initModuleManager Load all the modules and stores them in the module manager
// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
func (app *NibiruApp) InitModuleManager(
func (app *NibiruApp) initModuleManager(
encodingConfig EncodingConfig,
skipGenesisInvariants bool,
) {
app.mm = module.NewManager(
app.AppModules(encodingConfig, skipGenesisInvariants)...,
app.initAppModules(encodingConfig, skipGenesisInvariants)...,
)

// Init module orders for hooks and genesis
moduleNames := OrderedModuleNames()
app.mm.SetOrderBeginBlockers(moduleNames...)
app.mm.SetOrderEndBlockers(moduleNames...)
app.mm.SetOrderInitGenesis(moduleNames...)
orderedModules := orderedModuleNames()
app.mm.SetOrderBeginBlockers(orderedModules...)
app.mm.SetOrderEndBlockers(orderedModules...)
app.mm.SetOrderInitGenesis(orderedModules...)
app.mm.SetOrderExportGenesis(orderedModules...)

// Uncomment if you want to set a custom migration order here.
// app.mm.SetOrderMigrations(custom order)
Expand Down
15 changes: 0 additions & 15 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"github.com/cosmos/cosmos-sdk/x/gov"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/mint"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
"github.com/cosmos/cosmos-sdk/x/staking"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
)
Expand Down Expand Up @@ -79,19 +77,6 @@ func (CrisisModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
return cdc.MustMarshalJSON(genState)
}

// MintModule defines a custom wrapper around the x/mint module's
// AppModuleBasic implementation to provide custom default genesis state.
type MintModule struct {
mint.AppModuleBasic
}

// DefaultGenesis returns custom Nibiru x/mint module genesis state.
func (MintModule) DefaultGenesis(cdc codec.JSONCodec) json.RawMessage {
genState := minttypes.DefaultGenesisState()
genState.Params.MintDenom = BondDenom
return cdc.MustMarshalJSON(genState)
}

// GovModule defines a custom wrapper around the x/gov module's
// AppModuleBasic implementation to provide custom default genesis state.
type GovModule struct {
Expand Down

0 comments on commit d0bc884

Please sign in to comment.