-
Notifications
You must be signed in to change notification settings - Fork 657
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
damiannolan
merged 20 commits into
04-channel-upgrades
from
damian/4247-modify-init-state
Aug 16, 2023
Merged
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 ba8fb6c
proto format
damiannolan f4e5f9c
commenting out more failing tests from timeouts
damiannolan 0bae135
Merge branch '04-channel-upgrades' into damian/4237-modify-chan-upgra…
damiannolan 166e4a9
Merge branch '04-channel-upgrades' into damian/4237-modify-chan-upgra…
damiannolan a140964
Merge branch '04-channel-upgrades' into damian/4237-modify-chan-upgra…
damiannolan 60940de
fix compiler error
damiannolan de2173f
commenting out failing testcases due to timeout logic
damiannolan 56ef614
Merge branch '04-channel-upgrades' into damian/4237-modify-chan-upgra…
damiannolan b38c6f9
fix: reorder proto msg fields correctly
damiannolan 74eb09e
refactor: move increment upgrade sequence to write fn, rename current…
damiannolan 287e13a
refactor: rename msg server vars for consistency
damiannolan 101fce0
update FirstChannelID to FirstConnectionID in msg validate basic tests
damiannolan bbdfe6b
rename test var and use mock.UpgradeVersion
damiannolan 20ecdba
Merge branch '04-channel-upgrades' into damian/4237-modify-chan-upgra…
damiannolan af1b009
comment out failing tests
damiannolan aa4ace7
Merge branch '04-channel-upgrades' into damian/4247-modify-init-state
damiannolan 250cc99
refactor upgrade init state to open. refactor crossing hellos and try…
damiannolan 9cebf01
updating godoc and error return in chanUpgradeAck2
damiannolan 3e3cb7f
address nits from pr review
damiannolan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
|
||
emitChannelUpgradeInitEvent(ctx, portID, channelID, channel, upgrade) | ||
return channel | ||
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we've got the sparkling There was a problem hiding this comment. Choose a reason for hiding this commentThe 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]) | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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, | ||
|
@@ -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) | ||
} | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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