Skip to content

Commit 3a192be

Browse files
fix(state!): check upgrade compatibility in channel upgrade confirm (cosmos#6935)
1 parent 428118e commit 3a192be

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
9494
### Bug Fixes
9595

9696
* (apps/27-interchain-accounts) [\#6377](https://github.com/cosmos/ibc-go/pull/6377) Generate ICA simtest proposals only for provided keepers.
97+
* (core/04-channel) [\#6935](https://github.com/cosmos/ibc-go/pull/6935) Check upgrade compatibility in `ChanUpgradeConfirm`.
9798

9899
## [v8.3.2](https://github.com/cosmos/ibc-go/releases/tag/v8.3.2) - 2024-06-20
99100

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

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

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

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,27 @@ func (suite *KeeperTestSuite) TestChanUpgradeConfirm() {
10731073
},
10741074
types.NewUpgradeError(1, types.ErrTimeoutElapsed),
10751075
},
1076+
{
1077+
"upgrade not found",
1078+
func() {
1079+
path.EndpointB.Chain.DeleteKey(host.ChannelUpgradeKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID))
1080+
},
1081+
types.ErrUpgradeNotFound,
1082+
},
1083+
{
1084+
"upgrades are not compatible",
1085+
func() {
1086+
// the expected upgrade version is mock-version-v2
1087+
counterpartyUpgrade.Fields.Version = fmt.Sprintf("%s-v3", mock.Version)
1088+
path.EndpointA.SetChannelUpgrade(counterpartyUpgrade)
1089+
1090+
suite.coordinator.CommitBlock(suite.chainA)
1091+
1092+
err := path.EndpointB.UpdateClient()
1093+
suite.Require().NoError(err)
1094+
},
1095+
types.NewUpgradeError(1, types.ErrIncompatibleCounterpartyUpgrade),
1096+
},
10761097
}
10771098

10781099
for _, tc := range testCases {

0 commit comments

Comments
 (0)