-
Notifications
You must be signed in to change notification settings - Fork 629
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
Use new port router for OnChanUpgradeInit #7082
Merged
chatton
merged 11 commits into
feat/port-router
from
cian/issue#7026-use-new-port-router-for-onchanupgradeinit
Aug 8, 2024
Merged
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a5521ab
chore: add fee implementation for OnChanOpenTry
chatton fae6122
chore: fix wiring in app.gos
chatton 61c4799
chore: updated callbacks tests to handle new OnChanOpenTry
chatton 824d62f
chore: lint, correct error string
chatton abcdb32
chore: remove commented code
chatton f4faabb
chore: implementing OnChanUpgradeInit
chatton 78ba574
chore: updating callbacks OnChanUpgradeInit implementation
chatton 195bd06
chore: linter
chatton e71ba63
chore: removed redundant test
chatton 0d12db0
chore: addressing PR feedback
chatton 5835ec0
chore: merge feature branch
chatton 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
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
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
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -358,13 +358,8 @@ func (im IBCMiddleware) OnChanCloseConfirm(ctx sdk.Context, portID, channelID st | |||||
} | ||||||
|
||||||
// OnChanUpgradeInit implements the IBCModule interface | ||||||
func (im IBCMiddleware) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { | ||||||
cbs, ok := im.app.(porttypes.UpgradableModule) | ||||||
if !ok { | ||||||
return "", errorsmod.Wrap(porttypes.ErrInvalidRoute, "upgrade route not found to module in application callstack") | ||||||
} | ||||||
|
||||||
return cbs.OnChanUpgradeInit(ctx, portID, channelID, proposedOrder, proposedConnectionHops, proposedVersion) | ||||||
func (IBCMiddleware) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { | ||||||
return proposedVersion, nil | ||||||
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.
Suggested change
to be explicit? |
||||||
} | ||||||
|
||||||
// OnChanUpgradeTry implements the IBCModule interface | ||||||
|
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 |
---|---|---|
|
@@ -118,22 +118,6 @@ func (im *LegacyIBCModule) OnChanOpenTry( | |
return reconstructVersion(im.cbs, negotiatedVersions) | ||
} | ||
|
||
// reconstructVersion will generate the channel version by applying any version wrapping as necessary. | ||
// Version wrapping will only occur if the negotiated version is non=empty and the application is a VersionWrapper. | ||
func reconstructVersion(cbs []ClassicIBCModule, negotiatedVersions []string) (string, error) { | ||
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 just moved this to the bottom of the file since most handlers are not using this. |
||
version := negotiatedVersions[0] // base version | ||
for i := 1; i < len(cbs); i++ { // iterate over the remaining callbacks | ||
if strings.TrimSpace(negotiatedVersions[i]) != "" { | ||
wrapper, ok := cbs[i].(VersionWrapper) | ||
if !ok { | ||
return "", ibcerrors.ErrInvalidVersion | ||
} | ||
version = wrapper.WrapVersion(negotiatedVersions[i], version) | ||
} | ||
} | ||
return version, nil | ||
} | ||
|
||
// OnChanOpenAck implements the IBCModule interface | ||
func (LegacyIBCModule) OnChanOpenAck( | ||
ctx sdk.Context, | ||
|
@@ -227,8 +211,45 @@ func (LegacyIBCModule) OnTimeoutPacket( | |
} | ||
|
||
// OnChanUpgradeInit implements the IBCModule interface | ||
func (LegacyIBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { | ||
return "", nil | ||
func (im *LegacyIBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, proposedOrder channeltypes.Order, proposedConnectionHops []string, proposedVersion string) (string, error) { | ||
negotiatedVersions := make([]string, len(im.cbs)) | ||
|
||
for i := len(im.cbs) - 1; i >= 0; i-- { | ||
cbVersion := proposedVersion | ||
|
||
// To maintain backwards compatibility, we must handle two cases: | ||
// - relayer provides empty version (use default versions) | ||
// - relayer provides version which chooses to not enable a middleware | ||
// | ||
// If an application is a VersionWrapper which means it modifies the version string | ||
// and the version string is non-empty (don't use default), then the application must | ||
// attempt to unmarshal the version using the UnwrapVersionUnsafe interface function. | ||
// If it is unsuccessful, no callback will occur to this application as the version | ||
// indicates it should be disabled. | ||
if wrapper, ok := im.cbs[i].(VersionWrapper); ok && strings.TrimSpace(proposedVersion) != "" { | ||
appVersion, underlyingAppVersion, err := wrapper.UnwrapVersionUnsafe(proposedVersion) | ||
if err != nil { | ||
// middleware disabled | ||
negotiatedVersions[i] = "" | ||
continue | ||
} | ||
cbVersion, proposedVersion = appVersion, underlyingAppVersion | ||
} | ||
|
||
// in order to maintain backwards compatibility, every callback in the stack must implement the UpgradableModule interface. | ||
upgradableModule, ok := im.cbs[i].(UpgradableModule) | ||
if !ok { | ||
return "", errorsmod.Wrap(ErrInvalidRoute, "upgrade route not found to module in application callstack") | ||
} | ||
|
||
negotiatedVersion, err := upgradableModule.OnChanUpgradeInit(ctx, portID, channelID, proposedOrder, proposedConnectionHops, cbVersion) | ||
if err != nil { | ||
return "", errorsmod.Wrapf(err, "channel open init callback failed for port ID: %s, channel ID: %s", portID, channelID) | ||
} | ||
negotiatedVersions[i] = negotiatedVersion | ||
} | ||
|
||
return reconstructVersion(im.cbs, negotiatedVersions) | ||
} | ||
|
||
// OnChanUpgradeTry implements the IBCModule interface | ||
|
@@ -251,3 +272,19 @@ func (LegacyIBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID stri | |
func (LegacyIBCModule) UnmarshalPacketData(ctx sdk.Context, portID, channelID string, bz []byte) (interface{}, error) { | ||
return nil, nil | ||
} | ||
|
||
// reconstructVersion will generate the channel version by applying any version wrapping as necessary. | ||
// Version wrapping will only occur if the negotiated version is non=empty and the application is a VersionWrapper. | ||
func reconstructVersion(cbs []ClassicIBCModule, negotiatedVersions []string) (string, error) { | ||
version := negotiatedVersions[0] // base version | ||
for i := 1; i < len(cbs); i++ { // iterate over the remaining callbacks | ||
if strings.TrimSpace(negotiatedVersions[i]) != "" { | ||
wrapper, ok := cbs[i].(VersionWrapper) | ||
if !ok { | ||
return "", ibcerrors.ErrInvalidVersion | ||
} | ||
version = wrapper.WrapVersion(negotiatedVersions[i], version) | ||
} | ||
} | ||
return version, nil | ||
} |
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
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
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.
I think we can
return im.keeper.OnChanUpgradeInit()
?