From c9ee6284d7ca985215a4d5b3e9db77cba92d1e92 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Thu, 21 Dec 2023 18:54:41 +0100 Subject: [PATCH] changes to avoid breaking API for channel upgradability (#5480) * changes to avoid breaking API for channel upgradability * fix: compiler errors --------- Co-authored-by: Damian Nolan --- modules/core/04-channel/keeper/handshake.go | 17 ++++++++++++++++ .../core/04-channel/keeper/handshake_test.go | 2 +- modules/core/04-channel/keeper/timeout.go | 20 +++++++++++++++++++ .../core/04-channel/keeper/timeout_test.go | 2 +- modules/core/keeper/msg_server.go | 4 ++-- 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/modules/core/04-channel/keeper/handshake.go b/modules/core/04-channel/keeper/handshake.go index ccb1633f98d..3aaad5a95d2 100644 --- a/modules/core/04-channel/keeper/handshake.go +++ b/modules/core/04-channel/keeper/handshake.go @@ -431,6 +431,23 @@ func (k Keeper) ChanCloseConfirm( chanCap *capabilitytypes.Capability, proofInit []byte, proofHeight exported.Height, +) error { + return k.ChanCloseConfirmWithCounterpartyUpgradeSequence(ctx, portID, channelID, chanCap, proofInit, proofHeight, 0) +} + +// ChanCloseConfirmWithCounterpartyUpgradeSequence is called by the counterparty module to +// close their end of the channel, since the other end has been closed. The difference with +// ChanCloseConfirm is that it accepts an extra argument counterpartyUpgradeSequence that was +// needed for channel upgradability. +// +// This function will be removed in ibc-go v9.0.0 and the API of ChanCloseConfirm will be updated. +func (k Keeper) ChanCloseConfirmWithCounterpartyUpgradeSequence( + ctx sdk.Context, + portID, + channelID string, + chanCap *capabilitytypes.Capability, + proofInit []byte, + proofHeight exported.Height, counterpartyUpgradeSequence uint64, ) error { if !k.scopedKeeper.AuthenticateCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)) { diff --git a/modules/core/04-channel/keeper/handshake_test.go b/modules/core/04-channel/keeper/handshake_test.go index 91ddf3baf5f..b38bc2d3ad9 100644 --- a/modules/core/04-channel/keeper/handshake_test.go +++ b/modules/core/04-channel/keeper/handshake_test.go @@ -829,7 +829,7 @@ func (suite *KeeperTestSuite) TestChanCloseConfirm() { channelKey := host.ChannelKey(path.EndpointA.ChannelConfig.PortID, ibctesting.FirstChannelID) proof, proofHeight := suite.chainA.QueryProof(channelKey) - err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.ChanCloseConfirm( + err := suite.chainB.App.GetIBCKeeper().ChannelKeeper.ChanCloseConfirmWithCounterpartyUpgradeSequence( suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, ibctesting.FirstChannelID, channelCap, proof, malleateHeight(proofHeight, heightDiff), counterpartyUpgradeSequence, ) diff --git a/modules/core/04-channel/keeper/timeout.go b/modules/core/04-channel/keeper/timeout.go index a0f7f189fa6..c99419cb77f 100644 --- a/modules/core/04-channel/keeper/timeout.go +++ b/modules/core/04-channel/keeper/timeout.go @@ -212,6 +212,26 @@ func (k Keeper) TimeoutOnClose( proofClosed []byte, proofHeight exported.Height, nextSequenceRecv uint64, +) error { + return k.TimeoutOnCloseWithCounterpartyUpgradeSequence(ctx, chanCap, packet, proof, proofClosed, proofHeight, nextSequenceRecv, 0) +} + +// TimeoutOnCloseWithCounterpartyUpgradeSequence is called by a module in order +// to prove that the channel to which an unreceived packet was addressed has +// been closed, so the packet will never be received (even if the timeoutHeight +// has not yet been reached). The difference with TimeoutOnClose is that it +// accepts an extra argument counterpartyUpgradeSequence that was needed for +// channel upgradability. +// +// This function will be removed in ibc-go v9.0.0 and the API of TimeoutOnClose will be updated. +func (k Keeper) TimeoutOnCloseWithCounterpartyUpgradeSequence( + ctx sdk.Context, + chanCap *capabilitytypes.Capability, + packet exported.PacketI, + proof, + proofClosed []byte, + proofHeight exported.Height, + nextSequenceRecv uint64, counterpartyUpgradeSequence uint64, ) error { channel, found := k.GetChannel(ctx, packet.GetSourcePort(), packet.GetSourceChannel()) diff --git a/modules/core/04-channel/keeper/timeout_test.go b/modules/core/04-channel/keeper/timeout_test.go index 27f6def9f85..2656469157d 100644 --- a/modules/core/04-channel/keeper/timeout_test.go +++ b/modules/core/04-channel/keeper/timeout_test.go @@ -767,7 +767,7 @@ func (suite *KeeperTestSuite) TestTimeoutOnClose() { proof, _ = suite.chainB.QueryProof(unorderedPacketKey) } - err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutOnClose( + err := suite.chainA.App.GetIBCKeeper().ChannelKeeper.TimeoutOnCloseWithCounterpartyUpgradeSequence( suite.chainA.GetContext(), chanCap, packet, diff --git a/modules/core/keeper/msg_server.go b/modules/core/keeper/msg_server.go index 9caa8d482ec..dfa2c0a9342 100644 --- a/modules/core/keeper/msg_server.go +++ b/modules/core/keeper/msg_server.go @@ -432,7 +432,7 @@ func (k Keeper) ChannelCloseConfirm(goCtx context.Context, msg *channeltypes.Msg return nil, errorsmod.Wrapf(err, "channel close confirm callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId) } - err = k.ChannelKeeper.ChanCloseConfirm(ctx, msg.PortId, msg.ChannelId, capability, msg.ProofInit, msg.ProofHeight, msg.CounterpartyUpgradeSequence) + err = k.ChannelKeeper.ChanCloseConfirmWithCounterpartyUpgradeSequence(ctx, msg.PortId, msg.ChannelId, capability, msg.ProofInit, msg.ProofHeight, msg.CounterpartyUpgradeSequence) if err != nil { ctx.Logger().Error("channel close confirm failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error()) return nil, errorsmod.Wrap(err, "channel handshake close confirm failed") @@ -622,7 +622,7 @@ func (k Keeper) TimeoutOnClose(goCtx context.Context, msg *channeltypes.MsgTimeo // If the timeout was already received, perform a no-op // Use a cached context to prevent accidental state changes cacheCtx, writeFn := ctx.CacheContext() - err = k.ChannelKeeper.TimeoutOnClose(cacheCtx, capability, msg.Packet, msg.ProofUnreceived, msg.ProofClose, msg.ProofHeight, msg.NextSequenceRecv, msg.CounterpartyUpgradeSequence) + err = k.ChannelKeeper.TimeoutOnCloseWithCounterpartyUpgradeSequence(cacheCtx, capability, msg.Packet, msg.ProofUnreceived, msg.ProofClose, msg.ProofHeight, msg.NextSequenceRecv, msg.CounterpartyUpgradeSequence) switch err { case nil: