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

refactor: modify upgrade init to not change channel state #4357

Merged
merged 20 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b0d51f0
WIP: adding initial implementation of changes
damiannolan Aug 7, 2023
ba8fb6c
proto format
damiannolan Aug 7, 2023
f4e5f9c
commenting out more failing tests from timeouts
damiannolan Aug 8, 2023
0bae135
Merge branch '04-channel-upgrades' into damian/4237-modify-chan-upgra…
damiannolan Aug 8, 2023
166e4a9
Merge branch '04-channel-upgrades' into damian/4237-modify-chan-upgra…
damiannolan Aug 8, 2023
a140964
Merge branch '04-channel-upgrades' into damian/4237-modify-chan-upgra…
damiannolan Aug 14, 2023
60940de
fix compiler error
damiannolan Aug 14, 2023
de2173f
commenting out failing testcases due to timeout logic
damiannolan Aug 14, 2023
56ef614
Merge branch '04-channel-upgrades' into damian/4237-modify-chan-upgra…
damiannolan Aug 14, 2023
b38c6f9
fix: reorder proto msg fields correctly
damiannolan Aug 14, 2023
74eb09e
refactor: move increment upgrade sequence to write fn, rename current…
damiannolan Aug 14, 2023
287e13a
refactor: rename msg server vars for consistency
damiannolan Aug 14, 2023
101fce0
update FirstChannelID to FirstConnectionID in msg validate basic tests
damiannolan Aug 15, 2023
bbdfe6b
rename test var and use mock.UpgradeVersion
damiannolan Aug 15, 2023
20ecdba
Merge branch '04-channel-upgrades' into damian/4237-modify-chan-upgra…
damiannolan Aug 15, 2023
af1b009
comment out failing tests
damiannolan Aug 15, 2023
aa4ace7
Merge branch '04-channel-upgrades' into damian/4247-modify-init-state
damiannolan Aug 16, 2023
250cc99
refactor upgrade init state to open. refactor crossing hellos and try…
damiannolan Aug 16, 2023
9cebf01
updating godoc and error return in chanUpgradeAck2
damiannolan Aug 16, 2023
3e3cb7f
address nits from pr review
damiannolan Aug 16, 2023
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
53 changes: 18 additions & 35 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,12 @@ func (k Keeper) WriteUpgradeInitChannel(ctx sdk.Context, portID, channelID strin
panic(fmt.Sprintf("could not find existing channel when updating channel state in successful ChanUpgradeInit step, channelID: %s, portID: %s", channelID, portID))
}

channel.State = types.INITUPGRADE
channel.UpgradeSequence++

k.SetChannel(ctx, portID, channelID, channel)
k.SetUpgrade(ctx, portID, channelID, upgrade)

k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "previous-state", types.OPEN.String(), "new-state", types.INITUPGRADE.String())
k.Logger(ctx).Info("channel state updated", "port-id", portID, "channel-id", channelID, "state", channel.State.String(), "upgrade-sequence", fmt.Sprintf("%d", channel.UpgradeSequence))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe we can address these logs in a follow up later, channel state is technically not updated anymore, only the upgrade sequence is incremented

Copy link
Contributor

Choose a reason for hiding this comment

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

might as well drop the .String on the enum but fine if we do all these (since they must be in many places) in another round


emitChannelUpgradeInitEvent(ctx, portID, channelID, channel, upgrade)
return channel
Expand All @@ -81,9 +80,8 @@ func (k Keeper) ChanUpgradeTry(
return types.Upgrade{}, errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}

// the channel state must be in OPEN or INITUPGRADE if we are in a crossing hellos situation
if !collections.Contains(channel.State, []types.State{types.OPEN, types.INITUPGRADE}) {
return types.Upgrade{}, errorsmod.Wrapf(types.ErrInvalidChannelState, "expected one of [%s, %s], got %s", types.OPEN, types.INITUPGRADE, channel.State)
if channel.State != types.OPEN {
Copy link
Contributor

Choose a reason for hiding this comment

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

we've got the sparkling IsOpen we can use now ✨

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 actually find it easier to read like this 😅 but we can change it too

return types.Upgrade{}, errorsmod.Wrapf(types.ErrInvalidChannelState, "expected %s, got %s", types.OPEN, channel.State)
}

connection, found := k.connectionKeeper.GetConnection(ctx, channel.ConnectionHops[0])
Expand All @@ -110,43 +108,32 @@ func (k Keeper) ChanUpgradeTry(
upgrade types.Upgrade
)

switch channel.State {
case types.OPEN:
// initialize handshake with upgrade fields
// NOTE: if an upgrade exists (crossing hellos) then use existing upgrade fields
// otherwise, run the upgrade init sub-protocol
upgrade, found = k.GetUpgrade(ctx, portID, channelID)
if found {
proposedUpgradeFields = upgrade.Fields
} else {
// TODO: add fast forward feature
// https://github.com/cosmos/ibc-go/issues/3794
// NOTE: OnChanUpgradeInit will not be executed by the application
upgrade, err = k.ChanUpgradeInit(ctx, portID, channelID, proposedUpgradeFields)
if err != nil {
return types.Upgrade{}, errorsmod.Wrap(err, "failed to initialize upgrade")
}

// TODO: add fast forward feature
// https://github.com/cosmos/ibc-go/issues/3794

// NOTE: OnChanUpgradeInit will not be executed by the application

channel = k.WriteUpgradeInitChannel(ctx, portID, channelID, upgrade)
}

case types.INITUPGRADE:
// crossing hellos
// assert that the upgrade fields are the same as the upgrade already in progress
upgrade, found = k.GetUpgrade(ctx, portID, channelID)
if !found {
return types.Upgrade{}, errorsmod.Wrapf(types.ErrUpgradeNotFound, "current upgrade not found despite channel state being in %s", types.INITUPGRADE)
}

if !reflect.DeepEqual(upgrade.Fields, proposedUpgradeFields) {
return types.Upgrade{}, errorsmod.Wrapf(
types.ErrInvalidUpgrade, "upgrade fields are not equal to current upgrade fields in crossing hellos case; expected %s, got %s", upgrade.Fields, proposedUpgradeFields)
}

default:
panic(fmt.Sprintf("channel state should be asserted to be in OPEN or INITUPGRADE before reaching this check; state is %s", channel.State))
if err := k.checkForUpgradeCompatibility(ctx, proposedUpgradeFields, counterpartyUpgradeFields); err != nil {
return types.Upgrade{}, errorsmod.Wrap(err, "failed upgrade compatibility check")
}

// construct expected counterparty channel from information in state
// only the counterpartyUpgradeSequence is provided by the relayer
counterpartyConnectionHops := []string{connection.GetCounterparty().GetConnectionID()}
counterpartyChannel := types.Channel{
State: types.INITUPGRADE,
State: types.OPEN,
Ordering: channel.Ordering,
Counterparty: types.NewCounterparty(portID, channelID),
ConnectionHops: counterpartyConnectionHops,
Expand All @@ -171,10 +158,6 @@ func (k Keeper) ChanUpgradeTry(
return types.Upgrade{}, err
}

if err := k.checkForUpgradeCompatibility(ctx, upgrade.Fields, counterpartyUpgradeFields); err != nil {
return types.Upgrade{}, errorsmod.Wrap(err, "failed upgrade compatibility check")
}

// verifies the proof that a particular proposed upgrade has been stored in the upgrade path of the counterparty
if err := k.connectionKeeper.VerifyChannelUpgrade(
ctx,
Expand All @@ -187,7 +170,7 @@ func (k Keeper) ChanUpgradeTry(
return types.Upgrade{}, errorsmod.Wrap(err, "failed to verify counterparty upgrade")
}

if err = k.startFlushUpgradeHandshake(
if err := k.startFlushUpgradeHandshake(
ctx,
portID, channelID,
proposedUpgradeFields,
Expand Down Expand Up @@ -251,7 +234,7 @@ func (k Keeper) ChanUpgradeAck(
return errorsmod.Wrapf(types.ErrChannelNotFound, "port ID (%s) channel ID (%s)", portID, channelID)
}

if !collections.Contains(channel.State, []types.State{types.INITUPGRADE, types.TRYUPGRADE}) {
if !collections.Contains(channel.State, []types.State{types.OPEN, types.STATE_FLUSHING}) {
return errorsmod.Wrapf(types.ErrInvalidChannelState, "expected one of [%s, %s], got %s", types.INITUPGRADE, types.TRYUPGRADE, channel.State)
}

Expand Down
Loading