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

Cleanup: Use types.MetadataFromVersion in 29-fee callback handlers #4290

Merged
merged 6 commits into from
Aug 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions ibc-go
Submodule ibc-go added at b9dd49
12 changes: 7 additions & 5 deletions modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ func (im IBCMiddleware) OnChanOpenInit(
AppVersion: "",
}
} else {
if err := types.ModuleCdc.UnmarshalJSON([]byte(version), &versionMetadata); err != nil {
metadata, err := types.MetadataFromVersion(version)
if err != nil {
// Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
// lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
// application.
return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID,
chanCap, counterparty, version)
}
versionMetadata = metadata
}

if versionMetadata.FeeVersion != types.Version {
Expand Down Expand Up @@ -99,8 +101,8 @@ func (im IBCMiddleware) OnChanOpenTry(
counterparty channeltypes.Counterparty,
counterpartyVersion string,
) (string, error) {
var versionMetadata types.Metadata
if err := types.ModuleCdc.UnmarshalJSON([]byte(counterpartyVersion), &versionMetadata); err != nil {
versionMetadata, err := types.MetadataFromVersion(counterpartyVersion)
if err != nil {
// Since it is valid for fee version to not be specified, the above middleware version may be for a middleware
// lower down in the stack. Thus, if it is not a fee version we pass the entire version string onto the underlying
// application.
Expand Down Expand Up @@ -139,8 +141,8 @@ func (im IBCMiddleware) OnChanOpenAck(
// If handshake was initialized with fee enabled it must complete with fee enabled.
// If handshake was initialized with fee disabled it must complete with fee disabled.
if im.keeper.IsFeeEnabled(ctx, portID, channelID) {
var versionMetadata types.Metadata
if err := types.ModuleCdc.UnmarshalJSON([]byte(counterpartyVersion), &versionMetadata); err != nil {
versionMetadata, err := types.MetadataFromVersion(counterpartyVersion)
if err != nil {
return errorsmod.Wrapf(err, "failed to unmarshal ICS29 counterparty version metadata: %s", counterpartyVersion)
}

Expand Down
4 changes: 2 additions & 2 deletions modules/apps/29-fee/keeper/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func (k Keeper) GetAppVersion(ctx sdk.Context, portID, channelID string) (string
return version, true
}

var metadata types.Metadata
if err := types.ModuleCdc.UnmarshalJSON([]byte(version), &metadata); err != nil {
metadata, err := types.MetadataFromVersion(version)
if err != nil {
panic(fmt.Errorf("unable to unmarshal metadata for fee enabled channel: %w", err))
}

Expand Down