diff --git a/CHANGELOG.md b/CHANGELOG.md index 76df07b3b76..34b9c2e0e64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking * (core, apps) [\#7213](https://github.com/cosmos/ibc-go/pull/7213) Remove capabilities from `SendPacket`. +* (core, apps) [\#7213](https://github.com/cosmos/ibc-go/pull/7225) Remove capabilities from `WriteAcknowledgement`. ### State Machine Breaking diff --git a/docs/docs/05-migrations/14-v9-to-v10.md b/docs/docs/05-migrations/14-v9-to-v10.md index 39f6d2effae..2e257f1b16c 100644 --- a/docs/docs/05-migrations/14-v9-to-v10.md +++ b/docs/docs/05-migrations/14-v9-to-v10.md @@ -19,6 +19,7 @@ There are four sections based on the four potential user groups of this document ## IBC Apps - (TODO: expand later) Removal of capabilities in `SendPacket` [\#7213](https://github.com/cosmos/ibc-go/pull/7213). +- (TODO: expand later) Removal of capabilities in `WriteAcknowledgement` [\#7225](https://github.com/cosmos/ibc-go/pull/7213). ### ICS27 - Interchain Accounts diff --git a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go index f3c58ba59d0..c697d86dc90 100644 --- a/modules/apps/27-interchain-accounts/controller/ibc_middleware.go +++ b/modules/apps/27-interchain-accounts/controller/ibc_middleware.go @@ -338,7 +338,6 @@ func (IBCMiddleware) SendPacket( // WriteAcknowledgement implements the ICS4 Wrapper interface func (IBCMiddleware) WriteAcknowledgement( ctx context.Context, - chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, ack ibcexported.Acknowledgement, ) error { diff --git a/modules/apps/29-fee/ibc_middleware.go b/modules/apps/29-fee/ibc_middleware.go index 029bc7cd98c..58a12f00511 100644 --- a/modules/apps/29-fee/ibc_middleware.go +++ b/modules/apps/29-fee/ibc_middleware.go @@ -471,11 +471,10 @@ func (im IBCMiddleware) SendPacket( // WriteAcknowledgement implements the ICS4 Wrapper interface func (im IBCMiddleware) WriteAcknowledgement( ctx context.Context, - chanCap *capabilitytypes.Capability, packet exported.PacketI, ack exported.Acknowledgement, ) error { - return im.keeper.WriteAcknowledgement(ctx, chanCap, packet, ack) + return im.keeper.WriteAcknowledgement(ctx, packet, ack) } // GetAppVersion returns the application version of the underlying application diff --git a/modules/apps/29-fee/keeper/relay.go b/modules/apps/29-fee/keeper/relay.go index 20e1746bdb8..2fe2e2b70c4 100644 --- a/modules/apps/29-fee/keeper/relay.go +++ b/modules/apps/29-fee/keeper/relay.go @@ -6,7 +6,6 @@ import ( errorsmod "cosmossdk.io/errors" - capabilitytypes "github.com/cosmos/ibc-go/modules/capability/types" "github.com/cosmos/ibc-go/v9/modules/apps/29-fee/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" @@ -27,10 +26,10 @@ func (k Keeper) SendPacket( // WriteAcknowledgement wraps IBC ChannelKeeper's WriteAcknowledgement function // ICS29 WriteAcknowledgement is used for asynchronous acknowledgements -func (k Keeper) WriteAcknowledgement(ctx context.Context, chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error { +func (k Keeper) WriteAcknowledgement(ctx context.Context, packet ibcexported.PacketI, acknowledgement ibcexported.Acknowledgement) error { if !k.IsFeeEnabled(ctx, packet.GetDestPort(), packet.GetDestChannel()) { // ics4Wrapper may be core IBC or higher-level middleware - return k.ics4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, acknowledgement) + return k.ics4Wrapper.WriteAcknowledgement(ctx, packet, acknowledgement) } packetID := channeltypes.NewPacketID(packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence()) @@ -50,7 +49,7 @@ func (k Keeper) WriteAcknowledgement(ctx context.Context, chanCap *capabilitytyp k.DeleteForwardRelayerAddress(ctx, packetID) // ics4Wrapper may be core IBC or higher-level middleware - return k.ics4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, ack) + return k.ics4Wrapper.WriteAcknowledgement(ctx, packet, ack) } // GetAppVersion returns the underlying application version. diff --git a/modules/apps/29-fee/keeper/relay_test.go b/modules/apps/29-fee/keeper/relay_test.go index 1902c3fa5f5..4bffcedc0d3 100644 --- a/modules/apps/29-fee/keeper/relay_test.go +++ b/modules/apps/29-fee/keeper/relay_test.go @@ -54,12 +54,11 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsync() { ) ack := channeltypes.NewResultAcknowledgement([]byte("success")) - chanCap := suite.chainB.GetChannelCapability(suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID) // malleate test case tc.malleate() - err := suite.chainB.GetSimApp().IBCFeeKeeper.WriteAcknowledgement(suite.chainB.GetContext(), chanCap, packet, ack) + err := suite.chainB.GetSimApp().IBCFeeKeeper.WriteAcknowledgement(suite.chainB.GetContext(), packet, ack) if tc.expErr == nil { suite.Require().NoError(err) @@ -95,9 +94,8 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgementAsyncFeeDisabled() { ) ack := channeltypes.NewResultAcknowledgement([]byte("success")) - chanCap := suite.chainB.GetChannelCapability(suite.path.EndpointB.ChannelConfig.PortID, suite.path.EndpointB.ChannelID) - err := suite.chainB.GetSimApp().IBCFeeKeeper.WriteAcknowledgement(suite.chainB.GetContext(), chanCap, packet, ack) + err := suite.chainB.GetSimApp().IBCFeeKeeper.WriteAcknowledgement(suite.chainB.GetContext(), packet, ack) suite.Require().NoError(err) packetAck, _ := suite.chainB.GetSimApp().GetIBCKeeper().ChannelKeeper.GetPacketAcknowledgement(suite.chainB.GetContext(), packet.DestinationPort, packet.DestinationChannel, 1) diff --git a/modules/apps/callbacks/ibc_middleware.go b/modules/apps/callbacks/ibc_middleware.go index fb4e53b999f..74b6f44a237 100644 --- a/modules/apps/callbacks/ibc_middleware.go +++ b/modules/apps/callbacks/ibc_middleware.go @@ -246,11 +246,10 @@ func (im IBCMiddleware) OnRecvPacket(ctx context.Context, channelVersion string, // reverted via a panic. func (im IBCMiddleware) WriteAcknowledgement( ctx context.Context, - chanCap *capabilitytypes.Capability, packet ibcexported.PacketI, ack ibcexported.Acknowledgement, ) error { - err := im.ics4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, ack) + err := im.ics4Wrapper.WriteAcknowledgement(ctx, packet, ack) if err != nil { return err } diff --git a/modules/apps/callbacks/ibc_middleware_test.go b/modules/apps/callbacks/ibc_middleware_test.go index abf445ef7b5..ea81587414d 100644 --- a/modules/apps/callbacks/ibc_middleware_test.go +++ b/modules/apps/callbacks/ibc_middleware_test.go @@ -810,14 +810,12 @@ func (s *CallbacksTestSuite) TestWriteAcknowledgement() { ctx = s.chainB.GetContext() gasLimit := ctx.GasMeter().Limit() - chanCap := s.chainB.GetChannelCapability(s.path.EndpointB.ChannelConfig.PortID, s.path.EndpointB.ChannelID) - tc.malleate() // callbacks module is routed as top level middleware transferICS4Wrapper := GetSimApp(s.chainB).TransferKeeper.GetICS4Wrapper() - err := transferICS4Wrapper.WriteAcknowledgement(ctx, chanCap, packet, ack) + err := transferICS4Wrapper.WriteAcknowledgement(ctx, packet, ack) expPass := tc.expError == nil s.AssertHasExecutedExpectedCallback(tc.callbackType, expPass) diff --git a/modules/apps/transfer/keeper/forwarding.go b/modules/apps/transfer/keeper/forwarding.go index 656fbb75c4a..cb68b9d919a 100644 --- a/modules/apps/transfer/keeper/forwarding.go +++ b/modules/apps/transfer/keeper/forwarding.go @@ -10,7 +10,6 @@ import ( "github.com/cosmos/ibc-go/v9/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v9/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v9/modules/core/04-channel/types" - host "github.com/cosmos/ibc-go/v9/modules/core/24-host" ibcerrors "github.com/cosmos/ibc-go/v9/modules/core/errors" ) @@ -48,13 +47,7 @@ func (k Keeper) forwardPacket(ctx context.Context, data types.FungibleTokenPacke // acknowledgeForwardedPacket writes the async acknowledgement for forwardedPacket func (k Keeper) acknowledgeForwardedPacket(ctx context.Context, forwardedPacket, packet channeltypes.Packet, ack channeltypes.Acknowledgement) error { - sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - capability, ok := k.scopedKeeper.GetCapability(sdkCtx, host.ChannelCapabilityPath(forwardedPacket.DestinationPort, forwardedPacket.DestinationChannel)) - if !ok { - return errorsmod.Wrap(channeltypes.ErrChannelCapabilityNotFound, "module does not own channel capability") - } - - if err := k.ics4Wrapper.WriteAcknowledgement(ctx, capability, forwardedPacket, ack); err != nil { + if err := k.ics4Wrapper.WriteAcknowledgement(ctx, forwardedPacket, ack); err != nil { return err } diff --git a/modules/core/04-channel/keeper/packet.go b/modules/core/04-channel/keeper/packet.go index 2484aa2885f..f4a955aa34f 100644 --- a/modules/core/04-channel/keeper/packet.go +++ b/modules/core/04-channel/keeper/packet.go @@ -290,7 +290,6 @@ func (k *Keeper) applyReplayProtection(ctx sdk.Context, packet types.Packet, cha // previously by RecvPacket. func (k *Keeper) WriteAcknowledgement( ctx context.Context, - chanCap *capabilitytypes.Capability, packet exported.PacketI, acknowledgement exported.Acknowledgement, ) error { @@ -303,15 +302,7 @@ func (k *Keeper) WriteAcknowledgement( return errorsmod.Wrapf(types.ErrInvalidChannelState, "expected one of [%s, %s, %s], got %s", types.OPEN, types.FLUSHING, types.FLUSHCOMPLETE, channel.State) } - // Authenticate capability to ensure caller has authority to receive packet on this channel - capName := host.ChannelCapabilityPath(packet.GetDestPort(), packet.GetDestChannel()) sdkCtx := sdk.UnwrapSDKContext(ctx) // TODO: https://github.com/cosmos/ibc-go/issues/5917 - if !k.scopedKeeper.AuthenticateCapability(sdkCtx, chanCap, capName) { - return errorsmod.Wrapf( - types.ErrInvalidChannelCapability, - "channel capability failed authentication for capability name %s", capName, - ) - } // REPLAY PROTECTION: The recvStartSequence will prevent historical proofs from allowing replay // attacks on packets processed in previous lifecycles of a channel. After a successful channel diff --git a/modules/core/04-channel/keeper/packet_test.go b/modules/core/04-channel/keeper/packet_test.go index a1f5baab896..b5c2c480e75 100644 --- a/modules/core/04-channel/keeper/packet_test.go +++ b/modules/core/04-channel/keeper/packet_test.go @@ -667,10 +667,9 @@ func (suite *KeeperTestSuite) TestRecvPacket() { func (suite *KeeperTestSuite) TestWriteAcknowledgement() { var ( - path *ibctesting.Path - ack exported.Acknowledgement - packet exported.PacketI - channelCap *capabilitytypes.Capability + path *ibctesting.Path + ack exported.Acknowledgement + packet exported.PacketI ) testCases := []testCase{ @@ -680,7 +679,6 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, true, }, @@ -692,7 +690,6 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { ack = ibcmock.MockAcknowledgement path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHING }) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, true, }, @@ -704,7 +701,6 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { ack = ibcmock.MockAcknowledgement path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.FLUSHCOMPLETE }) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, true, }, @@ -713,7 +709,6 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, ibctesting.InvalidID, ibctesting.InvalidID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, {"channel not open", func() { path.Setup() @@ -721,18 +716,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { ack = ibcmock.MockAcknowledgement path.EndpointB.UpdateChannel(func(channel *types.Channel) { channel.State = types.CLOSED }) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false}, - { - "capability authentication failed", - func() { - path.Setup() - packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - ack = ibcmock.MockAcknowledgement - channelCap = capabilitytypes.NewCapability(3) - }, - false, - }, { "no-op, already acked", func() { @@ -740,7 +724,6 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.MockAcknowledgement suite.chainB.App.GetIBCKeeper().ChannelKeeper.SetPacketAcknowledgement(suite.chainB.GetContext(), packet.GetDestPort(), packet.GetDestChannel(), packet.GetSequence(), ack.Acknowledgement()) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false, }, @@ -750,7 +733,6 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = ibcmock.NewEmptyAcknowledgement() - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false, }, @@ -760,7 +742,6 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { path.Setup() packet = types.NewPacket(ibctesting.MockPacketData, 1, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) ack = nil - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) }, false, }, @@ -772,7 +753,6 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { sequence, err := path.EndpointA.SendPacket(defaultTimeoutHeight, disabledTimeoutTimestamp, ibctesting.MockPacketData) suite.Require().NoError(err) packet = types.NewPacket(ibctesting.MockPacketData, sequence, path.EndpointA.ChannelConfig.PortID, path.EndpointA.ChannelID, path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, defaultTimeoutHeight, disabledTimeoutTimestamp) - channelCap = suite.chainB.GetChannelCapability(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID) ack = ibcmock.MockAcknowledgement // set recv seq start to indicate packet was processed in previous upgrade @@ -789,7 +769,7 @@ func (suite *KeeperTestSuite) TestWriteAcknowledgement() { tc.malleate() - err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.WriteAcknowledgement(suite.chainB.GetContext(), channelCap, packet, ack) + err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.WriteAcknowledgement(suite.chainB.GetContext(), packet, ack) if tc.expPass { suite.Require().NoError(err) diff --git a/modules/core/05-port/types/module.go b/modules/core/05-port/types/module.go index 1d3d6441d7a..a9f2f52ebcc 100644 --- a/modules/core/05-port/types/module.go +++ b/modules/core/05-port/types/module.go @@ -175,7 +175,6 @@ type ICS4Wrapper interface { WriteAcknowledgement( ctx context.Context, - chanCap *capabilitytypes.Capability, packet exported.PacketI, ack exported.Acknowledgement, ) error diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 046271e3b39..5cb274b0133 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -492,7 +492,7 @@ func (k *Keeper) RecvPacket(goCtx context.Context, msg *channeltypes.MsgRecvPack // NOTE: IBC applications modules may call the WriteAcknowledgement asynchronously if the // acknowledgement is nil. if ack != nil { - if err := k.ChannelKeeper.WriteAcknowledgement(ctx, capability, msg.Packet, ack); err != nil { + if err := k.ChannelKeeper.WriteAcknowledgement(ctx, msg.Packet, ack); err != nil { return nil, err } } diff --git a/testing/endpoint.go b/testing/endpoint.go index 362b5f400c6..1426a386261 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -493,10 +493,8 @@ func (endpoint *Endpoint) RecvPacketWithResult(packet channeltypes.Packet) (*abc // WriteAcknowledgement writes an acknowledgement on the channel associated with the endpoint. // The counterparty client is updated. func (endpoint *Endpoint) WriteAcknowledgement(ack exported.Acknowledgement, packet exported.PacketI) error { - channelCap := endpoint.Chain.GetChannelCapability(packet.GetDestPort(), packet.GetDestChannel()) - // no need to send message, acting as a handler - err := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.WriteAcknowledgement(endpoint.Chain.GetContext(), channelCap, packet, ack) + err := endpoint.Chain.App.GetIBCKeeper().ChannelKeeper.WriteAcknowledgement(endpoint.Chain.GetContext(), packet, ack) if err != nil { return err } diff --git a/testing/mock/middleware.go b/testing/mock/middleware.go index 6cf2b0ba32e..7a62ffd0ff4 100644 --- a/testing/mock/middleware.go +++ b/testing/mock/middleware.go @@ -189,7 +189,6 @@ func (BlockUpgradeMiddleware) SendPacket( // WriteAcknowledgement implements the ICS4 Wrapper interface func (BlockUpgradeMiddleware) WriteAcknowledgement( ctx context.Context, - chanCap *capabilitytypes.Capability, packet exported.PacketI, ack exported.Acknowledgement, ) error {