From d42f0acf006fc05c61f001b9d6396cc80d79c88a Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 26 Nov 2021 11:35:09 +0100 Subject: [PATCH 1/3] chore: add ICS4 wrapper --- modules/apps/29-fee/keeper/escrow.go | 1 + modules/apps/29-fee/keeper/keeper.go | 9 +++------ modules/apps/29-fee/types/expected_keepers.go | 8 ++++++-- testing/simapp/app.go | 3 +-- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/modules/apps/29-fee/keeper/escrow.go b/modules/apps/29-fee/keeper/escrow.go index ce7c73db8ce..f999b62e196 100644 --- a/modules/apps/29-fee/keeper/escrow.go +++ b/modules/apps/29-fee/keeper/escrow.go @@ -17,6 +17,7 @@ func (k Keeper) EscrowPacketFee(ctx sdk.Context, identifiedFee *types.Identified if err != nil { return err } + hasRefundAcc := k.authKeeper.GetAccount(ctx, refundAcc) if hasRefundAcc == nil { return sdkerrors.Wrap(types.ErrRefundAccNotFound, fmt.Sprintf("Account with address: %s not found", refundAcc)) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index 1fda4910bc2..f5bdcb3f54f 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -28,6 +28,7 @@ type Keeper struct { cdc codec.BinaryCodec authKeeper types.AccountKeeper + ics4Wrapper types.ICS4Wrapper channelKeeper types.ChannelKeeper portKeeper types.PortKeeper bankKeeper types.BankKeeper @@ -36,12 +37,13 @@ type Keeper struct { // NewKeeper creates a new 29-fee Keeper instance func NewKeeper( cdc codec.BinaryCodec, key sdk.StoreKey, paramSpace paramtypes.Subspace, - channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, + ics4Wrapper types.ICS4Wrapper, channelKeeper types.ChannelKeeper, portKeeper types.PortKeeper, authKeeper types.AccountKeeper, bankKeeper types.BankKeeper, ) Keeper { return Keeper{ cdc: cdc, storeKey: key, + ics4Wrapper: ics4Wrapper, channelKeeper: channelKeeper, portKeeper: portKeeper, authKeeper: authKeeper, @@ -54,11 +56,6 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger { return ctx.Logger().With("module", "x/"+host.ModuleName+"-"+types.ModuleName) } -// ChanCloseInit wraps the channel keeper's function in order to expose it to underlying app. -func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error { - return k.channelKeeper.ChanCloseInit(ctx, portID, channelID, chanCap) -} - // BindPort defines a wrapper function for the port Keeper's function in // order to expose it to module's InitGenesis function func (k Keeper) BindPort(ctx sdk.Context, portID string) *capabilitytypes.Capability { diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index 33edb1c01ce..e73477ede46 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -14,12 +14,16 @@ type AccountKeeper interface { GetAccount(sdk.Context, sdk.AccAddress) types.AccountI } +// ICS4Wrapper defines the expected ICS4Wrapper for middleware +type ICS4Wrapper interface { + SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error +} + // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { + SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error - ChanCloseInit(ctx sdk.Context, portID, channelID string, chanCap *capabilitytypes.Capability) error } // PortKeeper defines the expected IBC port keeper diff --git a/testing/simapp/app.go b/testing/simapp/app.go index 58b2a79006d..a926bdd9f9f 100644 --- a/testing/simapp/app.go +++ b/testing/simapp/app.go @@ -222,7 +222,6 @@ func NewSimApp( homePath string, invCheckPeriod uint, encodingConfig simappparams.EncodingConfig, appOpts servertypes.AppOptions, baseAppOptions ...func(*baseapp.BaseApp), ) *SimApp { - appCodec := encodingConfig.Marshaler legacyAmino := encodingConfig.Amino interfaceRegistry := encodingConfig.InterfaceRegistry @@ -323,7 +322,7 @@ func NewSimApp( ) app.IBCFeeKeeper = ibcfeekeeper.NewKeeper(appCodec, keys[ibcfeetypes.StoreKey], app.GetSubspace(ibcfeetypes.ModuleName), - app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, + app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper, app.AccountKeeper, app.BankKeeper, ) // Create Transfer Keeper and pass IBCFeeKeeper as expected Channel and PortKeeper From dde7c863cee8c1f7e4a7432337117bd284363292 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 26 Nov 2021 12:47:11 +0100 Subject: [PATCH 2/3] fix: remove channelKeeper sender packet --- modules/apps/29-fee/keeper/keeper.go | 2 +- modules/apps/29-fee/types/expected_keepers.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/apps/29-fee/keeper/keeper.go b/modules/apps/29-fee/keeper/keeper.go index f5bdcb3f54f..953ce3ec8ad 100644 --- a/modules/apps/29-fee/keeper/keeper.go +++ b/modules/apps/29-fee/keeper/keeper.go @@ -79,7 +79,7 @@ func (k Keeper) GetFeeModuleAddress() sdk.AccAddress { // SendPacket wraps IBC ChannelKeeper's SendPacket function func (k Keeper) SendPacket(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI) error { - return k.channelKeeper.SendPacket(ctx, chanCap, packet) + return k.ics4Wrapper.SendPacket(ctx, chanCap, packet) } // SetFeeEnabled sets a flag to determine if fee handling logic should run for the given channel diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index e73477ede46..4e64d728371 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -21,7 +21,6 @@ type ICS4Wrapper interface { // ChannelKeeper defines the expected IBC channel keeper type ChannelKeeper interface { - SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error GetChannel(ctx sdk.Context, srcPort, srcChan string) (channel channeltypes.Channel, found bool) GetNextSequenceSend(ctx sdk.Context, portID, channelID string) (uint64, bool) } From 7be7cdc11b662267aaeb471d4e0fe053507235f9 Mon Sep 17 00:00:00 2001 From: Sean King Date: Tue, 30 Nov 2021 13:18:25 +0100 Subject: [PATCH 3/3] chore: add WriteAck --- modules/apps/29-fee/types/expected_keepers.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/apps/29-fee/types/expected_keepers.go b/modules/apps/29-fee/types/expected_keepers.go index 4e64d728371..76a7d8a382a 100644 --- a/modules/apps/29-fee/types/expected_keepers.go +++ b/modules/apps/29-fee/types/expected_keepers.go @@ -16,6 +16,7 @@ type AccountKeeper interface { // ICS4Wrapper defines the expected ICS4Wrapper for middleware type ICS4Wrapper interface { + WriteAcknowledgement(ctx sdk.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement []byte) error SendPacket(ctx sdk.Context, channelCap *capabilitytypes.Capability, packet ibcexported.PacketI) error }