Skip to content

Commit

Permalink
refactor: remove unnecessary decrement when fast forwarding upgrade s…
Browse files Browse the repository at this point in the history
…equence (#5231)

* update ChanUpgradeTry function

* update with Aditya's suggestion

* update with Carlos's review

* add check in test

* refactor: remove unnecessary - 1 on fast forward

---------

Co-authored-by: Charly <charly@interchain.berlin>
Co-authored-by: Đỗ Việt Hoàng <hoangdv2429@gmail.com>
Co-authored-by: Colin Axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
4 people authored Dec 13, 2023
1 parent 0323942 commit baa0318
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
15 changes: 7 additions & 8 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,19 @@ func (k Keeper) ChanUpgradeTry(
if found {
proposedUpgradeFields = upgrade.Fields
} else {
// if the counterparty sequence is greater than the current sequence, we fast-forward to the counterparty sequence.
if counterpartyUpgradeSequence > channel.UpgradeSequence {
// using -1 as WriteUpgradeInitChannel increments the sequence
channel.UpgradeSequence = counterpartyUpgradeSequence - 1
k.SetChannel(ctx, portID, channelID, channel)
}

// NOTE: OnChanUpgradeInit will not be executed by the application
upgrade, err = k.ChanUpgradeInit(ctx, portID, channelID, proposedUpgradeFields)
if err != nil {
return types.Channel{}, types.Upgrade{}, errorsmod.Wrap(err, "failed to initialize upgrade")
}

channel, upgrade = k.WriteUpgradeInitChannel(ctx, portID, channelID, upgrade, proposedUpgradeFields.Version)
channel, upgrade = k.WriteUpgradeInitChannel(ctx, portID, channelID, upgrade, upgrade.Fields.Version)

// if the counterparty sequence is greater than the current sequence, we fast-forward to the counterparty sequence.
if counterpartyUpgradeSequence > channel.UpgradeSequence {
channel.UpgradeSequence = counterpartyUpgradeSequence
k.SetChannel(ctx, portID, channelID, channel)
}
}

if err := k.checkForUpgradeCompatibility(ctx, proposedUpgradeFields, counterpartyUpgradeFields); err != nil {
Expand Down
1 change: 1 addition & 0 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ func (suite *KeeperTestSuite) TestChanUpgradeTry() {
suite.Require().NoError(err)
suite.Require().NotEmpty(upgrade)
suite.Require().Equal(proposedUpgrade.Fields, upgrade.Fields)
suite.Require().Equal(path.EndpointA.GetChannel().UpgradeSequence, path.EndpointB.GetChannel().UpgradeSequence)
} else {
suite.assertUpgradeError(err, tc.expError)
}
Expand Down

0 comments on commit baa0318

Please sign in to comment.