Skip to content

Commit

Permalink
add todos for BasicManager
Browse files Browse the repository at this point in the history
  • Loading branch information
kingpinXD committed Oct 3, 2024
1 parent 73fbcf5 commit cad3f4f
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 171 deletions.
88 changes: 29 additions & 59 deletions app/app.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app

import (
"encoding/json"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion app/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand Down
21 changes: 0 additions & 21 deletions app/genesis.go

This file was deleted.

66 changes: 0 additions & 66 deletions app/init_genesis.go

This file was deleted.

114 changes: 92 additions & 22 deletions app/modules.go
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
2 changes: 1 addition & 1 deletion tests/simulation/sim/sim_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cad3f4f

Please sign in to comment.