Skip to content

Commit

Permalink
Pass in counterparty portID, channelID when verifying channel in Chan…
Browse files Browse the repository at this point in the history
…UpgradeOpen. (#4052)

* Pass in counterparty portid, channelid.

* use direct check on err.

* Force distinct channel identifiers when testing UpgradeOpen.
  • Loading branch information
DimitrisJim committed Jul 12, 2023
1 parent ef239b4 commit fcd8ded
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 9 additions & 3 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (k Keeper) ChanUpgradeOpen(
portID,
channelID string,
counterpartyChannelState types.State,
proofChannel []byte,
proofCounterpartyChannel []byte,
proofHeight clienttypes.Height,
) error {
if k.hasInflightPackets(ctx, portID, channelID) {
Expand Down Expand Up @@ -397,8 +397,14 @@ func (k Keeper) ChanUpgradeOpen(
panic(fmt.Sprintf("counterparty channel state should be in one of [%s, %s, %s]; got %s", types.TRYUPGRADE, types.ACKUPGRADE, types.OPEN, counterpartyChannelState))
}

err = k.connectionKeeper.VerifyChannelState(ctx, connection, proofHeight, proofChannel, portID, channelID, counterpartyChannel)
if err != nil {
if err = k.connectionKeeper.VerifyChannelState(
ctx,
connection,
proofHeight, proofCounterpartyChannel,
channel.Counterparty.PortId,
channel.Counterparty.ChannelId,
counterpartyChannel,
); err != nil {
return errorsmod.Wrapf(err, "failed to verify counterparty channel, expected counterparty channel state: %s", counterpartyChannel.String())
}

Expand Down
8 changes: 8 additions & 0 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,14 @@ func (suite *KeeperTestSuite) TestChanUpgradeOpen() {
},
}

// Create an initial path used only to invoke a ChanOpenInit handshake.
// This bumps the channel identifier generated for chain A on the
// next path used to run the upgrade handshake.
// See issue 4062.
path = ibctesting.NewPath(suite.chainA, suite.chainB)
suite.coordinator.SetupConnections(path)
suite.Require().NoError(path.EndpointA.ChanOpenInit())

for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
Expand Down

0 comments on commit fcd8ded

Please sign in to comment.