Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (apps/callbacks) [\#9079](https://github.com/cosmos/ibc-go/pull/9079) Pass the raw application acknowledgement bytes to the destination callback in the IBC v2 asynchronous `WriteAcknowledgement` path, matching the synchronous `OnRecvPacket` path (previously the contract received a protobuf-encoded `channeltypesv2.Acknowledgement` wrapper).
* (core/02-client) [\#9080](https://github.com/cosmos/ibc-go/pull/9080) Return an error from `RecoverClient` when the substitute client is of a different client type than the subject instead of panicking in the subject light client module.
* (apps/pfm) [\#9006](https://github.com/cosmos/ibc-go/pull/9006) fix(apps/pfm): remove legacy params before the v3 to v4 migration
* (apps/rate-limiting) [\#8767](https://github.com/cosmos/ibc-go/pull/8767) Fix string conflict in rate-limiting prefix iterator
Expand Down
17 changes: 5 additions & 12 deletions modules/apps/callbacks/v2/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,6 @@ func (im *IBCMiddleware) WriteAcknowledgement(
return err
}

recvResult := channeltypesv2.RecvPacketResult{
Status: channeltypesv2.PacketStatus_Success,
Acknowledgement: ack.AppAcknowledgements[0],
}
callbackExecutor := func(cachedCtx sdk.Context) error {
// reconstruct a channel v1 packet from the v2 packet
// in order to preserve the same interface for the contract keeper
Expand All @@ -434,15 +430,12 @@ func (im *IBCMiddleware) WriteAcknowledgement(
TimeoutHeight: clienttypes.Height{},
TimeoutTimestamp: 0,
}
// wrap the individual acknowledgement into the channeltypesv2.Acknowledgement since it implements the exported.Acknowledgement interface
var ack channeltypesv2.Acknowledgement
if recvResult.Status == channeltypesv2.PacketStatus_Failure {
ack = channeltypesv2.NewAcknowledgement(channeltypesv2.ErrorAcknowledgement[:])
} else {
ack = channeltypesv2.NewAcknowledgement(recvResult.Acknowledgement)
}
// The contract must observe the same acknowledgement representation regardless
// of whether the acknowledgement was written synchronously in OnRecvPacket or
// asynchronously here: the raw application acknowledgement bytes.
recvAck := RecvAcknowledgement(ack.AppAcknowledgements[0])
return im.contractKeeper.IBCReceivePacketCallback(
cachedCtx, packetv1, ack, cbData.CallbackAddress, payload.Version,
cachedCtx, packetv1, recvAck, cbData.CallbackAddress, payload.Version,
)
}

Expand Down
51 changes: 51 additions & 0 deletions modules/apps/callbacks/v2/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
channeltypesv2 "github.com/lfdt-ibc/ibc-go/v11/modules/core/04-channel/v2/types"
"github.com/lfdt-ibc/ibc-go/v11/modules/core/api"
ibcerrors "github.com/lfdt-ibc/ibc-go/v11/modules/core/errors"
ibcexported "github.com/lfdt-ibc/ibc-go/v11/modules/core/exported"
ibctesting "github.com/lfdt-ibc/ibc-go/v11/testing"
ibcmock "github.com/lfdt-ibc/ibc-go/v11/testing/mock"
ibcmockv2 "github.com/lfdt-ibc/ibc-go/v11/testing/mock/v2"
Expand Down Expand Up @@ -852,3 +853,53 @@ func (s *CallbacksTestSuite) TestWriteAcknowledgement() {
})
}
}

// TestWriteAcknowledgementCallbackAckMatchesSyncPath ensures that a contract
// receives the same acknowledgement representation (the raw application
// acknowledgement bytes) whether the acknowledgement is written synchronously
// via OnRecvPacket or asynchronously via WriteAcknowledgement.
func (s *CallbacksTestSuite) TestWriteAcknowledgementCallbackAckMatchesSyncPath() {
s.SetupTest()

packetData := transfertypes.NewFungibleTokenPacketData(
ibctesting.TestCoin.Denom,
ibctesting.TestCoin.Amount.String(),
ibctesting.TestAccAddress,
s.chainB.SenderAccount.GetAddress().String(),
fmt.Sprintf(`{"dest_callback": {"address":"%s", "gas_limit":"600000"}}`, ibctesting.TestAccAddress),
)
payload := channeltypesv2.NewPayload(
transfertypes.PortID, transfertypes.PortID,
transfertypes.V1, transfertypes.EncodingJSON,
packetData.GetBytes(),
)

var receivedAcks [][]byte
GetSimApp(s.chainB).MockContractKeeper.IBCReceivePacketCallbackFn = func(
_ sdk.Context, _ ibcexported.PacketI, ack ibcexported.Acknowledgement, _, _ string,
) error {
receivedAcks = append(receivedAcks, ack.Acknowledgement())
return nil
}

cbs := s.chainB.App.GetIBCKeeper().ChannelKeeperV2.Router.Route(ibctesting.TransferPort)
mw, ok := cbs.(api.WriteAcknowledgementWrapper)
s.Require().True(ok)

// synchronous path
ctx := s.chainB.GetContext()
res := cbs.OnRecvPacket(ctx, s.path.EndpointA.ClientID, s.path.EndpointB.ClientID, 1, payload, s.chainB.SenderAccount.GetAddress())
s.Require().Equal(channeltypesv2.PacketStatus_Success, res.Status)
s.Require().Len(receivedAcks, 1)
s.Require().Equal(res.Acknowledgement, receivedAcks[0])

// asynchronous path with the same application acknowledgement
packet := channeltypesv2.NewPacket(2, s.path.EndpointA.ClientID, s.path.EndpointB.ClientID, uint64(ctx.BlockTime().Unix()), payload)
s.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetAsyncPacket(ctx, packet.DestinationClient, packet.Sequence, packet)
s.chainB.App.GetIBCKeeper().ChannelKeeperV2.SetPacketReceipt(ctx, packet.DestinationClient, packet.Sequence)

err := mw.WriteAcknowledgement(ctx, packet.DestinationClient, packet.Sequence, channeltypesv2.NewAcknowledgement(res.Acknowledgement))
s.Require().NoError(err)
s.Require().Len(receivedAcks, 2)
s.Require().Equal(receivedAcks[0], receivedAcks[1], "async callback must receive the same acknowledgement bytes as the sync callback")
}