Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(state!): check upgrade compatibility in channel upgrade confirm (backport #6935) #6944

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Bug Fixes

* (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

### Dependencies
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 @@ -448,6 +448,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 @@ -1124,6 +1124,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
Loading