-
Notifications
You must be signed in to change notification settings - Fork 751
chore: implement version checking for channel handshake application callbacks #6175
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
Changes from 2 commits
f741403
daa0b32
40337d8
a6238ce
2dbf77b
ac271fa
1166258
8bc703a
e5f3d73
90cca94
021e42f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ import ( | |
| "encoding/json" | ||
| "fmt" | ||
| "math" | ||
| "slices" | ||
| "strings" | ||
|
|
||
| errorsmod "cosmossdk.io/errors" | ||
|
|
@@ -89,16 +90,21 @@ func (im IBCModule) OnChanOpenInit( | |
| version = types.Version | ||
| } | ||
|
|
||
| if version != types.Version { | ||
| return "", errorsmod.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, version) | ||
| if !slices.Contains(types.SupportedVersions, version) { | ||
| return "", errorsmod.Wrapf(types.ErrInvalidVersion, "invalid version: expected %s or %s, got %s", types.Version1, types.Version, version) | ||
| } | ||
|
|
||
| // Claim channel capability passed back by IBC module | ||
| if err := im.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| return version, nil | ||
| if version == types.Version1 { | ||
| return types.Version1, nil | ||
| } | ||
charleenfei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // default to latest supported version | ||
| return types.Version, nil | ||
charleenfei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // OnChanOpenTry implements the IBCModule interface. | ||
|
|
@@ -116,16 +122,16 @@ func (im IBCModule) OnChanOpenTry( | |
| return "", err | ||
| } | ||
|
|
||
| if counterpartyVersion != types.Version { | ||
| return "", errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: expected %s, got %s", types.Version, counterpartyVersion) | ||
| if !slices.Contains(types.SupportedVersions, counterpartyVersion) { | ||
|
Contributor
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. Note: we could instead of erroring here, return our preferred version for ACK to optionally accept
Contributor
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. This should also be changed in ics20-1 only versions of ibc-go to truly take advantage of the change. It will also help here: #6171
Contributor
Author
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 think the comment from @chatton is relevant here, that relying on ics4wrapper to correctly return the transfer app version might not be the safest idea -- just adding this as a note, since we'd be relying on this as our proposed version. do you have any thoughts on that @AdityaSripal ?
Contributor
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. Can you link or summarize the comment from @chatton? Where is the ics4wrapper used when returning a string in the channel handshake?
Contributor
Author
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. if we want to counterpropose with our preferred version for ACK to optionally accept, we will have to get our own version from the ICS4 wrappper |
||
| return "", errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: expected %s or %s, got %s", types.Version1, types.Version, counterpartyVersion) | ||
charleenfei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // OpenTry must claim the channelCapability that IBC passes into the callback | ||
| if err := im.keeper.ClaimCapability(ctx, chanCap, host.ChannelCapabilityPath(portID, channelID)); err != nil { | ||
| return "", err | ||
| } | ||
|
|
||
| return types.Version, nil | ||
| return counterpartyVersion, nil | ||
| } | ||
|
|
||
| // OnChanOpenAck implements the IBCModule interface | ||
|
|
@@ -136,9 +142,10 @@ func (IBCModule) OnChanOpenAck( | |
| _ string, | ||
| counterpartyVersion string, | ||
| ) error { | ||
| if counterpartyVersion != types.Version { | ||
| return errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: expected %s, got %s", types.Version, counterpartyVersion) | ||
| if !slices.Contains(types.SupportedVersions, counterpartyVersion) { | ||
| return errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: expected %s or %s, got %s", types.Version1, types.Version, counterpartyVersion) | ||
charleenfei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -315,8 +322,8 @@ func (im IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, | |
| return "", err | ||
| } | ||
|
|
||
| if proposedVersion != types.Version { | ||
| return "", errorsmod.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, proposedVersion) | ||
| if !slices.Contains(types.SupportedVersions, proposedVersion) { | ||
| return "", errorsmod.Wrapf(types.ErrInvalidVersion, "invalid proposed version: expected %s or %s, got %s", types.Version1, types.Version, proposedVersion) | ||
charleenfei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return proposedVersion, nil | ||
|
|
@@ -328,17 +335,17 @@ func (im IBCModule) OnChanUpgradeTry(ctx sdk.Context, portID, channelID string, | |
| return "", err | ||
| } | ||
|
|
||
| if counterpartyVersion != types.Version { | ||
| return "", errorsmod.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, counterpartyVersion) | ||
| if !slices.Contains(types.SupportedVersions, counterpartyVersion) { | ||
| return "", errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: expected %s or %s, got %s", types.Version1, types.Version, counterpartyVersion) | ||
charleenfei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return counterpartyVersion, nil | ||
| } | ||
|
|
||
| // OnChanUpgradeAck implements the IBCModule interface | ||
| func (IBCModule) OnChanUpgradeAck(ctx sdk.Context, portID, channelID, counterpartyVersion string) error { | ||
| if counterpartyVersion != types.Version { | ||
| return errorsmod.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, counterpartyVersion) | ||
| if !slices.Contains(types.SupportedVersions, counterpartyVersion) { | ||
| return errorsmod.Wrapf(types.ErrInvalidVersion, "invalid counterparty version: expected %s or %s, got %s", types.Version1, types.Version, counterpartyVersion) | ||
charleenfei marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return nil | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.