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

Move check to fail on incompatible upgrade after proof verification. #4320

Merged
Merged
18 changes: 9 additions & 9 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,6 @@ func (k Keeper) ChanUpgradeAck(
FlushStatus: counterpartyFlushStatus, // provided by the relayer
}

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)
}

if err := k.checkForUpgradeCompatibility(ctx, upgrade.Fields, counterpartyUpgrade); err != nil {
return types.NewUpgradeError(channel.UpgradeSequence, err)
}

// verify the counterparty channel state containing the upgrade sequence
if err := k.connectionKeeper.VerifyChannelState(
ctx,
Expand All @@ -312,6 +303,15 @@ func (k Keeper) ChanUpgradeAck(
return errorsmod.Wrap(err, "failed to verify counterparty upgrade")
}

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)
}

if err := k.checkForUpgradeCompatibility(ctx, upgrade.Fields, counterpartyUpgrade); err != nil {
return types.NewUpgradeError(channel.UpgradeSequence, err)
}

if err := k.startFlushUpgradeHandshake(ctx, portID, channelID, upgrade.Fields, counterpartyChannel, counterpartyUpgrade,
proofChannel, proofUpgrade, proofHeight); err != nil {
return err
Expand Down
8 changes: 8 additions & 0 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,15 @@ func (suite *KeeperTestSuite) TestChanUpgradeAck() {
{
"fails due to upgrade incompatibility",
func() {
// Need to set counterparty upgrade in state and update clients to ensure
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've done a similar thing for the timeout in #4305, lmk if there's a better way to go about it

// proofs submitted reflect the altered upgrade.
counterpartyUpgrade.Fields.ConnectionHops = []string{ibctesting.InvalidID}
path.EndpointB.SetChannelUpgrade(counterpartyUpgrade)

err := path.EndpointB.UpdateClient()
suite.Require().NoError(err)
err = path.EndpointA.UpdateClient()
suite.Require().NoError(err)
crodriguezvega marked this conversation as resolved.
Show resolved Hide resolved
},
types.NewUpgradeError(1, types.ErrIncompatibleCounterpartyUpgrade),
},
Expand Down