From 06ee94176b1e8053f6e710c0ab5f64ceb6faad09 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Sun, 15 Jan 2023 16:45:20 -0700 Subject: [PATCH 1/2] Integrate packet forward middleware --- app/keepers/keepers.go | 93 +++++++++++++++++++++++++++--------------- app/keepers/keys.go | 3 +- app/modules.go | 7 ++++ go.mod | 1 + go.sum | 2 + 5 files changed, 73 insertions(+), 33 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index e90c54598..2b9105fd1 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -57,6 +57,10 @@ import ( ibchooks "github.com/osmosis-labs/osmosis/x/ibc-hooks" ibchookskeeper "github.com/osmosis-labs/osmosis/x/ibc-hooks/keeper" + packetforward "github.com/strangelove-ventures/packet-forward-middleware/v4/router" + packetforwardkeeper "github.com/strangelove-ventures/packet-forward-middleware/v4/router/keeper" + packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" + "github.com/CosmWasm/token-factory/x/tokenfactory/bindings" tokenfactorykeeper "github.com/CosmWasm/token-factory/x/tokenfactory/keeper" tokenfactorytypes "github.com/CosmWasm/token-factory/x/tokenfactory/types" @@ -88,26 +92,27 @@ type AppKeepers struct { memKeys map[string]*sdk.MemoryStoreKey // keepers - AccountKeeper authkeeper.AccountKeeper - BankKeeper bankkeeper.BaseKeeper - CapabilityKeeper *capabilitykeeper.Keeper - StakingKeeper stakingkeeper.Keeper - SlashingKeeper slashingkeeper.Keeper - MintKeeper mintkeeper.Keeper - DistrKeeper distrkeeper.Keeper - GovKeeper govkeeper.Keeper - CrisisKeeper crisiskeeper.Keeper - UpgradeKeeper upgradekeeper.Keeper - ParamsKeeper paramskeeper.Keeper - IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly - IBCFeeKeeper ibcfeekeeper.Keeper - IBCHooksKeeper *ibchookskeeper.Keeper - EvidenceKeeper evidencekeeper.Keeper - TransferKeeper ibctransferkeeper.Keeper - AuthzKeeper authzkeeper.Keeper - FeeGrantKeeper feegrantkeeper.Keeper - FeeShareKeeper feesharekeeper.Keeper - ContractKeeper *wasmkeeper.PermissionedKeeper + AccountKeeper authkeeper.AccountKeeper + BankKeeper bankkeeper.BaseKeeper + CapabilityKeeper *capabilitykeeper.Keeper + StakingKeeper stakingkeeper.Keeper + SlashingKeeper slashingkeeper.Keeper + MintKeeper mintkeeper.Keeper + DistrKeeper distrkeeper.Keeper + GovKeeper govkeeper.Keeper + CrisisKeeper crisiskeeper.Keeper + UpgradeKeeper upgradekeeper.Keeper + ParamsKeeper paramskeeper.Keeper + IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly + IBCFeeKeeper ibcfeekeeper.Keeper + IBCHooksKeeper *ibchookskeeper.Keeper + PacketForwardKeeper *packetforwardkeeper.Keeper + EvidenceKeeper evidencekeeper.Keeper + TransferKeeper ibctransferkeeper.Keeper + AuthzKeeper authzkeeper.Keeper + FeeGrantKeeper feegrantkeeper.Keeper + FeeShareKeeper feesharekeeper.Keeper + ContractKeeper *wasmkeeper.PermissionedKeeper OracleKeeper oraclekeeper.Keeper ICAControllerKeeper icacontrollerkeeper.Keeper @@ -261,16 +266,6 @@ func NewAppKeepers( scopedIBCKeeper, ) - appKeepers.IBCFeeKeeper = ibcfeekeeper.NewKeeper( - appCodec, appKeepers.keys[ibcfeetypes.StoreKey], - appKeepers.GetSubspace(ibcfeetypes.ModuleName), // this isn't even used in the keeper but is required? - appKeepers.IBCKeeper.ChannelKeeper, // may be replaced with IBC middleware - appKeepers.IBCKeeper.ChannelKeeper, - &appKeepers.IBCKeeper.PortKeeper, - appKeepers.AccountKeeper, - appKeepers.BankKeeper, - ) - appKeepers.FeeGrantKeeper = feegrantkeeper.NewKeeper( appCodec, appKeepers.keys[feegrant.StoreKey], @@ -305,13 +300,36 @@ func NewAppKeepers( appKeepers.Ics20WasmHooks, ) + // Initialize packet forward middleware router + appKeepers.PacketForwardKeeper = packetforwardkeeper.NewKeeper( + appCodec, appKeepers.keys[packetforwardtypes.StoreKey], + appKeepers.GetSubspace(packetforwardtypes.ModuleName), + appKeepers.TransferKeeper, // will be zero-vaue here. reference set later on with SetTransferKeeper. + appKeepers.IBCKeeper.ChannelKeeper, + appKeepers.DistrKeeper, + appKeepers.BankKeeper, + &appKeepers.IBCKeeper.PortKeeper, + // The ICS4Wrapper is replaced by the HooksICS4Wrapper instead of the channel so that sending can be overridden by the middleware + &appKeepers.HooksICS4Wrapper, + ) + + appKeepers.IBCFeeKeeper = ibcfeekeeper.NewKeeper( + appCodec, appKeepers.keys[ibcfeetypes.StoreKey], + appKeepers.GetSubspace(ibcfeetypes.ModuleName), // this isn't even used in the keeper but is required? + appKeepers.PacketForwardKeeper, // replaced with IBC middleware + appKeepers.IBCKeeper.ChannelKeeper, + &appKeepers.IBCKeeper.PortKeeper, + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + ) + // Create Transfer Keepers appKeepers.TransferKeeper = ibctransferkeeper.NewKeeper( appCodec, appKeepers.keys[ibctransfertypes.StoreKey], appKeepers.GetSubspace(ibctransfertypes.ModuleName), - // The ICS4Wrapper is replaced by the HooksICS4Wrapper instead of the channel so that sending can be overridden by the middleware - appKeepers.HooksICS4Wrapper, + // The ICS4Wrapper is replaced by the PacketForwardKeeper instead of the channel so that sending can be overridden by the middleware + appKeepers.PacketForwardKeeper, appKeepers.IBCKeeper.ChannelKeeper, &appKeepers.IBCKeeper.PortKeeper, appKeepers.AccountKeeper, @@ -319,6 +337,8 @@ func NewAppKeepers( scopedTransferKeeper, ) + appKeepers.PacketForwardKeeper.SetTransferKeeper(appKeepers.TransferKeeper) + appKeepers.ICAHostKeeper = icahostkeeper.NewKeeper( appCodec, appKeepers.keys[icahosttypes.StoreKey], @@ -440,8 +460,16 @@ func NewAppKeepers( // Create Transfer Stack var transferStack porttypes.IBCModule transferStack = transfer.NewIBCModule(appKeepers.TransferKeeper) + transferStack = packetforward.NewIBCMiddleware( + transferStack, + appKeepers.PacketForwardKeeper, + 0, + packetforwardkeeper.DefaultForwardTransferPacketTimeoutTimestamp, + packetforwardkeeper.DefaultRefundTransferPacketTimeoutTimestamp, + ) transferStack = ibcfee.NewIBCMiddleware(transferStack, appKeepers.IBCFeeKeeper) transferStack = ibchooks.NewIBCMiddleware(transferStack, &appKeepers.HooksICS4Wrapper) + // RecvPacket, message that originates from core IBC and goes down to app, the flow is: // channel.RecvPacket -> fee.OnRecvPacket -> icaHost.OnRecvPacket icaHostStack := ibcfee.NewIBCMiddleware(icaHostIBCModule, appKeepers.IBCFeeKeeper) @@ -493,6 +521,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino paramsKeeper.Subspace(govtypes.ModuleName).WithKeyTable(govtypes.ParamKeyTable()) paramsKeeper.Subspace(crisistypes.ModuleName) paramsKeeper.Subspace(ibctransfertypes.ModuleName) + paramsKeeper.Subspace(packetforwardtypes.ModuleName).WithKeyTable(packetforwardtypes.ParamKeyTable()) paramsKeeper.Subspace(ibchost.ModuleName) paramsKeeper.Subspace(icacontrollertypes.SubModuleName) paramsKeeper.Subspace(icahosttypes.SubModuleName) diff --git a/app/keepers/keys.go b/app/keepers/keys.go index fe5f81cad..5c20e7257 100644 --- a/app/keepers/keys.go +++ b/app/keepers/keys.go @@ -27,6 +27,7 @@ import ( ibchost "github.com/cosmos/ibc-go/v4/modules/core/24-host" intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types" ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types" + packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" ) func (appKeepers *AppKeepers) GenerateKeys() { @@ -37,7 +38,7 @@ func (appKeepers *AppKeepers) GenerateKeys() { evidencetypes.StoreKey, ibctransfertypes.StoreKey, capabilitytypes.StoreKey, authzkeeper.StoreKey, feegrant.StoreKey, icahosttypes.StoreKey, ibcfeetypes.StoreKey, tokenfactorytypes.StoreKey, feesharetypes.StoreKey, wasm.StoreKey, intertxtypes.StoreKey, - icacontrollertypes.StoreKey, oracletypes.StoreKey, ibchookstypes.StoreKey, + icacontrollertypes.StoreKey, oracletypes.StoreKey, ibchookstypes.StoreKey, packetforwardtypes.StoreKey, ) appKeepers.tkeys = sdk.NewTransientStoreKeys(paramstypes.TStoreKey) diff --git a/app/modules.go b/app/modules.go index 3b20169b8..b83b2d07b 100644 --- a/app/modules.go +++ b/app/modules.go @@ -56,6 +56,8 @@ import ( intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types" ibchooks "github.com/osmosis-labs/osmosis/x/ibc-hooks" ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types" + packetforward "github.com/strangelove-ventures/packet-forward-middleware/v4/router" + packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" ) // module account permissions @@ -106,6 +108,7 @@ var ModuleBasics = module.NewBasicManager( feeshare.AppModuleBasic{}, globalfee.AppModuleBasic{}, ibchooks.AppModuleBasic{}, + packetforward.AppModuleBasic{}, ) func appModules( @@ -146,6 +149,7 @@ func appModules( intertx.NewAppModule(appCodec, app.InterTxKeeper), oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper), ibchooks.NewAppModule(app.AccountKeeper), + packetforward.NewAppModule(app.PacketForwardKeeper), } } @@ -204,6 +208,7 @@ func orderBeginBlockers() []string { ibchost.ModuleName, ibctransfertypes.ModuleName, icatypes.ModuleName, + packetforwardtypes.ModuleName, intertxtypes.ModuleName, ibcfeetypes.ModuleName, oracletypes.ModuleName, @@ -237,6 +242,7 @@ func orderEndBlockers() []string { ibchost.ModuleName, ibctransfertypes.ModuleName, icatypes.ModuleName, + packetforwardtypes.ModuleName, intertxtypes.ModuleName, ibcfeetypes.ModuleName, oracletypes.ModuleName, @@ -270,6 +276,7 @@ func orderInitBlockers() []string { ibchost.ModuleName, ibctransfertypes.ModuleName, icatypes.ModuleName, + packetforwardtypes.ModuleName, oracletypes.ModuleName, intertxtypes.ModuleName, ibcfeetypes.ModuleName, diff --git a/go.mod b/go.mod index 145a328b1..9e415e874 100644 --- a/go.mod +++ b/go.mod @@ -19,6 +19,7 @@ require ( github.com/prometheus/client_golang v1.14.0 github.com/spf13/cast v1.5.0 github.com/spf13/cobra v1.6.1 + github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.1-0.20230115230008-9d283c08227d github.com/stretchr/testify v1.8.1 github.com/tendermint/tendermint v0.34.24 github.com/tendermint/tm-db v0.6.8-0.20220506192307-f628bb5dc95b diff --git a/go.sum b/go.sum index 685631cb0..8b53da8e4 100644 --- a/go.sum +++ b/go.sum @@ -880,6 +880,8 @@ github.com/spf13/viper v1.3.2/go.mod h1:ZiWeW+zYFKm7srdB9IoDzzZXaJaI5eL9QjNiN/DM github.com/spf13/viper v1.14.0 h1:Rg7d3Lo706X9tHsJMUjdiwMpHB7W8WnSVOssIY+JElU= github.com/spf13/viper v1.14.0/go.mod h1:WT//axPky3FdvXHzGw33dNdXXXfFQqmEalje+egj8As= github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q= +github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.1-0.20230115230008-9d283c08227d h1:9ZUFA1o5r/3T2vV0QwTJAo3LnuILaLsZRAPHrR11tP8= +github.com/strangelove-ventures/packet-forward-middleware/v4 v4.0.1-0.20230115230008-9d283c08227d/go.mod h1:zDsRdoeNhwyQ9j9984HDCZgUZneHklUCz/J9mj5ll5I= 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= From caa88a621cf5edbe4d007266fda49eebee4cb528 Mon Sep 17 00:00:00 2001 From: Andrew Gouin Date: Mon, 16 Jan 2023 14:11:01 -0700 Subject: [PATCH 2/2] Fix v11 to v12 upgrade --- app/keepers/keepers.go | 2 +- app/upgrades/v12/constants.go | 12 +++++++++++- app/upgrades/v12/upgrades.go | 5 +++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 2b9105fd1..a5c689048 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -304,7 +304,7 @@ func NewAppKeepers( appKeepers.PacketForwardKeeper = packetforwardkeeper.NewKeeper( appCodec, appKeepers.keys[packetforwardtypes.StoreKey], appKeepers.GetSubspace(packetforwardtypes.ModuleName), - appKeepers.TransferKeeper, // will be zero-vaue here. reference set later on with SetTransferKeeper. + appKeepers.TransferKeeper, // Will be zero-value here. Reference is set later on with SetTransferKeeper. appKeepers.IBCKeeper.ChannelKeeper, appKeepers.DistrKeeper, appKeepers.BankKeeper, diff --git a/app/upgrades/v12/constants.go b/app/upgrades/v12/constants.go index 6aa122756..ac65d3236 100644 --- a/app/upgrades/v12/constants.go +++ b/app/upgrades/v12/constants.go @@ -10,6 +10,7 @@ import ( ibcfeetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types" ibchookstypes "github.com/osmosis-labs/osmosis/x/ibc-hooks/types" + packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" ) // UpgradeName defines the on-chain upgrade name for the Juno v12 upgrade. @@ -19,6 +20,15 @@ var Upgrade = upgrades.Upgrade{ UpgradeName: UpgradeName, CreateUpgradeHandler: CreateV12UpgradeHandler, StoreUpgrades: store.StoreUpgrades{ - Added: []string{tokenfactorytypes.ModuleName, oracletypes.ModuleName, feesharetypes.ModuleName, globalfee.ModuleName, ibcfeetypes.ModuleName, intertxtypes.ModuleName, ibchookstypes.StoreKey}, + Added: []string{ + tokenfactorytypes.ModuleName, + oracletypes.ModuleName, + feesharetypes.ModuleName, + globalfee.ModuleName, + ibcfeetypes.ModuleName, + intertxtypes.ModuleName, + ibchookstypes.StoreKey, + packetforwardtypes.StoreKey, + }, }, } diff --git a/app/upgrades/v12/upgrades.go b/app/upgrades/v12/upgrades.go index 65b4784bc..1a9733bc5 100644 --- a/app/upgrades/v12/upgrades.go +++ b/app/upgrades/v12/upgrades.go @@ -27,6 +27,8 @@ import ( ica "github.com/cosmos/ibc-go/v4/modules/apps/27-interchain-accounts" ibcfeetypes "github.com/cosmos/ibc-go/v4/modules/apps/29-fee/types" + + packetforwardtypes "github.com/strangelove-ventures/packet-forward-middleware/v4/router/types" ) // Returns "ujunox" if the chain is uni, else returns the standard ujuno token denom. @@ -172,6 +174,9 @@ func CreateV12UpgradeHandler( keepers.FeeShareKeeper.SetParams(ctx, newFeeShareParams) logger.Info("set feeshare params") + // Packet Forward middleware initial params + keepers.PacketForwardKeeper.SetParams(ctx, packetforwardtypes.DefaultParams()) + return versionMap, err } }