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

fix: correct ica wiring and update pfm fixes for v8 upgrade #2008

Merged
merged 15 commits into from
Jan 16, 2023
85 changes: 40 additions & 45 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ import (
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
ica "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts"
icacontrollerkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
icahost "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host"
icahostkeeper "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/keeper"
icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
Expand Down Expand Up @@ -85,14 +83,13 @@ type AppKeepers struct {
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
// IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
IBCKeeper *ibckeeper.Keeper
ICAControllerKeeper icacontrollerkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
LiquidityKeeper liquiditykeeper.Keeper
IBCKeeper *ibckeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
TransferKeeper ibctransferkeeper.Keeper
FeeGrantKeeper feegrantkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
LiquidityKeeper liquiditykeeper.Keeper

RouterKeeper routerkeeper.Keeper

Expand All @@ -102,10 +99,9 @@ type AppKeepers struct {
RouterModule router.AppModule

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAControllerKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
ScopedTransferKeeper capabilitykeeper.ScopedKeeper
ScopedICAHostKeeper capabilitykeeper.ScopedKeeper
}

func NewAppKeeper(
Expand Down Expand Up @@ -147,7 +143,6 @@ func NewAppKeeper(
appKeepers.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, appKeepers.keys[capabilitytypes.StoreKey], appKeepers.memKeys[capabilitytypes.MemStoreKey])
appKeepers.ScopedIBCKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibchost.ModuleName)
appKeepers.ScopedTransferKeeper = appKeepers.CapabilityKeeper.ScopeToModule(ibctransfertypes.ModuleName)
appKeepers.ScopedICAControllerKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icacontrollertypes.SubModuleName)
appKeepers.ScopedICAHostKeeper = appKeepers.CapabilityKeeper.ScopeToModule(icahosttypes.SubModuleName)

appKeepers.CapabilityKeeper.Seal()
Expand Down Expand Up @@ -277,26 +272,33 @@ func NewAppKeeper(
govRouter,
)

// RouterKeeper must be created before TransferKeeper
appKeepers.RouterKeeper = *routerkeeper.NewKeeper(
appCodec, appKeepers.keys[routertypes.StoreKey],
appKeepers.GetSubspace(routertypes.ModuleName),
appKeepers.TransferKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
)

appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec,
appKeepers.keys[ibctransfertypes.StoreKey],
appKeepers.GetSubspace(ibctransfertypes.ModuleName),
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.RouterKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
&appKeepers.IBCKeeper.PortKeeper,
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.ScopedTransferKeeper,
)
appKeepers.TransferModule = transfer.NewAppModule(appKeepers.TransferKeeper)
transferIBCModule := transfer.NewIBCModule(appKeepers.TransferKeeper)

appKeepers.ICAControllerKeeper = icacontrollerkeeper.NewKeeper(
appCodec, appKeepers.keys[icacontrollertypes.StoreKey], appKeepers.GetSubspace(icacontrollertypes.SubModuleName),
appKeepers.IBCKeeper.ChannelKeeper, // may be replaced with middleware such as ics29 fee
appKeepers.IBCKeeper.ChannelKeeper, &appKeepers.IBCKeeper.PortKeeper,
appKeepers.ScopedICAControllerKeeper, bApp.MsgServiceRouter(),
)
appKeepers.RouterKeeper.SetTransferKeeper(appKeepers.TransferKeeper)

appKeepers.TransferModule = transfer.NewAppModule(appKeepers.TransferKeeper)

appKeepers.ICAHostKeeper = icahostkeeper.NewKeeper(
appCodec, appKeepers.keys[icahosttypes.StoreKey],
Expand All @@ -308,25 +310,25 @@ func NewAppKeeper(
bApp.MsgServiceRouter(),
)

appKeepers.ICAModule = ica.NewAppModule(&appKeepers.ICAControllerKeeper, &appKeepers.ICAHostKeeper)
appKeepers.ICAModule = ica.NewAppModule(nil, &appKeepers.ICAHostKeeper)
icaHostIBCModule := icahost.NewIBCModule(appKeepers.ICAHostKeeper)

appKeepers.RouterKeeper = routerkeeper.NewKeeper(
appCodec, appKeepers.keys[routertypes.StoreKey],
appKeepers.GetSubspace(routertypes.ModuleName),
appKeepers.TransferKeeper,
appKeepers.IBCKeeper.ChannelKeeper,
appKeepers.DistrKeeper,
appKeepers.BankKeeper,
)
appKeepers.RouterModule = router.NewAppModule(appKeepers.RouterKeeper)

appKeepers.RouterModule = router.NewAppModule(appKeepers.RouterKeeper, transferIBCModule, 0,
routerkeeper.DefaultForwardTransferPacketTimeoutTimestamp, routerkeeper.DefaultRefundTransferPacketTimeoutTimestamp)
var ibcStack porttypes.IBCModule
ibcStack = transfer.NewIBCModule(appKeepers.TransferKeeper)
ibcStack = router.NewIBCMiddleware(
ibcStack,
&appKeepers.RouterKeeper,
0,
routerkeeper.DefaultForwardTransferPacketTimeoutTimestamp,
routerkeeper.DefaultRefundTransferPacketTimeoutTimestamp,
)

// create static IBC router, add transfer route, then set and seal it
ibcRouter := porttypes.NewRouter()
ibcRouter.AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, appKeepers.RouterModule)
ibcRouter := porttypes.NewRouter().
AddRoute(icahosttypes.SubModuleName, icaHostIBCModule).
AddRoute(ibctransfertypes.ModuleName, ibcStack)

appKeepers.IBCKeeper.SetRouter(ibcRouter)

Expand Down Expand Up @@ -363,19 +365,12 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(ibchost.ModuleName)

paramsKeeper.Subspace(routertypes.ModuleName).WithKeyTable(routertypes.ParamKeyTable())
paramsKeeper.Subspace(icacontrollertypes.SubModuleName)
paramsKeeper.Subspace(icahosttypes.SubModuleName)
paramsKeeper.Subspace(globalfee.ModuleName)

return paramsKeeper
}

// TODO: find out why GetStakingKeeper was being written here,
// // GetStakingKeeper implements the TestingApp interface.
// func (appKeepers *AppKeepers) GetStakingKeeper() ibctestingtypes.StakingKeeper {
// return appKeepers.StakingKeeper
// }

// GetIBCKeeper implements the TestingApp interface.
func (appKeepers *AppKeepers) GetIBCKeeper() *ibckeeper.Keeper {
return appKeepers.IBCKeeper
Expand Down
3 changes: 1 addition & 2 deletions app/keepers/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
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"
icacontrollertypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v3/modules/apps/27-interchain-accounts/host/types"
ibctransfertypes "github.com/cosmos/ibc-go/v3/modules/apps/transfer/types"
ibchost "github.com/cosmos/ibc-go/v3/modules/core/24-host"
Expand All @@ -33,7 +32,7 @@ func (appKeepers *AppKeepers) GenerateKeys() {
govtypes.StoreKey, paramstypes.StoreKey, ibchost.StoreKey, upgradetypes.StoreKey,
evidencetypes.StoreKey, liquiditytypes.StoreKey, ibctransfertypes.StoreKey,
capabilitytypes.StoreKey, feegrant.StoreKey, authzkeeper.StoreKey, routertypes.StoreKey,
icacontrollertypes.StoreKey, icahosttypes.StoreKey,
icahosttypes.StoreKey,
)

// Define transient store keys
Expand Down
3 changes: 0 additions & 3 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func orderBeginBlockers() []string {
feegrant.ModuleName,
paramstypes.ModuleName,
vestingtypes.ModuleName,
icatypes.ModuleName,
globalfee.ModuleName,
}
}
Expand Down Expand Up @@ -221,7 +220,6 @@ func orderEndBlockers() []string {
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
icatypes.ModuleName,
globalfee.ModuleName,
}
}
Expand All @@ -246,7 +244,6 @@ func orderInitBlockers() []string {
authz.ModuleName,
feegrant.ModuleName,
routertypes.ModuleName,
icatypes.ModuleName,
paramstypes.ModuleName,
upgradetypes.ModuleName,
vestingtypes.ModuleName,
Expand Down
30 changes: 19 additions & 11 deletions app/upgrades/v8/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v8

import (
"errors"
"fmt"

"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -16,6 +17,8 @@ import (
)

func FixBankMetadata(ctx sdk.Context, keepers *keepers.AppKeepers) error {
ctx.Logger().Info("Starting fix bank metadata...")

malformedDenom := "uatomu"
correctDenom := "uatom"

Expand Down Expand Up @@ -47,10 +50,14 @@ func FixBankMetadata(ctx sdk.Context, keepers *keepers.AppKeepers) error {
atomMetaData.Symbol = "ATOM"
keepers.BankKeeper.SetDenomMetaData(ctx, atomMetaData)

ctx.Logger().Info("Fix bank metadata complete")

return nil
}

func QuicksilverFix(ctx sdk.Context, keepers *keepers.AppKeepers) error {
ctx.Logger().Info("Starting fix quicksilver...")

// Refund stuck coins from ica address
sourceAddress, err := sdk.AccAddressFromBech32("cosmos13dqvh4qtg4gzczuktgnw8gc2ewnwmhdwnctekxctyr4azz4dcyysecgq7e")
if err != nil {
Expand Down Expand Up @@ -78,6 +85,8 @@ func QuicksilverFix(ctx sdk.Context, keepers *keepers.AppKeepers) error {
closeChannel(keepers, ctx, "channel-465")
closeChannel(keepers, ctx, "channel-466")

ctx.Logger().Info("Fix quicksilver complete")

return nil
}

Expand All @@ -95,18 +104,11 @@ func CreateUpgradeHandler(
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
ctx.Logger().Info("start to run module migrations...")

vm, err := mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return vm, err
}

ctx.Logger().Info("running the rest of the upgrade handler...")
ctx.Logger().Info("Running upgrade fixes...")

err = FixBankMetadata(ctx, keepers)
err := FixBankMetadata(ctx, keepers)
if err != nil {
return vm, err
ctx.Logger().Info(fmt.Sprintf("error fixing bank metadata: %s", err.Error()))
}

err = QuicksilverFix(ctx, keepers)
Expand All @@ -123,8 +125,14 @@ func CreateUpgradeHandler(
// Update params for host & controller keepers
keepers.ICAHostKeeper.SetParams(ctx, hostParams)

ctx.Logger().Info("upgrade complete")
ctx.Logger().Info("Starting module migrations...")

vm, err = mm.RunMigrations(ctx, configurator, vm)
if err != nil {
return vm, err
}

ctx.Logger().Info("Upgrade complete")
return vm, err
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.14.0
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.0.0
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.1.1-0.20230113180046-4fb516ae522e
github.com/stretchr/testify v1.8.1
github.com/tendermint/tendermint v0.34.24
github.com/tendermint/tm-db v0.6.7
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1094,8 +1094,10 @@ github.com/ssgreg/nlreturn/v2 v2.2.1/go.mod h1:E/iiPB78hV7Szg2YfRgyIrk1AD6JVMTRk
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=
github.com/stbenjam/no-sprintf-host-port v0.1.1 h1:tYugd/yrm1O0dV+ThCbaKZh195Dfm07ysF0U6JQXczc=
github.com/stbenjam/no-sprintf-host-port v0.1.1/go.mod h1:TLhvtIvONRzdmkFiio4O8LHsN9N74I+PhRquPsxpL0I=
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.0.0 h1:V1RVRa2hga4TV//RQpk2PCt314slS3N12024TsJoJUo=
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.0.0/go.mod h1:sRBHb6KwuHQVc07vy8Ice9wUKVdvzn7eEms9scr2Zco=
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.1.0 h1:EeEeCAXbNhJtO8Q++C9ZSxLs+MjygsKRK7FiScNHe1E=
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.1.0/go.mod h1:sRBHb6KwuHQVc07vy8Ice9wUKVdvzn7eEms9scr2Zco=
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.1.1-0.20230113180046-4fb516ae522e h1:qdK0r0xRSZjWTn5g6ORLKBZcQ/vyQxJC1vZTW9ogVl4=
github.com/strangelove-ventures/packet-forward-middleware/v3 v3.1.1-0.20230113180046-4fb516ae522e/go.mod h1:sRBHb6KwuHQVc07vy8Ice9wUKVdvzn7eEms9scr2Zco=
github.com/streadway/amqp v0.0.0-20190404075320-75d898a42a94/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271/go.mod h1:AZpEONHx3DKn8O/DFsRAY58/XVQiIPMTMB1SddzLXVw=
github.com/streadway/handy v0.0.0-20190108123426-d5acb3125c2a/go.mod h1:qNTQ5P5JnDBl6z3cMAg/SywNDC5ABu5ApDIw6lUbRmI=
Expand Down