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

Remove sdk.Result from application callbacks #215 #227

Merged
merged 3 commits into from
Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}