From 05dd7d0c9c2557f8ad7b39a16e7061f50ebd87d0 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Mon, 1 Jan 2024 20:20:48 +0100 Subject: [PATCH] chore: remove `syncUpgradeSequence` (#5489) * chore: remove syncUpgradeSequence * remove unused import --- modules/core/04-channel/keeper/export_test.go | 5 -- modules/core/04-channel/keeper/upgrade.go | 20 ------- .../core/04-channel/keeper/upgrade_test.go | 58 ------------------- 3 files changed, 83 deletions(-) diff --git a/modules/core/04-channel/keeper/export_test.go b/modules/core/04-channel/keeper/export_test.go index 21fad92d9dd..a1ecb519716 100644 --- a/modules/core/04-channel/keeper/export_test.go +++ b/modules/core/04-channel/keeper/export_test.go @@ -25,11 +25,6 @@ func (k Keeper) CheckForUpgradeCompatibility(ctx sdk.Context, upgradeFields, cou return k.checkForUpgradeCompatibility(ctx, upgradeFields, counterpartyUpgradeFields) } -// SyncUpgradeSequence is a wrapper around syncUpgradeSequence to allow the function to be directly called in tests. -func (k Keeper) SyncUpgradeSequence(ctx sdk.Context, portID, channelID string, channel types.Channel, counterpartyUpgradeSequence uint64) error { - return k.syncUpgradeSequence(ctx, portID, channelID, channel, counterpartyUpgradeSequence) -} - // WriteErrorReceipt is a wrapper around writeErrorReceipt to allow the function to be directly called in tests. func (k Keeper) WriteErrorReceipt(ctx sdk.Context, portID, channelID string, upgradeError *types.UpgradeError) { k.writeErrorReceipt(ctx, portID, channelID, upgradeError) diff --git a/modules/core/04-channel/keeper/upgrade.go b/modules/core/04-channel/keeper/upgrade.go index 5f451955606..b58d8146ee5 100644 --- a/modules/core/04-channel/keeper/upgrade.go +++ b/modules/core/04-channel/keeper/upgrade.go @@ -6,7 +6,6 @@ import ( "slices" errorsmod "cosmossdk.io/errors" - sdkmath "cosmossdk.io/math" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" @@ -840,25 +839,6 @@ func (k Keeper) getAbsoluteUpgradeTimeout(ctx sdk.Context) types.Timeout { return types.NewTimeout(clienttypes.ZeroHeight(), uint64(ctx.BlockTime().UnixNano())+upgradeTimeout.Timestamp) } -// syncUpgradeSequence ensures current upgrade handshake only continues if both channels are using the same upgrade sequence, -// otherwise an upgrade error is returned so that an error receipt will be written so that the upgrade handshake may be attempted again with synchronized sequences. -func (k Keeper) syncUpgradeSequence(ctx sdk.Context, portID, channelID string, channel types.Channel, counterpartyUpgradeSequence uint64) error { - // save the previous upgrade sequence for the error message - prevUpgradeSequence := channel.UpgradeSequence - - if counterpartyUpgradeSequence != channel.UpgradeSequence { - // error on the higher sequence so that both chains synchronize on a fresh sequence - channel.UpgradeSequence = sdkmath.Max(counterpartyUpgradeSequence, channel.UpgradeSequence) - k.SetChannel(ctx, portID, channelID, channel) - - return types.NewUpgradeError(channel.UpgradeSequence, errorsmod.Wrapf( - types.ErrInvalidUpgradeSequence, "expected upgrade sequence (%d) to match counterparty upgrade sequence (%d)", prevUpgradeSequence, counterpartyUpgradeSequence), - ) - } - - return nil -} - // checkForUpgradeCompatibility checks performs stateful validation of self upgrade fields relative to counterparty upgrade. func (k Keeper) checkForUpgradeCompatibility(ctx sdk.Context, upgradeFields, counterpartyUpgradeFields types.UpgradeFields) error { // assert that both sides propose the same channel ordering diff --git a/modules/core/04-channel/keeper/upgrade_test.go b/modules/core/04-channel/keeper/upgrade_test.go index 475fb3b438b..5400a99e5ac 100644 --- a/modules/core/04-channel/keeper/upgrade_test.go +++ b/modules/core/04-channel/keeper/upgrade_test.go @@ -2690,64 +2690,6 @@ func (suite *KeeperTestSuite) TestCheckForUpgradeCompatibility() { } } -func (suite *KeeperTestSuite) TestSyncUpgradeSequence() { - var ( - path *ibctesting.Path - counterpartyUpgradeSequence uint64 - ) - - testCases := []struct { - name string - malleate func() - expError error - }{ - { - "success", - func() {}, - nil, - }, - { - "upgrade sequence mismatch, endpointB channel upgrade sequence is ahead", - func() { - channel := path.EndpointB.GetChannel() - channel.UpgradeSequence = 10 - path.EndpointB.SetChannel(channel) - }, - types.NewUpgradeError(10, types.ErrInvalidUpgradeSequence), // max sequence will be returned - }, - } - - for _, tc := range testCases { - tc := tc - suite.Run(tc.name, func() { - suite.SetupTest() - - path = ibctesting.NewPath(suite.chainA, suite.chainB) - suite.coordinator.Setup(path) - - path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion - path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = mock.UpgradeVersion - - err := path.EndpointA.ChanUpgradeInit() - suite.Require().NoError(err) - - err = path.EndpointB.ChanUpgradeInit() - suite.Require().NoError(err) - - counterpartyUpgradeSequence = 1 - - tc.malleate() - - err = suite.chainB.GetSimApp().IBCKeeper.ChannelKeeper.SyncUpgradeSequence(suite.chainB.GetContext(), path.EndpointB.ChannelConfig.PortID, path.EndpointB.ChannelID, path.EndpointB.GetChannel(), counterpartyUpgradeSequence) - if tc.expError != nil { - suite.Require().ErrorIs(err, tc.expError) - } else { - suite.Require().NoError(err) - } - }) - } -} - func (suite *KeeperTestSuite) TestChanUpgradeCrossingHelloWithHistoricalProofs() { var path *ibctesting.Path