diff --git a/CHANGELOG.md b/CHANGELOG.md index c4420fb805b..e62693b8d37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,21 +34,27 @@ 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 +* (modules) [\#223](https://github.com/cosmos/ibc-go/pull/223) Use correct Prometheus format for metric labels. * (06-solomachine) [\#214](https://github.com/cosmos/ibc-go/pull/214) Disable defensive timestamp check in SendPacket for solo machine clients. -* (07-tendermint) [#\210](https://github.com/cosmos/ibc-go/pull/210) Export all consensus metadata on genesis restarts for tendermint clients. +* (07-tendermint) [\#210](https://github.com/cosmos/ibc-go/pull/210) Export all consensus metadata on genesis restarts for tendermint clients. * (core) [\#200](https://github.com/cosmos/ibc-go/pull/200) Fixes incorrect export of IBC identifier sequences. Previously, the next identifier sequence for clients/connections/channels was not set during genesis export. This resulted in the next identifiers being generated on the new chain to reuse old identifiers (the sequences began again from 0). * (02-client) [\#192](https://github.com/cosmos/ibc-go/pull/192) Fix IBC `query ibc client header` cli command. Support historical queries for query header/node-state commands. * (modules/light-clients/06-solomachine) [\#153](https://github.com/cosmos/ibc-go/pull/153) Fix solo machine proof height sequence mismatch bug. * (modules/light-clients/06-solomachine) [\#122](https://github.com/cosmos/ibc-go/pull/122) Fix solo machine merkle prefix casting bug. * (modules/light-clients/06-solomachine) [\#120](https://github.com/cosmos/ibc-go/pull/120) Fix solo machine handshake verification bug. - ### API Breaking +* (04-channel) [\#220](https://github.com/cosmos/ibc-go/pull/220) Channel legacy handler functions were removed. Please use the MsgServer functions or directly call the channel keeper's handshake function. * (modules) [\#206](https://github.com/cosmos/ibc-go/pull/206) Expose `relayer sdk.AccAddress` on `OnRecvPacket`, `OnAcknowledgementPacket`, `OnTimeoutPacket` module callbacks to enable incentivization. * (02-client) [\#181](https://github.com/cosmos/ibc-go/pull/181) Remove 'InitialHeight' from UpdateClient Proposal. Only copy over latest consensus state from substitute client. * (06-solomachine) [\#169](https://github.com/cosmos/ibc-go/pull/169) Change FrozenSequence to boolean in solomachine ClientState. The solo machine proto package has been bumped from `v1` to `v2`. @@ -72,6 +78,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (04-channel) [\#220](https://github.com/cosmos/ibc-go/pull/220) Channel handshake events are now emitted with the channel keeper. * (core/02-client) [\#205](https://github.com/cosmos/ibc-go/pull/205) Add in-place and genesis migrations from SDK v0.42.0 to ibc-go v1.0.0. Solo machine protobuf defintions are migrated from v1 to v2. All solo machine consensus states are pruned. All expired tendermint consensus states are pruned. * (modules/core) [\#184](https://github.com/cosmos/ibc-go/pull/184) Improve error messages. Uses unique error codes to indicate already relayed packets. * (07-tendermint) [\#182](https://github.com/cosmos/ibc-go/pull/182) Remove duplicate checks in upgrade logic. 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. + + + 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..ab9e583385c 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -500,6 +500,10 @@ func (k Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPacke // Cache context so that we may discard state changes from callback if the acknowledgement is unsuccessful. cacheCtx, writeFn := ctx.CacheContext() ack := cbs.OnRecvPacket(cacheCtx, msg.Packet, relayer) + // This doesn't cause duplicate events to be emitted. + // NOTE: The context returned by CacheContext() refers to a new EventManager, so it needs to explicitly set events to the original context. + // Events from callback are emitted regardless of acknowledgement success + ctx.EventManager().EmitEvents(cacheCtx.EventManager().Events()) if ack == nil || ack.Success() { // write application state changes for asynchronous and successful acknowledgements writeFn() @@ -557,7 +561,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 +617,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 +671,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 }