Skip to content

Commit

Permalink
fix(state!): check upgrade compatibility in channel upgrade confirm (#…
Browse files Browse the repository at this point in the history
…6935)

(cherry picked from commit 3a192be)
  • Loading branch information
crodriguezvega authored and mergify[bot] committed Jul 25, 2024
1 parent ab46eb5 commit 6c8fc36
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

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

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

Expand Down
15 changes: 15 additions & 0 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,21 @@ func (k *Keeper) ChanUpgradeConfirm(
return errorsmod.Wrap(err, "failed to verify counterparty upgrade")
}

// if we have cancelled our upgrade after performing UpgradeInit,
// UpgradeTry or UpgradeAck, the lack of a stored upgrade will prevent
// us from continuing the upgrade handshake
upgrade, found := k.GetUpgrade(ctx, portID, channelID)
if !found {
return errorsmod.Wrapf(types.ErrUpgradeNotFound, "failed to retrieve channel upgrade: port ID (%s) channel ID (%s)", portID, channelID)
}

// in the crossing-hello case it is possible that both chains execute the
// INIT, TRY and CONFIRM steps without any of them executing ACK, therefore
// we also need to check that the upgrades are compatible on this step
if err := k.checkForUpgradeCompatibility(ctx, upgrade.Fields, counterpartyUpgrade.Fields); err != nil {
return types.NewUpgradeError(channel.UpgradeSequence, err)
}

timeout := counterpartyUpgrade.Timeout
selfHeight, selfTimestamp := clienttypes.GetSelfHeight(ctx), uint64(ctx.BlockTime().UnixNano())

Expand Down
21 changes: 21 additions & 0 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,27 @@ func (suite *KeeperTestSuite) TestChanUpgradeConfirm() {
},
types.NewUpgradeError(1, types.ErrTimeoutElapsed),
},
{
"upgrade not found",
func() {
path.EndpointB.Chain.DeleteKey(host.ChannelUpgradeKey(path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID))
},
types.ErrUpgradeNotFound,
},
{
"upgrades are not compatible",
func() {
// the expected upgrade version is mock-version-v2
counterpartyUpgrade.Fields.Version = fmt.Sprintf("%s-v3", mock.Version)
path.EndpointA.SetChannelUpgrade(counterpartyUpgrade)

suite.coordinator.CommitBlock(suite.chainA)

err := path.EndpointB.UpdateClient()
suite.Require().NoError(err)
},
types.NewUpgradeError(1, types.ErrIncompatibleCounterpartyUpgrade),
},
}

for _, tc := range testCases {
Expand Down

0 comments on commit 6c8fc36

Please sign in to comment.