Skip to content

Commit

Permalink
chore: remove syncUpgradeSequence (#5489)
Browse files Browse the repository at this point in the history
* chore: remove syncUpgradeSequence

* remove unused import
  • Loading branch information
crodriguezvega authored Jan 1, 2024
1 parent 947b15e commit 05dd7d0
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 83 deletions.
5 changes: 0 additions & 5 deletions modules/core/04-channel/keeper/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 0 additions & 20 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
58 changes: 0 additions & 58 deletions modules/core/04-channel/keeper/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 05dd7d0

Please sign in to comment.