Skip to content

Commit

Permalink
changes to avoid breaking API for channel upgradability (#5480)
Browse files Browse the repository at this point in the history
* changes to avoid breaking API for channel upgradability

* fix: compiler errors

---------

Co-authored-by: Damian Nolan <damiannolan@gmail.com>
  • Loading branch information
crodriguezvega and damiannolan authored Dec 21, 2023
1 parent 5392565 commit c9ee628
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
17 changes: 17 additions & 0 deletions modules/core/04-channel/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/handshake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
20 changes: 20 additions & 0 deletions modules/core/04-channel/keeper/timeout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion modules/core/04-channel/keeper/timeout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit c9ee628

Please sign in to comment.