Skip to content

Commit

Permalink
fix: keepers, genesis and remove intertx
Browse files Browse the repository at this point in the history
  • Loading branch information
emidev98 committed Aug 18, 2023
1 parent 79788b0 commit 39bc7f2
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 113 deletions.
85 changes: 43 additions & 42 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import (
mintkeeper "github.com/cosmos/cosmos-sdk/x/mint/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"

consensus "github.com/cosmos/cosmos-sdk/x/consensus"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
consensusparamtypes "github.com/cosmos/cosmos-sdk/x/consensus/types"

Expand All @@ -98,7 +99,6 @@ import (
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

ica "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts"
// https://github.com/cosmos/interchain-accounts-demo
icacontroller "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller"
icacontrollerkeeper "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
Expand All @@ -124,10 +124,6 @@ import (
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
"github.com/strangelove-ventures/packet-forward-middleware/v7/router"

intertx "github.com/cosmos/interchain-accounts/x/inter-tx"
intertxkeeper "github.com/cosmos/interchain-accounts/x/inter-tx/keeper"
intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"

routerkeeper "github.com/strangelove-ventures/packet-forward-middleware/v7/router/keeper"
routertypes "github.com/strangelove-ventures/packet-forward-middleware/v7/router/types"

Expand All @@ -139,7 +135,6 @@ import (
wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
"github.com/prometheus/client_golang/prometheus"

// Token Factory for sdk 46
"github.com/CosmWasm/wasmd/x/tokenfactory"
tokenfactorybindings "github.com/CosmWasm/wasmd/x/tokenfactory/bindings"
tokenfactorykeeper "github.com/CosmWasm/wasmd/x/tokenfactory/keeper"
Expand Down Expand Up @@ -252,12 +247,12 @@ var (
vesting.AppModuleBasic{},
ica.AppModuleBasic{},
ibcfee.AppModuleBasic{},
intertx.AppModuleBasic{},
router.AppModuleBasic{},
authzmodule.AppModuleBasic{},
tokenfactory.AppModuleBasic{},
ibchooks.AppModuleBasic{},
wasm.AppModuleBasic{},
consensus.AppModuleBasic{},
alliance.AppModuleBasic{},
)

Expand Down Expand Up @@ -313,11 +308,11 @@ type TerraApp struct {
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper stakingkeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
MintKeeper mintkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper *govkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper *crisiskeeper.Keeper
UpgradeKeeper *upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
Expand All @@ -329,7 +324,6 @@ type TerraApp struct {
FeeGrantKeeper feegrantkeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
InterTxKeeper intertxkeeper.Keeper
IBCFeeKeeper ibcfeekeeper.Keeper
RouterKeeper routerkeeper.Keeper
TokenFactoryKeeper tokenfactorykeeper.Keeper
Expand All @@ -346,7 +340,6 @@ type TerraApp struct {
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedInterTxKeeper capabilitykeeper.ScopedKeeper

wasmKeeper wasm.Keeper
scopedWasmKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -382,13 +375,13 @@ func NewTerraApp(
bApp.SetInterfaceRegistry(interfaceRegistry)

keys := sdk.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey,
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, crisistypes.StoreKey,
minttypes.StoreKey, distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, ibcexported.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey,
intertxtypes.StoreKey, authzkeeper.StoreKey, feegrant.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, routertypes.StoreKey, tokenfactorytypes.StoreKey, wasm.StoreKey,
ibcfeetypes.StoreKey, ibchookstypes.StoreKey, alliancetypes.StoreKey,
authzkeeper.StoreKey, feegrant.StoreKey, icahosttypes.StoreKey,
icacontrollertypes.StoreKey, routertypes.StoreKey, consensusparamtypes.StoreKey, tokenfactorytypes.StoreKey,
wasm.StoreKey, ibcfeetypes.StoreKey, ibchookstypes.StoreKey, alliancetypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -416,7 +409,6 @@ func NewTerraApp(
// grant capabilities for the ibc and ibc-transfer modules
scopedIBCKeeper := app.CapabilityKeeper.ScopeToModule(ibcexported.ModuleName)
scopedTransferKeeper := app.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
scopedInterTxKeeper := app.CapabilityKeeper.ScopeToModule(intertxtypes.ModuleName)
scopedICAControllerKeeper := app.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
scopedICAHostKeeper := app.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)

Expand All @@ -438,7 +430,7 @@ func NewTerraApp(
app.ModuleAccountAddrs(),
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
stakingKeeper := stakingkeeper.NewKeeper(
app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
keys[stakingtypes.StoreKey],
app.AccountKeeper,
Expand All @@ -449,7 +441,7 @@ func NewTerraApp(
app.MintKeeper = mintkeeper.NewKeeper(
appCodec,
keys[minttypes.StoreKey],
stakingKeeper,
app.StakingKeeper,
app.AccountKeeper,
app.BankKeeper,
authtypes.FeeCollectorName,
Expand All @@ -460,15 +452,15 @@ func NewTerraApp(
keys[distrtypes.StoreKey],
app.AccountKeeper,
app.BankKeeper,
stakingKeeper,
app.StakingKeeper,
authtypes.FeeCollectorName,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec,
app.LegacyAmino(),
keys[slashingtypes.StoreKey],
stakingKeeper,
app.StakingKeeper,
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)
app.CrisisKeeper = crisiskeeper.NewKeeper(
Expand Down Expand Up @@ -498,11 +490,11 @@ func NewTerraApp(
app.GetSubspace(alliancetypes.ModuleName),
app.AccountKeeper,
app.BankKeeper,
&app.StakingKeeper,
app.StakingKeeper,
app.DistrKeeper,
authtypes.FeeCollectorName,
)
app.BankKeeper.RegisterKeepers(app.AllianceKeeper, stakingKeeper)
app.BankKeeper.RegisterKeepers(app.AllianceKeeper, app.StakingKeeper)

// register the staking hooks
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
Expand All @@ -525,7 +517,12 @@ func NewTerraApp(

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibcexported.StoreKey], app.GetSubspace(ibcexported.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper,
appCodec,
keys[ibcexported.StoreKey],
app.GetSubspace(ibcexported.ModuleName),
app.StakingKeeper,
app.UpgradeKeeper,
scopedIBCKeeper,
)

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
Expand Down Expand Up @@ -593,11 +590,10 @@ func NewTerraApp(
app.MsgServiceRouter(),
)

app.InterTxKeeper = intertxkeeper.NewKeeper(appCodec, keys[intertxtypes.StoreKey], app.ICAControllerKeeper, scopedInterTxKeeper)
interTxIBCModule := intertx.NewIBCModule(app.InterTxKeeper)
var icaControllerStack porttypes.IBCModule
icaControllerStack = icacontroller.NewIBCMiddleware(icaControllerStack, app.ICAControllerKeeper)
icaControllerStack = ibcfee.NewIBCMiddleware(icaControllerStack, app.IBCFeeKeeper)

icaControllerIBCModule := icacontroller.NewIBCMiddleware(interTxIBCModule, app.ICAControllerKeeper)
icaControllerStack := ibcfee.NewIBCMiddleware(icaControllerIBCModule, app.IBCFeeKeeper)
icaHostIBCModule := icahost.NewIBCModule(app.ICAHostKeeper)
icaHostStack := ibcfee.NewIBCMiddleware(icaHostIBCModule, app.IBCFeeKeeper)

Expand All @@ -614,7 +610,7 @@ func NewTerraApp(

// Create evidence Keeper for to register the IBC light client misbehaviour evidence route
evidenceKeeper := evidencekeeper.NewKeeper(
appCodec, keys[evidencetypes.StoreKey], &app.StakingKeeper, app.SlashingKeeper,
appCodec, keys[evidencetypes.StoreKey], app.StakingKeeper, app.SlashingKeeper,
)
// If evidence needs to be handled for the app, set routes in router here and seal
app.EvidenceKeeper = *evidenceKeeper
Expand Down Expand Up @@ -660,20 +656,27 @@ func NewTerraApp(

// Create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter().
AddRoute(intertxtypes.ModuleName, icaControllerStack).
AddRoute(icacontrollertypes.SubModuleName, icaControllerStack).
AddRoute(icahosttypes.SubModuleName, icaHostStack).
AddRoute(ibctransfertypes.ModuleName, hooksTransferStack).
AddRoute(wasm.ModuleName, wasmStack)

app.IBCKeeper.SetRouter(ibcRouter)

app.GovKeeper = govkeeper.NewKeeper(
govKeeper := govkeeper.NewKeeper(
appCodec, keys[govtypes.StoreKey], app.AccountKeeper,
app.BankKeeper, stakingKeeper,
app.BankKeeper, app.StakingKeeper,
app.MsgServiceRouter(), govtypes.DefaultConfig(), authtypes.NewModuleAddress(govtypes.ModuleName).String(),
)

// Set legacy router for backwards compatibility with gov v1beta1
govKeeper.SetLegacyRouter(govRouter)
app.GovKeeper = *govKeeper.SetHooks(
govtypes.NewMultiGovHooks(
// register the governance hooks
),
)

/**** Module Options ****/

// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
Expand All @@ -694,11 +697,12 @@ func NewTerraApp(
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.GetSubspace(crisistypes.ModuleName)),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
gov.NewAppModule(appCodec, app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
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)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
consensus.NewAppModule(appCodec, app.ConsensusParamsKeeper),
upgrade.NewAppModule(app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
Expand All @@ -707,7 +711,6 @@ func NewTerraApp(
ibctransfer.NewAppModule(app.TransferKeeper),
ibcfee.NewAppModule(app.IBCFeeKeeper),
ica.NewAppModule(&app.ICAControllerKeeper, &app.ICAHostKeeper),
intertx.NewAppModule(appCodec, app.InterTxKeeper),
router.NewAppModule(&app.RouterKeeper),
wasm.NewAppModule(appCodec, &app.wasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.MsgServiceRouter(), app.GetSubspace(wasmtypes.ModuleName)),
ibchooks.NewAppModule(app.AccountKeeper),
Expand Down Expand Up @@ -741,12 +744,12 @@ func NewTerraApp(
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
intertxtypes.ModuleName,
routertypes.ModuleName,
ibchookstypes.ModuleName,
wasm.ModuleName,
tokenfactorytypes.ModuleName,
alliancetypes.ModuleName,
consensusparamtypes.ModuleName,
)

app.mm.SetOrderEndBlockers(
Expand All @@ -771,12 +774,12 @@ func NewTerraApp(
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
intertxtypes.ModuleName,
routertypes.ModuleName,
ibchookstypes.ModuleName,
wasm.ModuleName,
tokenfactorytypes.ModuleName,
alliancetypes.ModuleName,
consensusparamtypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand Down Expand Up @@ -805,16 +808,17 @@ func NewTerraApp(
ibctransfertypes.ModuleName,
icatypes.ModuleName,
ibcfeetypes.ModuleName,
intertxtypes.ModuleName,
routertypes.ModuleName,
tokenfactorytypes.ModuleName,
ibchookstypes.ModuleName,
wasm.ModuleName,
alliancetypes.ModuleName,
consensusparamtypes.ModuleName,
)

app.mm.RegisterInvariants(app.CrisisKeeper)
app.mm.RegisterServices(app.configurator)

// initialize stores
app.MountKVStores(keys)
app.MountTransientStores(tkeys)
Expand Down Expand Up @@ -856,7 +860,6 @@ func NewTerraApp(
if upgradeInfo.Name == terraappconfig.Upgrade2_3_0 && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := storetypes.StoreUpgrades{
Added: []string{
intertxtypes.StoreKey,
icacontrollertypes.StoreKey,
tokenfactorytypes.StoreKey,
ibcfeetypes.StoreKey,
Expand Down Expand Up @@ -887,7 +890,6 @@ func NewTerraApp(
app.ScopedICAControllerKeeper = scopedICAControllerKeeper
app.ScopedICAHostKeeper = scopedICAHostKeeper
app.scopedWasmKeeper = scopedWasmKeeper
app.ScopedInterTxKeeper = scopedInterTxKeeper

return app
}
Expand Down Expand Up @@ -1183,9 +1185,9 @@ func (app *TerraApp) SimulationManager() *module.SimulationManager {
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.GetSubspace(banktypes.ModuleName)),
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)),
gov.NewAppModule(appCodec, &app.GovKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(govtypes.ModuleName)),
mint.NewAppModule(appCodec, app.MintKeeper, app.AccountKeeper, nil, app.GetSubspace(minttypes.ModuleName)),
staking.NewAppModule(appCodec, &app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
distr.NewAppModule(appCodec, app.DistrKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(distrtypes.ModuleName)),
slashing.NewAppModule(appCodec, app.SlashingKeeper, app.AccountKeeper, app.BankKeeper, app.StakingKeeper, app.GetSubspace(stakingtypes.ModuleName)),
params.NewAppModule(app.ParamsKeeper),
Expand All @@ -1199,7 +1201,6 @@ func (app *TerraApp) SimulationManager() *module.SimulationManager {
tokenfactory.NewAppModule(app.TokenFactoryKeeper, app.AccountKeeper, app.BankKeeper),
alliance.NewAppModule(appCodec, app.AllianceKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
// does not implement simulation
// intertx.NewAppModule(appCodec, app.InterTxKeeper),
// ibchooks.NewAppModule(app.AccountKeeper),
)

Expand Down
2 changes: 1 addition & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (app *TerraApp) ExportAppStateAndValidators(
return servertypes.ExportedApp{}, err
}

validators, err := staking.WriteValidators(ctx, &app.StakingKeeper)
validators, err := staking.WriteValidators(ctx, app.StakingKeeper)
if err != nil {
return servertypes.ExportedApp{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (genState GenesisState) ConfigureBondDenom(cdc codec.JSONCodec, bondDenom s

var govGenState govtypesv1.GenesisState
cdc.MustUnmarshalJSON(genState[govtypes.ModuleName], &govGenState)
govGenState.DepositParams.MinDeposit[0].Denom = bondDenom
govGenState.Params.MinDeposit[0].Denom = bondDenom
genState[govtypes.ModuleName] = cdc.MustMarshalJSON(&govGenState)

var mintGenState minttypes.GenesisState
Expand Down
Loading

0 comments on commit 39bc7f2

Please sign in to comment.