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: cleanup upgrade init app callback args #4359

Merged
merged 21 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 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
f434996
refactor: rm unnecessary args in application upgrade init callback
damiannolan Aug 16, 2023
60ca446
Merge branch '04-channel-upgrades' into damian/cian/refactor-app-cb-args
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
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (im IBCMiddleware) OnTimeoutPacket(
}

// OnChanUpgradeInit implements the IBCModule interface
func (IBCMiddleware) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, sequence uint64, version, previousVersion string) (string, error) {
func (IBCMiddleware) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) {
return icatypes.Version, nil
}

Expand Down
2 changes: 1 addition & 1 deletion modules/apps/27-interchain-accounts/host/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func (IBCModule) OnTimeoutPacket(
}

// OnChanUpgradeInit implements the IBCModule interface
func (IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, sequence uint64, version, previousVersion string) (string, error) {
func (IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) {
return "", errorsmod.Wrap(icatypes.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain")
}

Expand Down
6 changes: 2 additions & 4 deletions modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,24 +331,22 @@ func (im IBCMiddleware) OnChanUpgradeInit(
channelID string,
order channeltypes.Order,
connectionHops []string,
upgradeSequence uint64,
upgradeVersion string,
previousVersion string,
) (string, error) {
versionMetadata, err := types.MetadataFromVersion(upgradeVersion)
if err != nil {
// fee version is unable to be parsed from upgrade version, disable fee
im.keeper.DeleteFeeEnabled(ctx, portID, channelID)
// since it is valid for fee version to not be specified, the upgrade version may be for a middleware
// or application further down in the stack. Thus, passthrough to next middleware or application in callstack.
return im.app.OnChanUpgradeInit(ctx, portID, channelID, order, connectionHops, upgradeSequence, upgradeVersion, previousVersion)
return im.app.OnChanUpgradeInit(ctx, portID, channelID, order, connectionHops, upgradeVersion)
}

if versionMetadata.FeeVersion != types.Version {
return "", errorsmod.Wrapf(types.ErrInvalidVersion, "expected %s, got %s", types.Version, versionMetadata.FeeVersion)
}

appVersion, err := im.app.OnChanUpgradeInit(ctx, portID, channelID, order, connectionHops, upgradeSequence, versionMetadata.AppVersion, previousVersion)
appVersion, err := im.app.OnChanUpgradeInit(ctx, portID, channelID, order, connectionHops, versionMetadata.AppVersion)
if err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions modules/apps/29-fee/ibc_middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeInit() {
path.EndpointA.ChannelConfig.ProposedUpgrade.Fields.Version = ibctesting.InvalidID
path.EndpointB.ChannelConfig.ProposedUpgrade.Fields.Version = ibctesting.InvalidID

suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeInit = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ uint64, _, _ string) (string, error) {
suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeInit = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) {
// intentionally force the error here so we can assert that a passthrough occurs when fees should not be enabled for this channel
return "", ibcmock.MockApplicationCallbackError
}
Expand All @@ -1074,7 +1074,7 @@ func (suite *FeeTestSuite) TestOnChanUpgradeInit() {
"underlying app callback returns error",
func() {
expFeeEnabled = false
suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeInit = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ uint64, _, _ string) (string, error) {
suite.chainA.GetSimApp().FeeMockModule.IBCApp.OnChanUpgradeInit = func(_ sdk.Context, _, _ string, _ channeltypes.Order, _ []string, _ string) (string, error) {
return "", ibcmock.MockApplicationCallbackError
}
},
Expand Down
2 changes: 1 addition & 1 deletion modules/apps/transfer/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func (im IBCModule) OnTimeoutPacket(
}

// OnChanUpgradeInit implements the IBCModule interface
func (im IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, upgradeSequence uint64, upgradeVersion, previousVersion string) (string, error) {
func (im IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, upgradeVersion string) (string, error) {
if err := ValidateTransferChannelParams(ctx, im.keeper, order, portID, channelID); err != nil {
return "", err
}
Expand Down
3 changes: 1 addition & 2 deletions modules/core/05-port/types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,7 @@ type UpgradableModule interface {
portID, channelID string,
order channeltypes.Order,
connectionHops []string,
sequence uint64,
version, previousVersion string,
version string,
) (string, error)

// OnChanUpgradeTry verifies the counterparty upgrade and sets the upgrade on TRY chain
Expand Down
9 changes: 1 addition & 8 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,28 +719,21 @@ func (k Keeper) ChannelUpgradeInit(goCtx context.Context, msg *channeltypes.MsgC
return nil, errorsmod.Wrap(err, "channel upgrade init failed")
}

channel, found := k.ChannelKeeper.GetChannel(ctx, msg.PortId, msg.ChannelId)
if !found {
return nil, errorsmod.Wrapf(channeltypes.ErrChannelNotFound, "port ID (%s) channel ID (%s)", msg.PortId, msg.ChannelId)
}

upgradeVersion, err := cbs.OnChanUpgradeInit(
ctx,
msg.PortId,
msg.ChannelId,
upgrade.Fields.Ordering,
upgrade.Fields.ConnectionHops,
channel.UpgradeSequence,
upgrade.Fields.Version,
channel.Version,
)
if err != nil {
ctx.Logger().Error("channel upgrade init callback failed", "port-id", msg.PortId, "channel-id", msg.ChannelId, "error", err.Error())
return nil, errorsmod.Wrapf(err, "channel upgrade init callback failed for port ID: %s, channel ID: %s", msg.PortId, msg.ChannelId)
}

upgrade.Fields.Version = upgradeVersion
k.ChannelKeeper.WriteUpgradeInitChannel(ctx, msg.PortId, msg.ChannelId, upgrade)
channel := k.ChannelKeeper.WriteUpgradeInitChannel(ctx, msg.PortId, msg.ChannelId, upgrade)

ctx.Logger().Info("channel upgrade init succeeded", "channel-id", msg.ChannelId, "version", upgradeVersion)

Expand Down
3 changes: 1 addition & 2 deletions testing/mock/ibc_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ type IBCApp struct {
portID, channelID string,
order channeltypes.Order,
connectionHops []string,
sequence uint64,
version, previousVersion string,
version string,
) (string, error)

OnChanUpgradeTry func(
Expand Down
4 changes: 2 additions & 2 deletions testing/mock/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ func (im IBCModule) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet,
}

// OnChanUpgradeInit implements the IBCModule interface
func (im IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, sequence uint64, version, previousVersion string) (string, error) {
func (im IBCModule) OnChanUpgradeInit(ctx sdk.Context, portID, channelID string, order channeltypes.Order, connectionHops []string, version string) (string, error) {
if im.IBCApp.OnChanUpgradeInit != nil {
return im.IBCApp.OnChanUpgradeInit(ctx, portID, channelID, order, connectionHops, sequence, version, previousVersion)
return im.IBCApp.OnChanUpgradeInit(ctx, portID, channelID, order, connectionHops, version)
}

return version, nil
Expand Down