From cad3f4fc72a37da5773ba1ff529d08549a6b91d2 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Thu, 3 Oct 2024 10:50:11 +0530 Subject: [PATCH] add todos for BasicManager --- app/app.go | 88 ++++++++-------------- app/config.go | 2 +- app/encoding.go | 2 +- app/genesis.go | 21 ------ app/init_genesis.go | 66 ----------------- app/modules.go | 114 +++++++++++++++++++++++------ tests/simulation/sim/sim_config.go | 2 +- 7 files changed, 124 insertions(+), 171 deletions(-) delete mode 100644 app/genesis.go delete mode 100644 app/init_genesis.go diff --git a/app/app.go b/app/app.go index 3f8c295b31..86955375d7 100644 --- a/app/app.go +++ b/app/app.go @@ -1,6 +1,7 @@ package app import ( + "encoding/json" "io" "net/http" "os" @@ -177,64 +178,33 @@ func getGovProposalHandlers() []govclient.ProposalHandler { return govProposalHandlers } -var ( - ModuleBasics = module.NewBasicManager( - auth.AppModuleBasic{}, - genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), - bank.AppModuleBasic{}, - //capability.AppModuleBasic{}, - staking.AppModuleBasic{}, - distr.AppModuleBasic{}, - gov.NewAppModuleBasic(getGovProposalHandlers()), - params.AppModuleBasic{}, - crisis.AppModuleBasic{}, - slashing.AppModuleBasic{}, - //ibc.AppModuleBasic{}, - //ibctm.AppModuleBasic{}, - upgrade.AppModuleBasic{}, - evidence.AppModuleBasic{}, - //transfer.AppModuleBasic{}, - vesting.AppModuleBasic{}, - consensus.AppModuleBasic{}, - evm.AppModuleBasic{}, - feemarket.AppModuleBasic{}, - authoritymodule.AppModuleBasic{}, - lightclientmodule.AppModuleBasic{}, - crosschainmodule.AppModuleBasic{}, - //ibccrosschain.AppModuleBasic{}, - observermodule.AppModuleBasic{}, - fungiblemodule.AppModuleBasic{}, - emissionsmodule.AppModuleBasic{}, - groupmodule.AppModuleBasic{}, - authzmodule.AppModuleBasic{}, - ) - - // module account permissions - maccPerms = map[string][]string{ - authtypes.FeeCollectorName: nil, - distrtypes.ModuleName: nil, - stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, - stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, - govtypes.ModuleName: {authtypes.Burner}, - //ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - //ibccrosschaintypes.ModuleName: nil, - evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner}, - emissionstypes.ModuleName: nil, - emissionstypes.UndistributedObserverRewardsPool: nil, - emissionstypes.UndistributedTssRewardsPool: nil, - } +type GenesisState map[string]json.RawMessage + +// module account permissions +var maccPerms = map[string][]string{ + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, + //ibctransfertypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + //ibccrosschaintypes.ModuleName: nil, + evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner}, + emissionstypes.ModuleName: nil, + emissionstypes.UndistributedObserverRewardsPool: nil, + emissionstypes.UndistributedTssRewardsPool: nil, +} - // module accounts that are NOT allowed to receive tokens - blockedReceivingModAcc = map[string]bool{ - distrtypes.ModuleName: true, - authtypes.FeeCollectorName: true, - stakingtypes.BondedPoolName: true, - stakingtypes.NotBondedPoolName: true, - govtypes.ModuleName: true, - } -) +// module accounts that are NOT allowed to receive tokens +var blockedReceivingModAcc = map[string]bool{ + distrtypes.ModuleName: true, + authtypes.FeeCollectorName: true, + stakingtypes.BondedPoolName: true, + stakingtypes.NotBondedPoolName: true, + govtypes.ModuleName: true, +} var ( _ runtime.AppI = (*App)(nil) @@ -738,7 +708,7 @@ func New( authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry), ) - app.ModuleBasics = newBasicManagerFromManager(app) + app.ModuleBasics = ModuleBasics // During begin block slashing happens after distr.BeginBlocker so that // there is nothing left over in the validator fee pool, so as to keep the @@ -906,7 +876,7 @@ func (app *App) ModuleAccountAddrs() map[string]bool { return modAccAddrs } -// LegacyAmino returns SimApp's amino codec. +// LegacyAmino returns app's amino codec. // // NOTE: This is solely to be used for testing purposes as it may be desirable // for modules to register their own custom testing types. diff --git a/app/config.go b/app/config.go index 8f50ff8b7b..3aae668605 100644 --- a/app/config.go +++ b/app/config.go @@ -20,7 +20,7 @@ var ( FlagBlockSizeValue int FlagLeanValue bool FlagCommitValue bool - FlagOnOperationValue bool // TODO: Remove in favor of binary search for invariant violation + FlagOnOperationValue bool FlagAllInvariantsValue bool FlagEnabledValue bool diff --git a/app/encoding.go b/app/encoding.go index 2e8c728b0f..755b4ccbae 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -14,7 +14,6 @@ import ( evmenc "github.com/zeta-chain/ethermint/encoding" ethermint "github.com/zeta-chain/ethermint/types" evmtypes "github.com/zeta-chain/ethermint/x/evm/types" - authoritytypes "github.com/zeta-chain/node/x/authority/types" crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" emissionstypes "github.com/zeta-chain/node/x/emissions/types" @@ -28,6 +27,7 @@ func MakeEncodingConfig() ethermint.EncodingConfig { encodingConfig := evmenc.MakeConfig(ModuleBasics) registry := encodingConfig.InterfaceRegistry + // TODO test if we need to register these interfaces again as MakeConfig already registers them cryptocodec.RegisterInterfaces(registry) authtypes.RegisterInterfaces(registry) authz.RegisterInterfaces(registry) diff --git a/app/genesis.go b/app/genesis.go deleted file mode 100644 index 5bf0c1da80..0000000000 --- a/app/genesis.go +++ /dev/null @@ -1,21 +0,0 @@ -package app - -import ( - "encoding/json" - - "github.com/cosmos/cosmos-sdk/codec" -) - -// The genesis state of the blockchain is represented here as a map of raw json -// messages key'd by a identifier string. -// The identifier is used to determine which module genesis information belongs -// to so it may be appropriately routed during init chain. -// Within this application default genesis information is retrieved from -// the ModuleBasicManager which populates json from each BasicModule -// object provided to it during init. -type GenesisState map[string]json.RawMessage - -// NewDefaultGenesisState generates the default state for the application. -func NewDefaultGenesisState(cdc codec.JSONCodec) GenesisState { - return ModuleBasics.DefaultGenesis(cdc) -} diff --git a/app/init_genesis.go b/app/init_genesis.go deleted file mode 100644 index b69972dbf8..0000000000 --- a/app/init_genesis.go +++ /dev/null @@ -1,66 +0,0 @@ -package app - -import ( - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" - "github.com/cosmos/cosmos-sdk/x/authz" - banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" - consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" - crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" - distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" - evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" - genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" - govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - "github.com/cosmos/cosmos-sdk/x/group" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - evmtypes "github.com/zeta-chain/ethermint/x/evm/types" - feemarkettypes "github.com/zeta-chain/ethermint/x/feemarket/types" - - authoritytypes "github.com/zeta-chain/node/x/authority/types" - crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" - emissionsModuleTypes "github.com/zeta-chain/node/x/emissions/types" - fungibleModuleTypes "github.com/zeta-chain/node/x/fungible/types" - lightclienttypes "github.com/zeta-chain/node/x/lightclient/types" - observertypes "github.com/zeta-chain/node/x/observer/types" -) - -// InitGenesisModuleList returns the module list for genesis initialization -// NOTE: Capability module must occur first so that it can initialize any capabilities -// TODO: enable back IBC -// all commented lines in this function are modules related to IBC -// https://github.com/zeta-chain/node/issues/2573 -func InitGenesisModuleList() []string { - return []string{ - //capabilitytypes.ModuleName, - authtypes.ModuleName, - banktypes.ModuleName, - distrtypes.ModuleName, - stakingtypes.ModuleName, - slashingtypes.ModuleName, - govtypes.ModuleName, - //ibcexported.ModuleName, - //ibctransfertypes.ModuleName, - evmtypes.ModuleName, - feemarkettypes.ModuleName, - paramstypes.ModuleName, - group.ModuleName, - genutiltypes.ModuleName, - upgradetypes.ModuleName, - evidencetypes.ModuleName, - vestingtypes.ModuleName, - observertypes.ModuleName, - crosschaintypes.ModuleName, - //ibccrosschaintypes.ModuleName, - fungibleModuleTypes.ModuleName, - emissionsModuleTypes.ModuleName, - authz.ModuleName, - authoritytypes.ModuleName, - lightclienttypes.ModuleName, - consensusparamtypes.ModuleName, - // NOTE: crisis module must go at the end to check for invariants on each module - crisistypes.ModuleName, - } -} diff --git a/app/modules.go b/app/modules.go index c94872305b..b041cc0d1a 100644 --- a/app/modules.go +++ b/app/modules.go @@ -1,59 +1,129 @@ package app import ( - "fmt" - "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/types/module" "github.com/cosmos/cosmos-sdk/x/auth" authsims "github.com/cosmos/cosmos-sdk/x/auth/simulation" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + "github.com/cosmos/cosmos-sdk/x/auth/vesting" + vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types" + "github.com/cosmos/cosmos-sdk/x/authz" authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" "github.com/cosmos/cosmos-sdk/x/bank" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/cosmos/cosmos-sdk/x/consensus" + consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types" + "github.com/cosmos/cosmos-sdk/x/crisis" + crisistypes "github.com/cosmos/cosmos-sdk/x/crisis/types" distr "github.com/cosmos/cosmos-sdk/x/distribution" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" "github.com/cosmos/cosmos-sdk/x/evidence" + evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" "github.com/cosmos/cosmos-sdk/x/genutil" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" "github.com/cosmos/cosmos-sdk/x/gov" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" + "github.com/cosmos/cosmos-sdk/x/group" groupmodule "github.com/cosmos/cosmos-sdk/x/group/module" "github.com/cosmos/cosmos-sdk/x/params" + paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/cosmos/cosmos-sdk/x/slashing" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "github.com/cosmos/cosmos-sdk/x/upgrade" + upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" "github.com/zeta-chain/ethermint/x/evm" evmtypes "github.com/zeta-chain/ethermint/x/evm/types" + "github.com/zeta-chain/ethermint/x/feemarket" + feemarkettypes "github.com/zeta-chain/ethermint/x/feemarket/types" + authoritymodule "github.com/zeta-chain/node/x/authority" + authoritytypes "github.com/zeta-chain/node/x/authority/types" + crosschainmodule "github.com/zeta-chain/node/x/crosschain" + crosschaintypes "github.com/zeta-chain/node/x/crosschain/types" + emissionsmodule "github.com/zeta-chain/node/x/emissions" + emissionsModuleTypes "github.com/zeta-chain/node/x/emissions/types" + fungiblemodule "github.com/zeta-chain/node/x/fungible" + fungibleModuleTypes "github.com/zeta-chain/node/x/fungible/types" + lightclientmodule "github.com/zeta-chain/node/x/lightclient" + lightclienttypes "github.com/zeta-chain/node/x/lightclient/types" + observermodule "github.com/zeta-chain/node/x/observer" + observertypes "github.com/zeta-chain/node/x/observer/types" ) // ModuleBasics defines the module BasicManager that is in charge of setting up basic, // non-dependant module elements, such as codec registration // and genesis verification. -func newBasicManagerFromManager(app *App) module.BasicManager { - moduleBasics := make([]module.AppModuleBasic, 0) - for _, m := range app.mm.Modules { - m, ok := m.(module.AppModuleBasic) - if !ok { - fmt.Printf("module %s is not an instance of module.AppModuleBasic\n", m) - continue - } - if m.Name() == govtypes.ModuleName { - m = gov.NewAppModuleBasic(getGovProposalHandlers()) - } - if m.Name() == genutiltypes.ModuleName { - m = genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator) - } +// TODO: Use app.mm to create the basic manager instead +var ModuleBasics = module.NewBasicManager( + auth.AppModuleBasic{}, + genutil.NewAppModuleBasic(genutiltypes.DefaultMessageValidator), + bank.AppModuleBasic{}, + //capability.AppModuleBasic{}, + staking.AppModuleBasic{}, + distr.AppModuleBasic{}, + gov.NewAppModuleBasic(getGovProposalHandlers()), + params.AppModuleBasic{}, + crisis.AppModuleBasic{}, + slashing.AppModuleBasic{}, + //ibc.AppModuleBasic{}, + //ibctm.AppModuleBasic{}, + upgrade.AppModuleBasic{}, + evidence.AppModuleBasic{}, + //transfer.AppModuleBasic{}, + vesting.AppModuleBasic{}, + consensus.AppModuleBasic{}, + evm.AppModuleBasic{}, + feemarket.AppModuleBasic{}, + authoritymodule.AppModuleBasic{}, + lightclientmodule.AppModuleBasic{}, + crosschainmodule.AppModuleBasic{}, + //ibccrosschain.AppModuleBasic{}, + observermodule.AppModuleBasic{}, + fungiblemodule.AppModuleBasic{}, + emissionsmodule.AppModuleBasic{}, + groupmodule.AppModuleBasic{}, + authzmodule.AppModuleBasic{}, +) - moduleBasics = append(moduleBasics, m) +// InitGenesisModuleList returns the module list for genesis initialization +// NOTE: Capability module must occur first so that it can initialize any capabilities +// TODO: enable back IBC +// all commented lines in this function are modules related to IBC +// https://github.com/zeta-chain/node/issues/2573 +func InitGenesisModuleList() []string { + return []string{ + //capabilitytypes.ModuleName, + authtypes.ModuleName, + banktypes.ModuleName, + distrtypes.ModuleName, + stakingtypes.ModuleName, + slashingtypes.ModuleName, + govtypes.ModuleName, + //ibcexported.ModuleName, + //ibctransfertypes.ModuleName, + evmtypes.ModuleName, + feemarkettypes.ModuleName, + paramstypes.ModuleName, + group.ModuleName, + genutiltypes.ModuleName, + upgradetypes.ModuleName, + evidencetypes.ModuleName, + vestingtypes.ModuleName, + observertypes.ModuleName, + crosschaintypes.ModuleName, + //ibccrosschaintypes.ModuleName, + fungibleModuleTypes.ModuleName, + emissionsModuleTypes.ModuleName, + authz.ModuleName, + authoritytypes.ModuleName, + lightclienttypes.ModuleName, + consensusparamtypes.ModuleName, + // NOTE: crisis module must go at the end to check for invariants on each module + crisistypes.ModuleName, } - basicManager := module.NewBasicManager(moduleBasics...) - //basicManager.RegisterLegacyAminoCodec(app.cdc) - basicManager.RegisterInterfaces(app.interfaceRegistry) - - return basicManager } func simulationModules( diff --git a/tests/simulation/sim/sim_config.go b/tests/simulation/sim/sim_config.go index 98d2ffb6d9..915a77dd40 100644 --- a/tests/simulation/sim/sim_config.go +++ b/tests/simulation/sim/sim_config.go @@ -20,7 +20,7 @@ var ( FlagBlockSizeValue int FlagLeanValue bool FlagCommitValue bool - FlagOnOperationValue bool // TODO: Remove in favor of binary search for invariant violation + FlagOnOperationValue bool FlagAllInvariantsValue bool FlagEnabledValue bool