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

update app, middleware and 05-port modules with ChanUpgradeTimeout function #3859

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions modules/apps/27-interchain-accounts/controller/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,19 @@ func (im IBCMiddleware) OnChanUpgradeRestore(ctx sdk.Context, portID, channelID
return nil
}

// OnChanUpgradeTimeout implements the IBCModule interface
func (im IBCMiddleware) OnChanUpgradeTimeout(
ctx sdk.Context,
portID, channelID string,
counterpartyChannel channeltypes.Channel,
prevErrorReceipt channeltypes.ErrorReceipt,
proofCounterpartyChannel,
proofErrorReceipt []byte,
proofHeight ibcexported.Height,
) error {
return im.app.OnChanUpgradeTimeout(ctx, portID, channelID, counterpartyChannel, prevErrorReceipt, proofCounterpartyChannel, proofErrorReceipt, proofHeight)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why you forward here instead of nil? Just curious.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, because we are calling it from the controller middleware here which should pass the call through to the app for the app callback.

basically, this would be called in the usecase where you have an underlying module that you want to use to authenticate ICA actions (the kinda v0 auth module design we had for ICA), and then you wrap that application with the ICA controller middleware. in the v1 design you can pass a nil app to the ICA controller middleware, and use the controller msg_server directly.

}

// SendPacket implements the ICS4 Wrapper interface
func (im IBCMiddleware) SendPacket(
ctx sdk.Context,
Expand Down
13 changes: 13 additions & 0 deletions modules/apps/27-interchain-accounts/host/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,16 @@ func (im IBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string)
func (im IBCModule) OnChanUpgradeRestore(ctx sdk.Context, portID, channelID string) error {
return nil
}

// OnChanUpgradeTimeout implements the IBCModule interface
func (im IBCModule) OnChanUpgradeTimeout(
ctx sdk.Context,
portID, channelID string,
counterpartyChannel channeltypes.Channel,
prevErrorReceipt channeltypes.ErrorReceipt,
proofCounterpartyChannel,
proofErrorReceipt []byte,
proofHeight ibcexported.Height,
) error {
return nil
}
13 changes: 13 additions & 0 deletions modules/apps/29-fee/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,19 @@ func (im IBCMiddleware) OnChanUpgradeRestore(ctx sdk.Context, portID, channelID
return im.app.OnChanUpgradeRestore(ctx, portID, channelID)
}

// OnChanUpgradeTimeout implements the IBCModule interface
func (im IBCMiddleware) OnChanUpgradeTimeout(
ctx sdk.Context,
portID, channelID string,
counterpartyChannel channeltypes.Channel,
prevErrorReceipt channeltypes.ErrorReceipt,
proofCounterpartyChannel,
proofErrorReceipt []byte,
proofHeight exported.Height,
) error {
return im.app.OnChanUpgradeTimeout(ctx, portID, channelID, counterpartyChannel, prevErrorReceipt, proofCounterpartyChannel, proofErrorReceipt, proofHeight)
}

// SendPacket implements the ICS4 Wrapper interface
func (im IBCMiddleware) SendPacket(
ctx sdk.Context,
Expand Down
13 changes: 13 additions & 0 deletions modules/apps/transfer/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,3 +325,16 @@ func (im IBCModule) OnChanUpgradeOpen(ctx sdk.Context, portID, channelID string)
func (im IBCModule) OnChanUpgradeRestore(ctx sdk.Context, portID, channelID string) error {
return nil
}

// OnChanUpgradeTimeout implements the IBCModule interface
func (im IBCModule) OnChanUpgradeTimeout(
ctx sdk.Context,
portID, channelID string,
counterpartyChannel channeltypes.Channel,
prevErrorReceipt channeltypes.ErrorReceipt,
proofCounterpartyChannel,
proofErrorReceipt []byte,
proofHeight ibcexported.Height,
) error {
return nil
}
15 changes: 15 additions & 0 deletions modules/core/04-channel/keeper/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
"github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
)

// ChanUpgradeInit is called by a module to initiate a channel upgrade handshake with
Expand Down Expand Up @@ -359,6 +360,20 @@ func (k Keeper) ChanUpgradeAck(
return nil
}

// ChanUpgradeTimeout times out an outstanding upgrade.
// This should be used by the initialising chain when the counterparty chain has not responded to an upgrade proposal within the specified timeout period.
func (k Keeper) ChanUpgradeTimeout(
ctx sdk.Context,
portID, channelID string,
counterpartyChannel types.Channel,
prevErrorReceipt types.ErrorReceipt,
proofCounterpartyChannel,
proofErrorReceipt []byte,
proofHeight exported.Height,
) error {
return nil
}

// writeUpgradeTimeoutChannel restores the channel state of an initialising chain in the event that the counterparty chain has passed the timeout set in ChanUpgradeInit to the state before the upgrade was proposed.
// Auxiliary upgrade state is also deleted.
// An event is emitted for the handshake step.
Expand Down
11 changes: 11 additions & 0 deletions modules/core/05-port/types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,17 @@ type UpgradableModule interface {
portID,
channelID string,
) error

// OnChanUpgradeTimeout times out an outstanding upgrade when the counterparty chain has not responded.
OnChanUpgradeTimeout(
ctx sdk.Context,
portID, channelID string,
counterpartyChannel channeltypes.Channel,
prevErrorReceipt channeltypes.ErrorReceipt,
proofCounterpartyChannel,
proofErrorReceipt []byte,
proofHeight exported.Height,
) error
}

// ICS4Wrapper implements the ICS4 interfaces that IBC applications use to send packets and acknowledgements.
Expand Down
10 changes: 10 additions & 0 deletions testing/mock/ibc_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ type IBCApp struct {
portID,
channelID string,
) error

OnChanUpgradeTimeout func(
ctx sdk.Context,
portID, channelID string,
counterpartyChannel channeltypes.Channel,
prevErrorReceipt channeltypes.ErrorReceipt,
proofCounterpartyChannel,
proofErrorReceipt []byte,
proofHeight exported.Height,
) error
}

// NewIBCApp returns a IBCApp. An empty PortID indicates the mock app doesn't bind/claim ports.
Expand Down
17 changes: 17 additions & 0 deletions testing/mock/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,23 @@ func (im IBCModule) OnChanUpgradeRestore(ctx sdk.Context, portID, channelID stri
return nil
}

// OnChanUpgradeTimeout implements the IBCModule interface
func (im IBCModule) OnChanUpgradeTimeout(
ctx sdk.Context,
portID, channelID string,
counterpartyChannel channeltypes.Channel,
prevErrorReceipt channeltypes.ErrorReceipt,
proofCounterpartyChannel,
proofErrorReceipt []byte,
proofHeight exported.Height,
) error {
if im.IBCApp.OnChanUpgradeTimeout != nil {
return im.IBCApp.OnChanUpgradeTimeout(ctx, portID, channelID, counterpartyChannel, prevErrorReceipt, proofCounterpartyChannel, proofErrorReceipt, proofHeight)
}

return nil
}

// GetMockRecvCanaryCapabilityName generates a capability name for testing OnRecvPacket functionality.
func GetMockRecvCanaryCapabilityName(packet channeltypes.Packet) string {
return fmt.Sprintf("%s%s%s%s", MockRecvCanaryCapabilityName, packet.GetDestPort(), packet.GetDestChannel(), strconv.Itoa(int(packet.GetSequence())))
Expand Down