From 449445007b8a7bcad2bb5f78ddb6c9e039b6d7ef Mon Sep 17 00:00:00 2001 From: Paul Chen Date: Tue, 25 Jun 2024 17:43:39 +0800 Subject: [PATCH] fix: fix action module and simapp --- go.mod | 4 +--- modules/actions/module.go | 28 ++++++++++++++---------- modules/registrar.go | 2 +- modules/types/sources.go | 16 ++++---------- utils/simapp/app.go | 46 ++++++++++++++++++++++++++++++--------- 5 files changed, 58 insertions(+), 38 deletions(-) diff --git a/go.mod b/go.mod index db4ef54d9..1c1332a84 100644 --- a/go.mod +++ b/go.mod @@ -2,9 +2,8 @@ module github.com/forbole/callisto/v4 go 1.21 -toolchain go1.22.3 - require ( + cosmossdk.io/log v1.3.1 cosmossdk.io/math v1.3.0 cosmossdk.io/store v1.1.0 cosmossdk.io/x/evidence v0.1.1 @@ -41,7 +40,6 @@ require ( cosmossdk.io/core v0.11.0 // indirect cosmossdk.io/depinject v1.0.0-alpha.4 // indirect cosmossdk.io/errors v1.0.1 // indirect - cosmossdk.io/log v1.3.1 // indirect cosmossdk.io/x/tx v0.13.3 // indirect filippo.io/edwards25519 v1.0.0 // indirect github.com/4meepo/tagalign v1.3.3 // indirect diff --git a/modules/actions/module.go b/modules/actions/module.go index c5231bc00..51825606e 100644 --- a/modules/actions/module.go +++ b/modules/actions/module.go @@ -1,6 +1,8 @@ package actions import ( + "fmt" + "github.com/cosmos/cosmos-sdk/codec" authtx "github.com/cosmos/cosmos-sdk/x/auth/tx" "github.com/forbole/juno/v6/modules" @@ -8,6 +10,7 @@ import ( "github.com/forbole/juno/v6/node/builder" nodeconfig "github.com/forbole/juno/v6/node/config" "github.com/forbole/juno/v6/types/config" + "github.com/rs/zerolog/log" modulestypes "github.com/forbole/callisto/v4/modules/types" ) @@ -27,7 +30,7 @@ type Module struct { sources *modulestypes.Sources } -func NewModule(cfg config.Config, cdc codec.Codec) *Module { +func NewModule(cfg config.Config, cdc codec.Codec, sources *modulestypes.Sources) *Module { bz, err := cfg.GetBytes() if err != nil { panic(err) @@ -43,22 +46,23 @@ func NewModule(cfg config.Config, cdc codec.Codec) *Module { nodeCfg = nodeconfig.NewConfig(nodeconfig.TypeRemote, actionsCfg.Node) } - // Build the node - txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) - junoNode, err := builder.BuildNode(nodeCfg, txConfig, cdc) - if err != nil { - panic(err) - } + var node node.Node + if cfg.Node.Type == nodeconfig.TypeLocal { + log.Err(fmt.Errorf("local node is not supported for actions module")) + } else { + // Build the node + txConfig := authtx.NewTxConfig(cdc, authtx.DefaultSignModes) + junoNode, err := builder.BuildNode(nodeCfg, txConfig, cdc) + if err != nil { + panic(err) + } - // Build the sources - sources, err := modulestypes.BuildSources(nodeCfg, cdc) - if err != nil { - panic(err) + node = junoNode } return &Module{ cfg: actionsCfg, - node: junoNode, + node: node, sources: sources, } } diff --git a/modules/registrar.go b/modules/registrar.go index da8b68237..69f8c3aff 100644 --- a/modules/registrar.go +++ b/modules/registrar.go @@ -77,7 +77,7 @@ func (r *Registrar) BuildModules(ctx registrar.Context) jmodules.Modules { panic(err) } - actionsModule := actions.NewModule(ctx.JunoConfig, r.cdc) + actionsModule := actions.NewModule(ctx.JunoConfig, r.cdc, sources) authModule := auth.NewModule(r.parser, r.cdc, db) bankModule := bank.NewModule(r.parser, sources.BankSource, r.cdc, db) consensusModule := consensus.NewModule(db) diff --git a/modules/types/sources.go b/modules/types/sources.go index 602f86cdf..6a404b085 100644 --- a/modules/types/sources.go +++ b/modules/types/sources.go @@ -7,6 +7,7 @@ import ( "github.com/cosmos/cosmos-sdk/codec" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1" @@ -23,6 +24,7 @@ import ( localbanksource "github.com/forbole/callisto/v4/modules/bank/source/local" remotebanksource "github.com/forbole/callisto/v4/modules/bank/source/remote" distrsource "github.com/forbole/callisto/v4/modules/distribution/source" + localdistrsource "github.com/forbole/callisto/v4/modules/distribution/source/local" remotedistrsource "github.com/forbole/callisto/v4/modules/distribution/source/remote" govsource "github.com/forbole/callisto/v4/modules/gov/source" localgovsource "github.com/forbole/callisto/v4/modules/gov/source/local" @@ -69,8 +71,8 @@ func buildLocalSources(cfg *local.Details, cdc codec.Codec) (*Sources, error) { app := simapp.NewSimApp(cdc) sources := &Sources{ - BankSource: localbanksource.NewSource(source, banktypes.QueryServer(app.BankKeeper)), - // DistrSource: localdistrsource.NewSource(source, distrtypes.QueryServer(app.DistrKeeper)), + BankSource: localbanksource.NewSource(source, banktypes.QueryServer(app.BankKeeper)), + DistrSource: localdistrsource.NewSource(source, distrkeeper.NewQuerier(app.DistrKeeper)), GovSource: localgovsource.NewSource(source, govkeeper.NewQueryServer(&app.GovKeeper)), MintSource: localmintsource.NewSource(source, mintkeeper.NewQueryServerImpl(app.MintKeeper)), SlashingSource: localslashingsource.NewSource(source, slashingtypes.QueryServer(app.SlashingKeeper)), @@ -83,16 +85,6 @@ func buildLocalSources(cfg *local.Details, cdc codec.Codec) (*Sources, error) { return nil, err } - err = source.MountTransientStores(app, "tkeys") - if err != nil { - return nil, err - } - - err = source.MountMemoryStores(app, "memKeys") - if err != nil { - return nil, err - } - err = source.InitStores() if err != nil { return nil, err diff --git a/utils/simapp/app.go b/utils/simapp/app.go index cc006c1ab..273a3926f 100644 --- a/utils/simapp/app.go +++ b/utils/simapp/app.go @@ -4,6 +4,7 @@ package simapp import ( storetypes "cosmossdk.io/store/types" + "cosmossdk.io/log" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/runtime" sdk "github.com/cosmos/cosmos-sdk/types" @@ -12,27 +13,37 @@ import ( authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + distrkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper" + distrtypes "github.com/cosmos/cosmos-sdk/x/distribution/types" govkeeper "github.com/cosmos/cosmos-sdk/x/gov/keeper" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - paramstypes "github.com/cosmos/cosmos-sdk/x/params/types" slashingkeeper "github.com/cosmos/cosmos-sdk/x/slashing/keeper" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) +var maccPerms = map[string][]string{ + authtypes.FeeCollectorName: nil, + distrtypes.ModuleName: nil, + minttypes.ModuleName: {authtypes.Minter}, + stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking}, + stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking}, + govtypes.ModuleName: {authtypes.Burner}, +} + type SimApp struct { // keys to access the substores - keys map[string]*storetypes.KVStoreKey - tkeys map[string]*storetypes.TransientStoreKey + keys map[string]*storetypes.KVStoreKey // keepers BankKeeper bankkeeper.BaseKeeper StakingKeeper *stakingkeeper.Keeper SlashingKeeper slashingkeeper.Keeper MintKeeper mintkeeper.Keeper + DistrKeeper distrkeeper.Keeper GovKeeper govkeeper.Keeper } @@ -44,26 +55,41 @@ func NewSimApp(cdc codec.Codec) *SimApp { minttypes.StoreKey, slashingtypes.StoreKey, govtypes.StoreKey, + distrtypes.StoreKey, ) - tkeys := storetypes.NewTransientStoreKeys(paramstypes.TStoreKey) app := &SimApp{ - keys: keys, - tkeys: tkeys, + keys: keys, } - accountKeeper := authkeeper.NewAccountKeeper(cdc, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, nil, authcodec.NewBech32Codec(sdk.Bech32MainPrefix), sdk.Bech32MainPrefix, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + accountKeeper := authkeeper.NewAccountKeeper(cdc, runtime.NewKVStoreService(keys[authtypes.StoreKey]), authtypes.ProtoBaseAccount, maccPerms, authcodec.NewBech32Codec(sdk.GetConfig().GetBech32AccountAddrPrefix()), sdk.GetConfig().GetBech32AccountAddrPrefix(), authtypes.NewModuleAddress(govtypes.ModuleName).String()) + + app.BankKeeper = bankkeeper.NewBaseKeeper( + cdc, + runtime.NewKVStoreService(keys[banktypes.StoreKey]), + accountKeeper, + nil, + authtypes.NewModuleAddress(govtypes.ModuleName).String(), + log.NewNopLogger(), + ) + app.DistrKeeper = distrkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[distrtypes.StoreKey]), accountKeeper, app.BankKeeper, app.StakingKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.StakingKeeper = stakingkeeper.NewKeeper( - cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr), authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), + cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, app.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ValidatorAddrPrefix()), authcodec.NewBech32Codec(sdk.GetConfig().GetBech32ConsensusAddrPrefix()), ) + app.MintKeeper = mintkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[minttypes.StoreKey]), app.StakingKeeper, accountKeeper, app.BankKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.SlashingKeeper = slashingkeeper.NewKeeper( cdc, nil, runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) - app.StakingKeeper.SetHooks( - stakingtypes.NewMultiStakingHooks(app.SlashingKeeper.Hooks()), + govConfig := govtypes.DefaultConfig() + govKeeper := govkeeper.NewKeeper( + cdc, runtime.NewKVStoreService(keys[govtypes.StoreKey]), accountKeeper, app.BankKeeper, + app.StakingKeeper, app.DistrKeeper, nil, govConfig, authtypes.NewModuleAddress(govtypes.ModuleName).String(), ) + app.GovKeeper = *govKeeper return app }