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

chore: sdk 50 basic module manager #607

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
106 changes: 47 additions & 59 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"path/filepath"
"time"

tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

"github.com/neutron-org/neutron/v4/x/dynamicfees"
dynamicfeestypes "github.com/neutron-org/neutron/v4/x/dynamicfees/types"

Expand Down Expand Up @@ -52,9 +54,6 @@ import (

wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/cosmos/cosmos-sdk/runtime"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
tendermint "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint"

"github.com/neutron-org/neutron/v4/docs"

Expand Down Expand Up @@ -106,6 +105,9 @@ import (
"github.com/cosmos/cosmos-sdk/x/crisis"
crisiskeeper "github.com/cosmos/cosmos-sdk/x/crisis/keeper"
crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types"
"github.com/cosmos/cosmos-sdk/x/genutil"
genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
"github.com/cosmos/cosmos-sdk/x/params"
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
Expand Down Expand Up @@ -136,6 +138,7 @@ import (
ibchost "github.com/cosmos/ibc-go/v8/modules/core/exported"
ibckeeper "github.com/cosmos/ibc-go/v8/modules/core/keeper"
ibctesting "github.com/cosmos/ibc-go/v8/testing"

"github.com/spf13/cast"

govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
Expand All @@ -151,7 +154,6 @@ import (
adminmodulecli "github.com/cosmos/admin-module/v2/x/adminmodule/client/cli"
adminmodulekeeper "github.com/cosmos/admin-module/v2/x/adminmodule/keeper"
adminmoduletypes "github.com/cosmos/admin-module/v2/x/adminmodule/types"
govclient "github.com/cosmos/cosmos-sdk/x/gov/client"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"

appparams "github.com/neutron-org/neutron/v4/app/params"
Expand Down Expand Up @@ -230,58 +232,6 @@ var (
// DefaultNodeHome default home directories for the application daemon
DefaultNodeHome string

// ModuleBasics defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration
// and genesis verification.
ModuleBasics = module.NewBasicManager(
auth.AppModuleBasic{},
authzmodule.AppModuleBasic{},
bank.AppModuleBasic{},
capability.AppModuleBasic{},
genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
params.AppModuleBasic{},
crisis.AppModuleBasic{},
slashing.AppModuleBasic{},
feegrantmodule.AppModuleBasic{},
ibc.AppModuleBasic{},
ica.AppModuleBasic{},
tendermint.AppModuleBasic{},
upgrade.AppModuleBasic{},
evidence.AppModuleBasic{},
transferSudo.AppModuleBasic{},
vesting.AppModuleBasic{},
ccvconsumer.AppModuleBasic{},
wasm.AppModuleBasic{},
tokenfactory.AppModuleBasic{},
interchainqueries.AppModuleBasic{},
interchaintxs.AppModuleBasic{},
feerefunder.AppModuleBasic{},
feeburner.AppModuleBasic{},
contractmanager.AppModuleBasic{},
cron.AppModuleBasic{},
adminmodule.NewAppModuleBasic(
govclient.NewProposalHandler(
adminmodulecli.NewSubmitParamChangeProposalTxCmd,
),
govclient.NewProposalHandler(
adminmodulecli.NewCmdSubmitUpgradeProposal,
),
govclient.NewProposalHandler(
adminmodulecli.NewCmdSubmitCancelUpgradeProposal,
),
),
ibchooks.AppModuleBasic{},
packetforward.AppModuleBasic{},
auction.AppModuleBasic{},
globalfee.AppModule{},
feemarket.AppModuleBasic{},
dex.AppModuleBasic{},
ibcswap.AppModuleBasic{},
oracle.AppModuleBasic{},
marketmap.AppModuleBasic{},
dynamicfees.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
Expand Down Expand Up @@ -401,7 +351,8 @@ type App struct {
oracleClient oracleclient.OracleClient

// mm is the module manager
mm *module.Manager
mm *module.Manager
BasicModuleManager module.BasicManager

// sm is the simulation manager
sm *module.SimulationManager
Expand Down Expand Up @@ -464,12 +415,12 @@ func New(
skipUpgradeHeights map[int64]bool,
homePath string,
invCheckPeriod uint,
encodingConfig appparams.EncodingConfig,
appOpts servertypes.AppOptions,
wasmOpts []wasmkeeper.Option,
baseAppOptions ...func(*baseapp.BaseApp),
) *App {
overrideWasmVariables()
encodingConfig := MakeEncodingConfig()

appCodec := encodingConfig.Marshaler
legacyAmino := encodingConfig.Amino
Expand Down Expand Up @@ -954,6 +905,7 @@ func New(
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
tendermint.NewAppModule(),
transferModule,
consumerModule,
icaModule,
Expand All @@ -975,10 +927,37 @@ func New(
marketmapModule,
oracleModule,
auction.NewAppModule(appCodec, app.AuctionKeeper),
genutil.NewAppModule(app.AccountKeeper, app.ConsumerKeeper, app, encodingConfig.TxConfig),
// always be last to make sure that it checks for all invariants and not only part of them
crisis.NewAppModule(&app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
)

// BasicModuleManager defines the module BasicManager is in charge of setting up basic,
// non-dependant module elements, such as codec registration and genesis verification.
// By default it is composed of all the module from the module manager.
// Additionally, app module basics can be overwritten by passing them as argument.
app.BasicModuleManager = module.NewBasicManagerFromManager(
app.mm,
map[string]module.AppModuleBasic{
genutiltypes.ModuleName: genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator),
adminmoduletypes.ModuleName: adminmodule.NewAppModuleBasic(
govclient.NewProposalHandler(
adminmodulecli.NewSubmitParamChangeProposalTxCmd,
),
govclient.NewProposalHandler(
adminmodulecli.NewCmdSubmitUpgradeProposal,
),
govclient.NewProposalHandler(
adminmodulecli.NewCmdSubmitCancelUpgradeProposal,
),
),
// Manually register the transfer module since we dont use a native ibc-go transfer module but a custom implementation
ibctransfertypes.ModuleName: transferSudo.AppModuleBasic{},
},
)
app.BasicModuleManager.RegisterLegacyAminoCodec(encodingConfig.Amino)
app.BasicModuleManager.RegisterInterfaces(encodingConfig.InterfaceRegistry)

app.mm.SetOrderPreBlockers(
upgradetypes.ModuleName,
)
Expand Down Expand Up @@ -1099,6 +1078,7 @@ func New(
ibcswaptypes.ModuleName,
dextypes.ModuleName,
dynamicfeestypes.ModuleName,
genutiltypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -1554,6 +1534,14 @@ func (app *App) AppCodec() codec.Codec {
return app.appCodec
}

func (app *App) InterfaceRegistry() types.InterfaceRegistry {
return app.interfaceRegistry
}

func (app *App) GetConfigurator() module.Configurator {
return app.configurator
}

// GetKey returns the KVStoreKey for the provided store key.
//
// NOTE: This is solely to be used for testing purposes.
Expand Down Expand Up @@ -1592,7 +1580,7 @@ func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig
// Register new tendermint queries routes from grpc-gateway.
cmtservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
app.BasicModuleManager.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)

// Register app's swagger ui
if apiConfig.Swagger {
Expand Down
2 changes: 0 additions & 2 deletions app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,5 @@ func MakeEncodingConfig() params.EncodingConfig {
encodingConfig := params.MakeEncodingConfig()
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
return encodingConfig
}
6 changes: 2 additions & 4 deletions app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"cosmossdk.io/math"

feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"

"github.com/cosmos/cosmos-sdk/codec"
)

var FeeDenom = "untrn"
Expand All @@ -22,8 +20,8 @@ var FeeDenom = "untrn"
type GenesisState map[string]json.RawMessage

// NewDefaultGenesisState generates the default state for the application.
func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState {
genesisState := ModuleBasics.DefaultGenesis(cdc)
func (app *App) NewDefaultGenesisState() GenesisState {
genesisState := app.BasicModuleManager.DefaultGenesis(app.appCodec)

feemarketFeeGenesis := feemarkettypes.GenesisState{
Params: feemarkettypes.Params{
Expand Down
5 changes: 5 additions & 0 deletions app/params/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ func MakeEncodingConfig() EncodingConfig {
if err != nil {
panic(err)
}

if err := reg.SigningContext().Validate(); err != nil {
panic(err)
}

marshaler := codec.NewProtoCodec(reg)
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)

Expand Down
30 changes: 18 additions & 12 deletions cmd/neutrond/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/cosmos/cosmos-sdk/server"
servertypes "github.com/cosmos/cosmos-sdk/server/types"
"github.com/cosmos/cosmos-sdk/testutil/sims"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/version"
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
Expand All @@ -47,8 +49,6 @@ import (
// NewRootCmd creates a new root command for neutrond. It is called once in the
// main function.
func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
encodingConfig := app.MakeEncodingConfig()

// create a temporary application for use in constructing query + tx commands
initAppOptions := viper.New()
tempDir := tempDir()
Expand All @@ -61,10 +61,15 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
nil,
tempDir,
0,
encodingConfig,
initAppOptions,
sims.NewAppOptionsWithFlagHome(app.DefaultNodeHome),
nil,
)
encodingConfig := params.EncodingConfig{
InterfaceRegistry: tempApplication.InterfaceRegistry(),
Marshaler: tempApplication.AppCodec(),
TxConfig: tempApplication.GetTxConfig(),
Amino: tempApplication.LegacyAmino(),
}
defer func() {
if err := tempApplication.Close(); err != nil {
panic(err)
Expand Down Expand Up @@ -113,7 +118,7 @@ func NewRootCmd() (*cobra.Command, params.EncodingConfig) {
},
}

initRootCmd(rootCmd, encodingConfig)
initRootCmd(rootCmd, encodingConfig, tempApplication.BasicModuleManager)
initClientCtx, err := config.ReadDefaultValuesFromDefaultClientConfig(initClientCtx)
if err != nil {
panic(err)
Expand Down Expand Up @@ -144,16 +149,19 @@ func tempDir() string {
return dir
}

func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
func initRootCmd(rootCmd *cobra.Command,
encodingConfig params.EncodingConfig,
moduleBasics module.BasicManager,
) {
debugCmd := debug.Cmd()
debugCmd.AddCommand(genContractAddressCmd())
gentxModule := app.ModuleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)
gentxModule := moduleBasics[genutiltypes.ModuleName].(genutil.AppModuleBasic)

rootCmd.AddCommand(
genutilcli.InitCmd(app.ModuleBasics, app.DefaultNodeHome),
genutilcli.InitCmd(moduleBasics, app.DefaultNodeHome),
genutilcli.CollectGenTxsCmd(banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, gentxModule.GenTxValidator, encodingConfig.TxConfig.SigningContext().ValidatorAddressCodec()),
genutilcli.GenTxCmd(app.ModuleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, encodingConfig.TxConfig.SigningContext().ValidatorAddressCodec()),
genutilcli.ValidateGenesisCmd(app.ModuleBasics),
genutilcli.GenTxCmd(moduleBasics, encodingConfig.TxConfig, banktypes.GenesisBalancesIterator{}, app.DefaultNodeHome, encodingConfig.TxConfig.SigningContext().ValidatorAddressCodec()),
genutilcli.ValidateGenesisCmd(moduleBasics),
AddGenesisAccountCmd(app.DefaultNodeHome),
addGenesisWasmMsgCmd(app.DefaultNodeHome),
tmcli.NewCompletionCmd(rootCmd, true),
Expand Down Expand Up @@ -289,7 +297,6 @@ func (ac appCreator) newApp(
return app.New(logger, db, traceStore, true, skipUpgradeHeights,
homeDir,
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
ac.encCfg,
appOpts,
wasmOpts,
baseapp.SetPruning(pruningOpts),
Expand Down Expand Up @@ -331,7 +338,6 @@ func (ac appCreator) appExport(
map[int64]bool{},
homePath,
cast.ToUint(appOpts.Get(server.FlagInvCheckPeriod)),
ac.encCfg,
appOpts,
emptyWasmOpts,
)
Expand Down
Loading
Loading