From fcd8ded85b0f2019fefca4e5af59343700760e5b Mon Sep 17 00:00:00 2001 From: Jim Fasarakis-Hilliard Date: Wed, 12 Jul 2023 09:51:13 +0300 Subject: [PATCH] Pass in counterparty portID, channelID when verifying channel in ChanUpgradeOpen. (#4052) * Pass in counterparty portid, channelid. * use direct check on err. * Force distinct channel identifiers when testing UpgradeOpen. --- modules/core/04-channel/keeper/upgrade.go | 12 +++++++++--- modules/core/04-channel/keeper/upgrade_test.go | 8 ++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 9d50031ab13..a07c2730076 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -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) { @@ -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()) } diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index 9ff671d4541..5130f23d45d 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -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() {