Skip to content

Commit

Permalink
ICA controller/host submodules (#541)
Browse files Browse the repository at this point in the history
* go mod tidy

* creating new genesis types for controller and host submodules

* removing dead root module code

* updating genesis helpers and adding newly generated types

* adding interchain-accounts controller submodule

* adding interchain-accounts host submodule

* updating simapp to include controller and host ica submodules

* adding errors returns for disallowed handshake directions, removing embedded app from host module, updating simapp to conform

* updating simapp to remove nil arg to ica host ibc module

* removing ics4Wrapper arg from ica host submodule

* cleaning up module.go for controller and host submodules

* removing commented out tests

* commit with broken tests to rebase

* disabling app version negotation on controller submodule

* fixing tests - now passing

* various cleanup, godocs and moving code

* updating error msgs to conform to pkg split

* removing commented out code

* adding combined ica genesis, consolidating to single ica AppModule, updating app.go

* adding missing godocs

* clean up, godocs, rename validate.go -> version.go, move version related funcs

* updating godocs and code organization

* removing controller module acc, using icatypes module name for module acc in host submodule

* correcting panic error msg

* Update modules/apps/27-interchain-accounts/controller/ibc_module.go

* Update modules/apps/27-interchain-accounts/types/genesis.go

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* updating logger kvs, and simplifying OnRecvPacket

* address nits on error strings and godocs

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
  • Loading branch information
damiannolan and colin-axner authored Nov 18, 2021
1 parent b8bc1a8 commit 7efc384
Show file tree
Hide file tree
Showing 48 changed files with 3,205 additions and 2,475 deletions.
69 changes: 21 additions & 48 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@

- [ibc/applications/interchain_accounts/v1/genesis.proto](#ibc/applications/interchain_accounts/v1/genesis.proto)
- [ActiveChannel](#ibc.applications.interchain_accounts.v1.ActiveChannel)
- [ControllerGenesisState](#ibc.applications.interchain_accounts.v1.ControllerGenesisState)
- [GenesisState](#ibc.applications.interchain_accounts.v1.GenesisState)
- [HostGenesisState](#ibc.applications.interchain_accounts.v1.HostGenesisState)
- [RegisteredInterchainAccount](#ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount)

- [ibc/applications/interchain_accounts/v1/query.proto](#ibc/applications/interchain_accounts/v1/query.proto)
- [QueryInterchainAccountAddressRequest](#ibc.applications.interchain_accounts.v1.QueryInterchainAccountAddressRequest)
- [QueryInterchainAccountAddressResponse](#ibc.applications.interchain_accounts.v1.QueryInterchainAccountAddressResponse)

- [Query](#ibc.applications.interchain_accounts.v1.Query)

- [ibc/applications/interchain_accounts/v1/types.proto](#ibc/applications/interchain_accounts/v1/types.proto)
- [CosmosTx](#ibc.applications.interchain_accounts.v1.CosmosTx)
- [InterchainAccountPacketData](#ibc.applications.interchain_accounts.v1.InterchainAccountPacketData)
Expand Down Expand Up @@ -329,10 +325,10 @@ ActiveChannel contains a pairing of port ID and channel ID for an active interch



<a name="ibc.applications.interchain_accounts.v1.GenesisState"></a>
<a name="ibc.applications.interchain_accounts.v1.ControllerGenesisState"></a>

### GenesisState
GenesisState defines the interchain accounts genesis state
### ControllerGenesisState
ControllerGenesisState defines the interchain accounts controller genesis state


| Field | Type | Label | Description |
Expand All @@ -346,62 +342,49 @@ GenesisState defines the interchain accounts genesis state



<a name="ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount"></a>
<a name="ibc.applications.interchain_accounts.v1.GenesisState"></a>

### RegisteredInterchainAccount
RegisteredInterchainAccount contains a pairing of controller port ID and associated interchain account address
### GenesisState
GenesisState defines the interchain accounts genesis state


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `port_id` | [string](#string) | | |
| `account_address` | [string](#string) | | |



| `controller_genesis_state` | [ControllerGenesisState](#ibc.applications.interchain_accounts.v1.ControllerGenesisState) | | |
| `host_genesis_state` | [HostGenesisState](#ibc.applications.interchain_accounts.v1.HostGenesisState) | | |


<!-- end messages -->

<!-- end enums -->

<!-- end HasExtensions -->

<!-- end services -->

<a name="ibc.applications.interchain_accounts.v1.HostGenesisState"></a>


<a name="ibc/applications/interchain_accounts/v1/query.proto"></a>
<p align="right"><a href="#top">Top</a></p>

## ibc/applications/interchain_accounts/v1/query.proto



<a name="ibc.applications.interchain_accounts.v1.QueryInterchainAccountAddressRequest"></a>

### QueryInterchainAccountAddressRequest
Query request for an interchain account address
### HostGenesisState
HostGenesisState defines the interchain accounts host genesis state


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `counterparty_port_id` | [string](#string) | | Counterparty PortID is the portID on the controller chain |
| `active_channels` | [ActiveChannel](#ibc.applications.interchain_accounts.v1.ActiveChannel) | repeated | |
| `interchain_accounts` | [RegisteredInterchainAccount](#ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount) | repeated | |
| `port` | [string](#string) | | |






<a name="ibc.applications.interchain_accounts.v1.QueryInterchainAccountAddressResponse"></a>
<a name="ibc.applications.interchain_accounts.v1.RegisteredInterchainAccount"></a>

### QueryInterchainAccountAddressResponse
Query response for an interchain account address
### RegisteredInterchainAccount
RegisteredInterchainAccount contains a pairing of controller port ID and associated interchain account address


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `interchain_account_address` | [string](#string) | | The corresponding interchain account address on the host chain |
| `port_id` | [string](#string) | | |
| `account_address` | [string](#string) | | |



Expand All @@ -413,16 +396,6 @@ Query response for an interchain account address

<!-- end HasExtensions -->


<a name="ibc.applications.interchain_accounts.v1.Query"></a>

### Query
Query defines the gRPC querier service.

| Method Name | Request Type | Response Type | Description | HTTP Verb | Endpoint |
| ----------- | ------------ | ------------- | ------------| ------- | -------- |
| `InterchainAccountAddress` | [QueryInterchainAccountAddressRequest](#ibc.applications.interchain_accounts.v1.QueryInterchainAccountAddressRequest) | [QueryInterchainAccountAddressResponse](#ibc.applications.interchain_accounts.v1.QueryInterchainAccountAddressResponse) | Query to get the address of an interchain account | |

<!-- end services -->


Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ require (
github.com/prometheus/common v0.29.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/regen-network/cosmos-proto v0.3.1 // indirect
github.com/rs/cors v1.7.0 // indirect
github.com/rs/zerolog v1.23.0 // indirect
github.com/sasha-s/go-deadlock v0.2.1-0.20190427202633-1595213edefa // indirect
Expand All @@ -115,7 +114,6 @@ require (
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 // indirect
golang.org/x/text v0.3.6 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
nhooyr.io/websocket v1.8.6 // indirect
)
52 changes: 0 additions & 52 deletions modules/apps/27-interchain-accounts/client/cli/query.go

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
package interchain_accounts
package controller

import (
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/keeper"
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/controller/keeper"
"github.com/cosmos/ibc-go/v2/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v2/modules/core/04-channel/types"
porttypes "github.com/cosmos/ibc-go/v2/modules/core/05-port/types"
ibcexported "github.com/cosmos/ibc-go/v2/modules/core/exported"
)

// IBCModule implements the ICS26 interface for interchain accounts given the
// interchain account keeper and underlying application.
// IBCModule implements the ICS26 interface for interchain accounts controller chains
type IBCModule struct {
keeper keeper.Keeper
app porttypes.IBCModule
}

// NewIBCModule creates a new IBCModule given the keeper and underlying application
// NewIBCModule creates a new IBCModule given the associated keeper and underlying application
func NewIBCModule(k keeper.Keeper, app porttypes.IBCModule) IBCModule {
return IBCModule{
keeper: k,
app: app,
}
}

// OnChanOpenInit implements the IBCModule interface. Interchain Accounts is
// implemented to act as middleware for connected authentication modules on
// 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 @@ -53,8 +52,6 @@ func (im IBCModule) OnChanOpenInit(
}

// OnChanOpenTry implements the IBCModule interface
//
// Host Chain
func (im IBCModule) OnChanOpenTry(
ctx sdk.Context,
order channeltypes.Order,
Expand All @@ -66,16 +63,15 @@ func (im IBCModule) OnChanOpenTry(
version,
counterpartyVersion string,
) error {
return im.keeper.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version, counterpartyVersion)
return sdkerrors.Wrap(types.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain")
}

// OnChanOpenAck implements the IBCModule interface. Interchain Accounts is
// implemented to act as middleware for connected authentication modules on
// 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,
Expand All @@ -91,14 +87,12 @@ func (im IBCModule) OnChanOpenAck(
}

// OnChanOpenAck implements the IBCModule interface
//
// Host Chain
func (im IBCModule) OnChanOpenConfirm(
ctx sdk.Context,
portID,
channelID string,
) error {
return im.keeper.OnChanOpenConfirm(ctx, portID, channelID)
return sdkerrors.Wrap(types.ErrInvalidChannelFlow, "channel handshake must be initiated by controller chain")
}

// OnChanCloseInit implements the IBCModule interface
Expand All @@ -121,31 +115,15 @@ func (im IBCModule) OnChanCloseConfirm(
}

// OnRecvPacket implements the IBCModule interface
//
// Host Chain
func (im IBCModule) OnRecvPacket(
ctx sdk.Context,
packet channeltypes.Packet,
_ sdk.AccAddress,
) ibcexported.Acknowledgement {
ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)})

// only attempt the application logic if the packet data
// was successfully decoded
if ack.Success() {
err := im.keeper.OnRecvPacket(ctx, packet)
if err != nil {
ack = channeltypes.NewErrorAcknowledgement(err.Error())
}
}

// NOTE: acknowledgement will be written synchronously during IBC handler execution.
return ack
return channeltypes.NewErrorAcknowledgement("cannot receive packet on controller chain")
}

// OnAcknowledgementPacket implements the IBCModule interface
//
// Controller Chain
func (im IBCModule) OnAcknowledgementPacket(
ctx sdk.Context,
packet channeltypes.Packet,
Expand All @@ -157,8 +135,6 @@ func (im IBCModule) OnAcknowledgementPacket(
}

// OnTimeoutPacket implements the IBCModule interface
//
// Controller Chain
func (im IBCModule) OnTimeoutPacket(
ctx sdk.Context,
packet channeltypes.Packet,
Expand All @@ -180,5 +156,5 @@ func (im IBCModule) NegotiateAppVersion(
counterparty channeltypes.Counterparty,
proposedVersion string,
) (string, error) {
return im.keeper.NegotiateAppVersion(ctx, order, connectionID, portID, counterparty, proposedVersion)
return "", sdkerrors.Wrap(types.ErrInvalidChannelFlow, "ICS-27 app version negotiation is unsupported on controller chains")
}
Loading

0 comments on commit 7efc384

Please sign in to comment.