From 3bc4d18005c3669e025c8091cbb4bf3b43f7104f Mon Sep 17 00:00:00 2001 From: Sarin Madarasmi Date: Sat, 3 Jul 2021 16:53:29 +0800 Subject: [PATCH 1/2] Remove sdk.Result from application callbacks #215 --- modules/apps/transfer/module.go | 22 +++++++++------------- modules/core/05-port/types/module.go | 4 ++-- modules/core/keeper/msg_server.go | 6 +++--- testing/mock/mock.go | 8 ++++---- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/modules/apps/transfer/module.go b/modules/apps/transfer/module.go index 1c9afbe9f46..a9a1aa4f875 100644 --- a/modules/apps/transfer/module.go +++ b/modules/apps/transfer/module.go @@ -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( @@ -404,9 +404,7 @@ func (am AppModule) OnAcknowledgementPacket( ) } - return &sdk.Result{ - Events: ctx.EventManager().Events().ToABCIEvents(), - }, nil + return nil } // OnTimeoutPacket implements the IBCModule interface @@ -414,14 +412,14 @@ 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( @@ -434,7 +432,5 @@ func (am AppModule) OnTimeoutPacket( ), ) - return &sdk.Result{ - Events: ctx.EventManager().Events().ToABCIEvents(), - }, nil + return nil } diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index 4a1c2596b81..9c0885c0cf1 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -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 } diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 3aeeffdb457..fe410471d63 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -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") } @@ -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") } @@ -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") } diff --git a/testing/mock/mock.go b/testing/mock/mock.go index e2062dda51a..9edf5d3536a 100644 --- a/testing/mock/mock.go +++ b/testing/mock/mock.go @@ -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 } From 3f462aec4446098bdab95bea6346ded1ef8d3ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Colin=20Axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 5 Jul 2021 11:29:46 +0200 Subject: [PATCH 2/2] add changelog and migration doc entry --- CHANGELOG.md | 5 +++++ docs/migrations/ibc-migration-v100.md | 8 ++++++++ 2 files changed, 13 insertions(+) create mode 100644 docs/migrations/ibc-migration-v100.md diff --git a/CHANGELOG.md b/CHANGELOG.md index c4420fb805b..3956025464d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/migrations/ibc-migration-v100.md b/docs/migrations/ibc-migration-v100.md new file mode 100644 index 00000000000..5f5c814c3ac --- /dev/null +++ b/docs/migrations/ibc-migration-v100.md @@ -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. + + +