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

ICA Controller Side Middleware #417

Merged
merged 24 commits into from
Nov 5, 2021
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7de03ee
initial draft for ica middleware
colin-axner Sep 16, 2021
9f0f495
add capability handling, fix build and tests
colin-axner Sep 17, 2021
51fe4b2
merge interchain-accounts branch and fix conflicts
colin-axner Sep 29, 2021
0eb681a
split module.go into ibc_module.go
colin-axner Sep 29, 2021
e3a3d8f
merge interchain-accounts branch, fix merge conflicts
colin-axner Sep 29, 2021
4404535
add middleware handshake tests
colin-axner Sep 29, 2021
eb071fb
fix app.go wiring and various tests
colin-axner Oct 5, 2021
607aa8f
merge interchain accounts branch
colin-axner Oct 8, 2021
a6066da
godoc self nits
colin-axner Oct 12, 2021
eccb110
merge interchain account branch
colin-axner Oct 12, 2021
70bf29b
remove unnecessary error
colin-axner Oct 12, 2021
205d6f0
update comment
colin-axner Nov 1, 2021
ee61276
merge interchain-accounts branch
colin-axner Nov 2, 2021
8e279ea
merge interchain accounts branch
colin-axner Nov 4, 2021
7baafe0
fix testing build
colin-axner Nov 4, 2021
b166880
split channel keeper interface
colin-axner Nov 4, 2021
45bee51
fix tests
colin-axner Nov 4, 2021
816293b
remove comments
colin-axner Nov 4, 2021
9a0e7de
add callback for timeouts
colin-axner Nov 4, 2021
b2db520
Apply suggestions from code review
colin-axner Nov 5, 2021
c4a4aeb
fix test and update testing README
colin-axner Nov 5, 2021
46f30de
add OnRecvPacket test
colin-axner Nov 5, 2021
e22684b
Merge branch 'colin/313-ica-middleware' of github.com:cosmos/ibc-go i…
colin-axner Nov 5, 2021
62dd3d3
add failing test case for NegotiateAppVersion
colin-axner Nov 5, 2021
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
72 changes: 48 additions & 24 deletions modules/apps/27-interchain-accounts/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
ibcexported "github.com/cosmos/ibc-go/v2/modules/core/exported"
)

// IBCModule implements the ICS26 callbacks for interchain accounts given the
// IBCModule implements the ICS26 interface for interchain accounts given the
// interchain account keeper and underlying application.
type IBCModule struct {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
keeper keeper.Keeper
Expand All @@ -29,7 +29,13 @@ func NewIBCModule(k keeper.Keeper, app porttypes.IBCModule) IBCModule {
}
}

// OnChanOpenInit implements the IBCModule interface
// OnChanOpenInit implements the IBCModule interface. Interchain Accounts is
// implemented to act as middleware for connected authentication modules on
// the controller side. The connected modules may not change the controller side portID or
// version. They will be allowed to perform custom logic without changing
// the parameters stored within a channel struct.
//
// Controller Chain
func (im IBCModule) OnChanOpenInit(
ctx sdk.Context,
order channeltypes.Order,
Expand All @@ -40,10 +46,18 @@ func (im IBCModule) OnChanOpenInit(
counterparty channeltypes.Counterparty,
version string,
) error {
return im.keeper.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version)
if err := im.keeper.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version); err != nil {
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
return err
}

// call underlying app's OnChanOpenInit callback with the appVersion
return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID,
chanCap, counterparty, version)
}

// OnChanOpenTry implements the IBCModule interface
//
// Host Chain
func (im IBCModule) OnChanOpenTry(
ctx sdk.Context,
order channeltypes.Order,
Expand All @@ -58,17 +72,30 @@ func (im IBCModule) OnChanOpenTry(
return im.keeper.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version, counterpartyVersion)
}

// OnChanOpenAck implements the IBCModule interface
// OnChanOpenAck implements the IBCModule interface. Interchain Accounts is
// implemented to act as middleware for connected authentication modules on
// the controller side. The connected modules may not change the portID or
// version. They will be allowed to perform custom logic without changing
// the parameters stored within a channel struct.
//
// Controller Chain
func (im IBCModule) OnChanOpenAck(
ctx sdk.Context,
portID,
channelID string,
counterpartyVersion string,
) error {
return im.keeper.OnChanOpenAck(ctx, portID, channelID, counterpartyVersion)
if err := im.keeper.OnChanOpenAck(ctx, portID, channelID, counterpartyVersion); err != nil {
return err
}

// call underlying app's OnChanOpenAck callback with the counterparty app version.
return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyVersion)
}

// OnChanOpenConfirm implements the IBCModule interface
// OnChanOpenAck implements the IBCModule interface
//
// Host Chain
damiannolan marked this conversation as resolved.
Show resolved Hide resolved
func (im IBCModule) OnChanOpenConfirm(
ctx sdk.Context,
portID,
Expand Down Expand Up @@ -97,6 +124,8 @@ func (im IBCModule) OnChanCloseConfirm(
}

// OnRecvPacket implements the IBCModule interface
//
// Host Chain
func (im IBCModule) OnRecvPacket(
ctx sdk.Context,
packet channeltypes.Packet,
Expand All @@ -123,36 +152,31 @@ func (im IBCModule) OnRecvPacket(
}

// OnAcknowledgementPacket implements the IBCModule interface
//
// Controller Chain
func (im IBCModule) OnAcknowledgementPacket(
ctx sdk.Context,
packet channeltypes.Packet,
acknowledgement []byte,
_ sdk.AccAddress,
relayer sdk.AccAddress,
) error {
var ack channeltypes.Acknowledgement

if err := types.ModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 interchain account packet acknowledgment: %v", err)
}
var data types.InterchainAccountPacketData
if err := types.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
return sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "cannot unmarshal ICS-27 interchain account packet data: %s", err.Error())
}

if err := im.keeper.OnAcknowledgementPacket(ctx, packet, data, ack); err != nil {
return err
}

return nil
// call underlying app's OnAcknowledgementPacket callback.
return im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer)
colin-axner marked this conversation as resolved.
Show resolved Hide resolved
}

// OnTimeoutPacket implements the IBCModule interface
//
// Controller Chain
func (im IBCModule) OnTimeoutPacket(
ctx sdk.Context,
packet channeltypes.Packet,
_ sdk.AccAddress,
relayer sdk.AccAddress,
) error {
return im.keeper.OnTimeoutPacket(ctx, packet)
if err := im.keeper.OnTimeoutPacket(ctx, packet); err != nil {
return err
}

return im.app.OnTimeoutPacket(ctx, packet, relayer)
}

// NegotiateAppVersion implements the IBCModule interface
Expand Down
Loading