Skip to content

Commit

Permalink
Remove sdk.Result from application callbacks #215 (#227)
Browse files Browse the repository at this point in the history
* Remove sdk.Result from application callbacks #215

* add changelog and migration doc entry

Co-authored-by: Colin Axnér <[email protected]>
  • Loading branch information
smadarasmi and colin-axner authored Jul 5, 2021
1 parent 007c680 commit b36f8c6
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ Ref: https://keepachangelog.com/en/1.0.0/

# Changelog

## [Unreleased (2.0)]

* (core) [\#227](https://github.com/cosmos/ibc-go/pull/227) Remove sdk.Result from application callbacks


## [Unreleased]

### Bug Fixes
Expand Down
8 changes: 8 additions & 0 deletions docs/migrations/ibc-migration-v100.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Migrating from ibc-go v1.x.x to v2.0.0

## Application Callbacks

sdk.Result has been removed as a return value in the application callbacks. Previously it was being discarded by core IBC and was thus unused.



22 changes: 9 additions & 13 deletions modules/apps/transfer/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,18 @@ func (am AppModule) OnAcknowledgementPacket(
packet channeltypes.Packet,
acknowledgement []byte,
relayer sdk.AccAddress,
) (*sdk.Result, error) {
) error {
var ack channeltypes.Acknowledgement
if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err)
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet acknowledgement: %v", err)
}
var data types.FungibleTokenPacketData
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error())
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error())
}

if err := am.keeper.OnAcknowledgementPacket(ctx, packet, data, ack); err != nil {
return nil, err
return err
}

ctx.EventManager().EmitEvent(
Expand Down Expand Up @@ -404,24 +404,22 @@ func (am AppModule) OnAcknowledgementPacket(
)
}

return &sdk.Result{
Events: ctx.EventManager().Events().ToABCIEvents(),
}, nil
return nil
}

// OnTimeoutPacket implements the IBCModule interface
func (am AppModule) OnTimeoutPacket(
ctx sdk.Context,
packet channeltypes.Packet,
relayer sdk.AccAddress,
) (*sdk.Result, error) {
) error {
var data types.FungibleTokenPacketData
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error())
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-20 transfer packet data: %s", err.Error())
}
// refund tokens
if err := am.keeper.OnTimeoutPacket(ctx, packet, data); err != nil {
return nil, err
return err
}

ctx.EventManager().EmitEvent(
Expand All @@ -434,7 +432,5 @@ func (am AppModule) OnTimeoutPacket(
),
)

return &sdk.Result{
Events: ctx.EventManager().Events().ToABCIEvents(),
}, nil
return nil
}
4 changes: 2 additions & 2 deletions modules/core/05-port/types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ type IBCModule interface {
packet channeltypes.Packet,
acknowledgement []byte,
relayer sdk.AccAddress,
) (*sdk.Result, error)
) error

OnTimeoutPacket(
ctx sdk.Context,
packet channeltypes.Packet,
relayer sdk.AccAddress,
) (*sdk.Result, error)
) error
}
6 changes: 3 additions & 3 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ func (k Keeper) Timeout(goCtx context.Context, msg *channeltypes.MsgTimeout) (*c
}

// Perform application logic callback
_, err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer)
err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer)
if err != nil {
return nil, sdkerrors.Wrap(err, "timeout packet callback failed")
}
Expand Down Expand Up @@ -613,7 +613,7 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo
// Perform application logic callback
// NOTE: MsgTimeout and MsgTimeoutOnClose use the same "OnTimeoutPacket"
// application logic callback.
_, err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer)
err = cbs.OnTimeoutPacket(ctx, msg.Packet, relayer)
if err != nil {
return nil, sdkerrors.Wrap(err, "timeout packet callback failed")
}
Expand Down Expand Up @@ -667,7 +667,7 @@ func (k Keeper) Acknowledgement(goCtx context.Context, msg *channeltypes.MsgAckn
}

// Perform application logic callback
_, err = cbs.OnAcknowledgementPacket(ctx, msg.Packet, msg.Acknowledgement, relayer)
err = cbs.OnAcknowledgementPacket(ctx, msg.Packet, msg.Acknowledgement, relayer)
if err != nil {
return nil, sdkerrors.Wrap(err, "acknowledge packet callback failed")
}
Expand Down
8 changes: 4 additions & 4 deletions testing/mock/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,11 @@ func (am AppModule) OnRecvPacket(ctx sdk.Context, packet channeltypes.Packet, re
}

// OnAcknowledgementPacket implements the IBCModule interface.
func (am AppModule) OnAcknowledgementPacket(sdk.Context, channeltypes.Packet, []byte, sdk.AccAddress) (*sdk.Result, error) {
return nil, nil
func (am AppModule) OnAcknowledgementPacket(sdk.Context, channeltypes.Packet, []byte, sdk.AccAddress) error {
return nil
}

// OnTimeoutPacket implements the IBCModule interface.
func (am AppModule) OnTimeoutPacket(sdk.Context, channeltypes.Packet, sdk.AccAddress) (*sdk.Result, error) {
return nil, nil
func (am AppModule) OnTimeoutPacket(sdk.Context, channeltypes.Packet, sdk.AccAddress) error {
return nil
}

0 comments on commit b36f8c6

Please sign in to comment.