Skip to content

Commit

Permalink
Merge pull request cosmos#4 from informalsystems/interchain-security-…
Browse files Browse the repository at this point in the history
…2-v3.0.0-rebase

Interchain security 2 v3.0.0 rebase
  • Loading branch information
sainoe authored Jun 21, 2022
2 parents 1317331 + 235b82b commit 83aa279
Show file tree
Hide file tree
Showing 51 changed files with 1,228 additions and 500 deletions.
109 changes: 93 additions & 16 deletions CHANGELOG.md

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions docs/.vuepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,37 +109,37 @@ module.exports = {
{
title: "Interchain Accounts",
directory: true,
path: "/app-modules",
path: "/apps",
children: [
{
title: "Overview",
directory: false,
path: "/app-modules/interchain-accounts/overview.html"
path: "/apps/interchain-accounts/overview.html"
},
{
title: "Authentication Modules",
directory: false,
path: "/app-modules/interchain-accounts/auth-modules.html"
path: "/apps/interchain-accounts/auth-modules.html"
},
{
title: "Active Channels",
directory: false,
path: "/app-modules/interchain-accounts/active-channels.html"
path: "/apps/interchain-accounts/active-channels.html"
},
{
title: "Integration",
directory: false,
path: "/app-modules/interchain-accounts/integration.html"
path: "/apps/interchain-accounts/integration.html"
},
{
title: "Parameters",
directory: false,
path: "/app-modules/interchain-accounts/parameters.html"
path: "/apps/interchain-accounts/parameters.html"
},
{
title: "Transactions",
directory: false,
path: "/app-modules/interchain-accounts/transactions.html"
path: "/apps/interchain-accounts/transactions.html"
},
]
},
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,13 @@ If the controller chain is connected to a host chain using the host module on ib

Begin by unmarshaling the acknowledgement into sdk.TxMsgData:
```go
var ack channeltypes.Acknowledgement
if err := channeltypes.SubModuleCdc.UnmarshalJSON(acknowledgement, &ack); err != nil {
return err
}

txMsgData := &sdk.TxMsgData{}
if err := proto.Unmarshal(ack.Acknowledgement(), txMsgData); err != nil {
if err := proto.Unmarshal(ack.GetResult(), txMsgData); err != nil {
return err
}
```
Expand All @@ -232,6 +237,8 @@ The auth module should interpret the txMsgData.Data as follows:
```go
switch len(txMsgData.Data) {
case 0:
// see documentation below for SDK 0.46.x or greater
default:
for _, msgData := range txMsgData.Data {
if err := handler(msgData); err != nil {
return err
Expand All @@ -246,24 +253,24 @@ A router could be used, or more simply a switch statement.

```go
func handler(msgData sdk.MsgData) error {
switch msgData.TypeURL {
case banktypes.MsgSend:
switch msgData.MsgType {
case sdk.MsgTypeURL(&banktypes.MsgSend{}):
msgResponse := &banktypes.MsgSendResponse{}
if err := proto.Unmarshal(msgData.Data, msgResponse}; err != nil {
return err
}

handleBankSendMsg(msgResponse)

case stakingtypes.MsgDelegate:
case sdk.MsgTypeURL(&stakingtypes.MsgDelegate{}):
msgResponse := &stakingtypes.MsgDelegateResponse{}
if err := proto.Unmarshal(msgData.Data, msgResponse}; err != nil {
return err
}

handleStakingDelegateMsg(msgResponse)

case transfertypes.MsgTransfer:
case sdk.MsgTypeURL(&transfertypes.MsgTransfer{}):
msgResponse := &transfertypes.MsgTransferResponse{}
if err := proto.Unmarshal(msgData.Data, msgResponse}; err != nil {
return err
Expand All @@ -281,8 +288,8 @@ The auth module should interpret the txMsgData.Responses as follows:

```go
...
// switch statement from above continued
default:
// switch statement from above
case 0:
for _, any := range txMsgData.MsgResponses {
if err := handleAny(any); err != nil {
return err
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions docs/ibc/integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ func NewApp(...args) *App {

// Create IBC Keeper
app.IBCKeeper = ibckeeper.NewKeeper(
appCodec, keys[ibchost.StoreKey], app.StakingKeeper, scopedIBCKeeper,
appCodec, keys[ibchost.StoreKey], app.GetSubspace(ibchost.ModuleName), app.StakingKeeper, app.UpgradeKeeper, scopedIBCKeeper,
)

// Create Transfer Keepers
app.TransferKeeper = ibctransferkeeper.NewKeeper(
appCodec, keys[ibctransfertypes.StoreKey],
app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
appCodec, keys[ibctransfertypes.StoreKey], app.GetSubspace(ibctransfertypes.ModuleName),
app.IBCKeeper.ChannelKeeper, app.IBCKeeper.ChannelKeeper, &app.IBCKeeper.PortKeeper,
app.AccountKeeper, app.BankKeeper, scopedTransferKeeper,
)
transferModule := transfer.NewAppModule(app.TransferKeeper)
Expand Down
35 changes: 35 additions & 0 deletions docs/ibc/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
- [MsgTimeoutOnCloseResponse](#ibc.core.channel.v1.MsgTimeoutOnCloseResponse)
- [MsgTimeoutResponse](#ibc.core.channel.v1.MsgTimeoutResponse)

- [ResponseResultType](#ibc.core.channel.v1.ResponseResultType)

- [Msg](#ibc.core.channel.v1.Msg)

- [ibc/core/client/v1/genesis.proto](#ibc/core/client/v1/genesis.proto)
Expand Down Expand Up @@ -1738,6 +1740,11 @@ MsgAcknowledgement receives incoming IBC acknowledgement
MsgAcknowledgementResponse defines the Msg/Acknowledgement response type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |





Expand Down Expand Up @@ -1954,6 +1961,11 @@ MsgRecvPacket receives incoming IBC packet
MsgRecvPacketResponse defines the Msg/RecvPacket response type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |





Expand Down Expand Up @@ -2003,6 +2015,11 @@ MsgTimeoutOnClose timed-out packet upon counterparty channel closure.
MsgTimeoutOnCloseResponse defines the Msg/TimeoutOnClose response type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |





Expand All @@ -2013,11 +2030,29 @@ MsgTimeoutOnCloseResponse defines the Msg/TimeoutOnClose response type.
MsgTimeoutResponse defines the Msg/Timeout response type.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `result` | [ResponseResultType](#ibc.core.channel.v1.ResponseResultType) | | |





<!-- end messages -->


<a name="ibc.core.channel.v1.ResponseResultType"></a>

### ResponseResultType
ResponseResultType defines the possible outcomes of the execution of a message

| Name | Number | Description |
| ---- | ------ | ----------- |
| RESPONSE_RESULT_UNSPECIFIED | 0 | Default zero value enumeration |
| RESPONSE_RESULT_NOOP | 1 | The message did not call the IBC application callbacks (because, for example, the packet had already been relayed) |
| RESPONSE_RESULT_SUCCESS | 2 | The message was executed successfully |


<!-- end enums -->

<!-- end HasExtensions -->
Expand Down
2 changes: 1 addition & 1 deletion docs/ibc/relayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ a module event emission with the attribute value `ibc_<submodulename>` (02-clien

### Subscribing with Tendermint

Calling the Tendermint RPC method `Subscribe` via [Tendermint's Websocket](https://docs.tendermint.com/master/rpc/) will return events using
Calling the Tendermint RPC method `Subscribe` via [Tendermint's Websocket](https://docs.tendermint.com/v0.35/rpc/) will return events using
Tendermint's internal representation of them. Instead of receiving back a list of events as they
were emitted, Tendermint will return the type `map[string][]string` which maps a string in the
form `<event_type>.<attribute_key>` to `attribute_value`. This causes extraction of the event
Expand Down
110 changes: 109 additions & 1 deletion docs/migrations/v2-to-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ No genesis or in-place migrations are required when upgrading from v1 or v2 of i

## Chains

### IS04 - Channel

The `WriteAcknowledgement` API now takes the `exported.Acknowledgement` type instead of passing in the acknowledgement byte array directly.
This is an API breaking change and as such IBC application developers will have to update any calls to `WriteAcknowledgement`.


### ICS20

The `transferkeeper.NewKeeper(...)` now takes in an ICS4Wrapper.
Expand All @@ -26,7 +32,101 @@ The ICS4Wrapper should be the IBC Channel Keeper unless ICS 20 is being connecte
### ICS27

ICS27 Interchain Accounts has been added as a supported IBC application of ibc-go.
Please see the [ICS27 documentation](../app-modules/interchain-accounts/overview.md) for more information.
Please see the [ICS27 documentation](../apps/interchain-accounts/overview.md) for more information.

### Upgrade Proposal

If the chain will adopt ICS27, it must set the appropriate params during the execution of the upgrade handler in `app.go`:
```go
app.UpgradeKeeper.SetUpgradeHandler("v3",
func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
// set the ICS27 consensus version so InitGenesis is not run
fromVM[icatypes.ModuleName] = icamodule.ConsensusVersion()

// create ICS27 Controller submodule params
controllerParams := icacontrollertypes.Params{
ControllerEnabled: true,
}

// create ICS27 Host submodule params
hostParams := icahosttypes.Params{
HostEnabled: true,
AllowMessages: []string{"/cosmos.bank.v1beta1.MsgSend", ...},
}

// initialize ICS27 module
icamodule.InitModule(ctx, controllerParams, hostParams)

...

return app.mm.RunMigrations(ctx, app.configurator, fromVM)
})

```

The host and controller submodule params only need to be set if the chain integrates those submodules.
For example, if a chain chooses not to integrate a controller submodule, it may pass empty params into `InitModule`.

#### Add `StoreUpgrades` for ICS27 module

For ICS27 it is also necessary to [manually add store upgrades](https://docs.cosmos.network/v0.44/core/upgrade.html#add-storeupgrades-for-new-modules) for the new ICS27 module and then configure the store loader to apply those upgrades in `app.go`:

```go
if upgradeInfo.Name == "v3" && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := store.StoreUpgrades{
Added: []string{icacontrollertypes.StoreKey, icahosttypes.StoreKey},
}

app.SetStoreLoader(upgradetypes.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
}
```

This ensures that the new module's stores are added to the multistore before the migrations begin.
The host and controller submodule keys only need to be added if the chain integrates those submodules.
For example, if a chain chooses not to integrate a controller submodule, it does not need to add the controller key to the `Added` field.


### Genesis migrations

If the chain will adopt ICS27 and chooses to upgrade via a genesis export, then the ICS27 parameters must be set during genesis migration.

The migration code required may look like:

```go
controllerGenesisState := icatypes.DefaultControllerGenesis()
// overwrite parameters as desired
controllerGenesisState.Params = icacontrollertypes.Params{
ControllerEnabled: true,
}

hostGenesisState := icatypes.DefaultHostGenesis()
// overwrite parameters as desired
hostGenesisState.Params = icahosttypes.Params{
HostEnabled: true,
AllowMessages: []string{"/cosmos.bank.v1beta1.MsgSend", ...},
}

icaGenesisState := icatypes.NewGenesisState(controllerGenesisState, hostGenesisState)

// set new ics27 genesis state
appState[icatypes.ModuleName] = clientCtx.JSONCodec.MustMarshalJSON(icaGenesisState)
```

### Ante decorator

The field of type `channelkeeper.Keeper` in the `AnteDecorator` structure has been replaced with a field of type `*keeper.Keeper`:

```diff
type AnteDecorator struct {
- k channelkeeper.Keeper
+ k *keeper.Keeper
}

- func NewAnteDecorator(k channelkeeper.Keeper) AnteDecorator {
+ func NewAnteDecorator(k *keeper.Keeper) AnteDecorator {
return AnteDecorator{k: k}
}
```

## IBC Apps

Expand All @@ -39,6 +139,10 @@ IBC applications must perform application version negoitation in `OnChanOpenTry`
The negotiated application version then must be returned in `OnChanOpenTry` to core IBC.
Core IBC will set this version in the TRYOPEN channel.

### `OnChanOpenAck` will take additional `counterpartyChannelID` argument
The `OnChanOpenAck` application callback has been modified.
The arguments now include the counterparty channel id.

### `NegotiateAppVersion` removed from `IBCModule` interface

Previously this logic was handled by the `NegotiateAppVersion` function.
Expand All @@ -64,6 +168,10 @@ As apart of this release, the mock module now supports middleware testing. Pleas

Please review the [mock](../../testing/mock/ibc_module.go) and [transfer](../../modules/apps/transfer/ibc_module.go) modules as examples. Additionally, [simapp](../../testing/simapp/app.go) provides an example of how `IBCModule` types should now be added to the IBC router in favour of `AppModule`.

### IBC testing package

`TestChain`s are now created with chainID's beginning from an index of 1. Any calls to `GetChainID(0)` will now fail. Please increment all calls to `GetChainID` by 1.

## Relayers

`AppVersion` gRPC has been removed.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ replace github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alp

require (
github.com/armon/go-metrics v0.3.10
github.com/confio/ics23/go v0.6.6
github.com/confio/ics23/go v0.7.0
github.com/cosmos/cosmos-sdk v0.45.2-0.20220210215401-58c103ca4daf
github.com/gogo/protobuf v1.3.3
github.com/golang/protobuf v1.5.2
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:z
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
github.com/coinbase/rosetta-sdk-go v0.7.0 h1:lmTO/JEpCvZgpbkOITL95rA80CPKb5CtMzLaqF2mCNg=
github.com/coinbase/rosetta-sdk-go v0.7.0/go.mod h1:7nD3oBPIiHqhRprqvMgPoGxe/nyq3yftRmpsy29coWE=
github.com/confio/ics23/go v0.6.6 h1:pkOy18YxxJ/r0XFDCnrl4Bjv6h4LkBSpLS6F38mrKL8=
github.com/confio/ics23/go v0.6.6/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/confio/ics23/go v0.7.0 h1:00d2kukk7sPoHWL4zZBZwzxnpA2pec1NPdwbSokJ5w8=
github.com/confio/ics23/go v0.7.0/go.mod h1:E45NqnlpxGnpfTWL/xauN7MRwEE28T4Dd4uraToOaKg=
github.com/containerd/console v1.0.2/go.mod h1:ytZPjGgY2oeTkAONYafi2kSj0aYggsf8acV1PGKCbzQ=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6 h1:NmTXa/uVnDyp0TY5MKi197+3HWcnYWfnHGyaFthlnGw=
github.com/containerd/continuity v0.0.0-20190827140505-75bee3e2ccb6/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
Expand Down
3 changes: 2 additions & 1 deletion modules/apps/27-interchain-accounts/controller/ibc_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (im IBCModule) OnChanOpenAck(
ctx sdk.Context,
portID,
channelID string,
counterpartyChannelID string,
counterpartyVersion string,
) error {
if !im.keeper.IsControllerEnabled(ctx) {
Expand All @@ -91,7 +92,7 @@ func (im IBCModule) OnChanOpenAck(
}

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

// OnChanOpenAck implements the IBCModule interface
Expand Down
Loading

0 comments on commit 83aa279

Please sign in to comment.