Skip to content

Commit

Permalink
update app, middleware and 05-port modules with ChanUpgradeTimeout f…
Browse files Browse the repository at this point in the history
…unction
  • Loading branch information
charleenfei authored Jun 16, 2023
1 parent 3fc6954 commit e201873
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 0 deletions.
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)
}

// 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

0 comments on commit e201873

Please sign in to comment.