Skip to content

Commit

Permalink
Call TimeoutExecuted, add wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed Feb 3, 2020
1 parent 3304ffb commit 30a3a46
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
16 changes: 10 additions & 6 deletions x/ibc/20-transfer/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func handlePacketDataTransfer(
),
)

// packet receiving should not fail
return &sdk.Result{
Events: ctx.EventManager().Events(),
}, nil
Expand All @@ -96,13 +95,18 @@ func handlePacketDataTransfer(
// See onTimeoutPacket in spec: https://github.com/cosmos/ics/tree/master/spec/ics-020-fungible-token-transfer#packet-relay
func handleTimeoutDataTransfer(ctx sdk.Context, k Keeper, msg channeltypes.MsgTimeout, data FungibleTokenPacketData) (*sdk.Result, error) {
packet := msg.Packet
if err := k.TimeoutTransfer(
ctx, packet.SourcePort, packet.SourceChannel, packet.DestinationPort, packet.DestinationChannel, data,
); err != nil {
return nil, err
err := k.TimeoutTransfer(ctx, packet.SourcePort, packet.SourceChannel, packet.DestinationPort, packet.DestinationChannel, data)
if err != nil {
// TODO: This chain sent invalid packet
panic(err)
}

err = k.TimeoutExecuted(ctx, packet)
if err != nil {
// TODO: This should not happen
panic(err)
}

// packet timeout should not fail
return &sdk.Result{
Events: ctx.EventManager().Events(),
}, nil
Expand Down
8 changes: 7 additions & 1 deletion x/ibc/20-transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (k Keeper) GetTransferAccount(ctx sdk.Context) supplyexported.ModuleAccount
}

// PacketExecuted defines a wrapper function for the channel Keeper's function
// in order to expose it to the ICS20 trasfer handler.
// in order to expose it to the ICS20 transfer handler.
func (k Keeper) PacketExecuted(ctx sdk.Context, packet channelexported.PacketI, acknowledgement channelexported.PacketDataI) error {
return k.channelKeeper.PacketExecuted(ctx, packet, acknowledgement)
}
Expand All @@ -74,3 +74,9 @@ func (k Keeper) PacketExecuted(ctx sdk.Context, packet channelexported.PacketI,
func (k Keeper) ChanCloseInit(ctx sdk.Context, portID, channelID string) error {
return k.channelKeeper.ChanCloseInit(ctx, portID, channelID)
}

// TimeoutExecuted defines a wrapper function for the channel Keeper's function
// in order to expose it to the ICS20 transfer handler.
func (k Keeper) TimeoutExecuted(ctx sdk.Context, packet channelexported.PacketI) error {
return k.channelKeeper.TimeoutExecuted(ctx, packet)
}
1 change: 1 addition & 0 deletions x/ibc/20-transfer/types/expected_keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ChannelKeeper interface {
SendPacket(ctx sdk.Context, packet channelexported.PacketI) error
PacketExecuted(ctx sdk.Context, packet channelexported.PacketI, acknowledgement channelexported.PacketDataI) error
ChanCloseInit(ctx sdk.Context, portID, channelID string) error
TimeoutExecuted(ctx sdk.Context, packet channelexported.PacketI) error
}

// ClientKeeper defines the expected IBC client keeper
Expand Down

0 comments on commit 30a3a46

Please sign in to comment.