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

chore: remove syncUpgradeSequence #5489

Merged
merged 2 commits into from
Jan 1, 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
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
Loading