Skip to content

Commit cdaaa94

Browse files
fix(state!): check upgrade compatibility in channel upgrade confirm (backport #6935) (#6944)
* fix(state!): check upgrade compatibility in channel upgrade confirm (#6935) (cherry picked from commit 3a192be) # Conflicts: # CHANGELOG.md * fix conflicts --------- Co-authored-by: Carlos Rodriguez <[email protected]>
1 parent babe971 commit cdaaa94

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
5050

5151
### Bug Fixes
5252

53+
* (core/04-channel) [\#6935](https://github.com/cosmos/ibc-go/pull/6935) Check upgrade compatibility in `ChanUpgradeConfirm`.
54+
5355
## [v8.3.2](https://github.com/cosmos/ibc-go/releases/tag/v8.3.2) - 2024-06-20
5456

5557
### Dependencies

modules/core/04-channel/keeper/upgrade.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,21 @@ func (k Keeper) ChanUpgradeConfirm(
448448
return errorsmod.Wrap(err, "failed to verify counterparty upgrade")
449449
}
450450

451+
// if we have cancelled our upgrade after performing UpgradeInit,
452+
// UpgradeTry or UpgradeAck, the lack of a stored upgrade will prevent
453+
// us from continuing the upgrade handshake
454+
upgrade, found := k.GetUpgrade(ctx, portID, channelID)
455+
if !found {
456+
return errorsmod.Wrapf(types.ErrUpgradeNotFound, "failed to retrieve channel upgrade: port ID (%s) channel ID (%s)", portID, channelID)
457+
}
458+
459+
// in the crossing-hello case it is possible that both chains execute the
460+
// INIT, TRY and CONFIRM steps without any of them executing ACK, therefore
461+
// we also need to check that the upgrades are compatible on this step
462+
if err := k.checkForUpgradeCompatibility(ctx, upgrade.Fields, counterpartyUpgrade.Fields); err != nil {
463+
return types.NewUpgradeError(channel.UpgradeSequence, err)
464+
}
465+
451466
timeout := counterpartyUpgrade.Timeout
452467
selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano())
453468

modules/core/04-channel/keeper/upgrade_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,6 +1124,27 @@ func (suite *KeeperTestSuite) TestChanUpgradeConfirm() {
11241124
},
11251125
types.NewUpgradeError(1, types.ErrTimeoutElapsed),
11261126
},
1127+
{
1128+
"upgrade not found",
1129+
func() {
1130+
path.EndpointB.Chain.DeleteKey(host.ChannelUpgradeKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID))
1131+
},
1132+
types.ErrUpgradeNotFound,
1133+
},
1134+
{
1135+
"upgrades are not compatible",
1136+
func() {
1137+
// the expected upgrade version is mock-version-v2
1138+
counterpartyUpgrade.Fields.Version = fmt.Sprintf("%s-v3", mock.Version)
1139+
path.EndpointA.SetChannelUpgrade(counterpartyUpgrade)
1140+
1141+
suite.coordinator.CommitBlock(suite.chainA)
1142+
1143+
err := path.EndpointB.UpdateClient()
1144+
suite.Require().NoError(err)
1145+
},
1146+
types.NewUpgradeError(1, types.ErrIncompatibleCounterpartyUpgrade),
1147+
},
11271148
}
11281149

11291150
for _, tc := range testCases {

0 commit comments

Comments
 (0)