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

IBC SDK specification #5426

Merged
merged 8 commits into from
Feb 18, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 0 additions & 3 deletions docs/spec/ibc/README.md

This file was deleted.

2 changes: 2 additions & 0 deletions x/ibc/03-connection/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func HandleMsgConnectionOpenInit(ctx sdk.Context, k keeper.Keeper, msg types.Msg
sdk.NewEvent(
types.EventTypeConnectionOpenInit,
sdk.NewAttribute(types.AttributeKeyConnectionID, msg.ConnectionID),
sdk.NewAttribute(types.AttributeKeyClientID, msg.ClientID),
sdk.NewAttribute(types.AttributeKeyCounterpartyClientID, msg.Counterparty.ClientID),
),
sdk.NewEvent(
Expand All @@ -42,6 +43,7 @@ func HandleMsgConnectionOpenTry(ctx sdk.Context, k keeper.Keeper, msg types.MsgC
sdk.NewEvent(
types.EventTypeConnectionOpenTry,
sdk.NewAttribute(types.AttributeKeyConnectionID, msg.ConnectionID),
sdk.NewAttribute(types.AttributeKeyClientID, msg.ClientID),
sdk.NewAttribute(types.AttributeKeyCounterpartyClientID, msg.Counterparty.ClientID),
),
sdk.NewEvent(
Expand Down
1 change: 1 addition & 0 deletions x/ibc/03-connection/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
// IBC connection events
const (
AttributeKeyConnectionID = "connection_id"
AttributeKeyClientID = "client_id"
AttributeKeyCounterpartyClientID = "counterparty_client_id"
)

Expand Down
5 changes: 2 additions & 3 deletions x/ibc/04-channel/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ const (
CodePacketTimeout = types.CodePacketTimeout
CodeInvalidChannel = types.CodeInvalidChannel
CodeInvalidChannelState = types.CodeInvalidChannelState
AttributeKeySenderPort = types.AttributeKeySenderPort
AttributeKeyReceiverPort = types.AttributeKeyReceiverPort
AttributeKeyPortID = types.AttributeKeyPortID
AttributeCounterpartyPortID = types.AttributeCounterpartyPortID
AttributeKeyChannelID = types.AttributeKeyChannelID
AttributeKeySequence = types.AttributeKeySequence
SubModuleName = types.SubModuleName
StoreKey = types.StoreKey
RouterKey = types.RouterKey
Expand Down
19 changes: 12 additions & 7 deletions x/ibc/04-channel/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ func HandleMsgChannelOpenInit(ctx sdk.Context, k keeper.Keeper, msg types.MsgCha
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelOpenInit,
sdk.NewAttribute(types.AttributeKeySenderPort, msg.PortID),
sdk.NewAttribute(types.AttributeKeyPortID, msg.PortID),
sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelID),
sdk.NewAttribute(types.AttributeCounterpartyPortID, msg.Channel.Counterparty.PortID),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, msg.Channel.Counterparty.ChannelID),
sdk.NewAttribute(types.AttributeKeyConnectionID, msg.Channel.ConnectionHops[0]), // TODO: iterate
),
sdk.NewEvent(
sdk.EventTypeMessage,
Expand All @@ -44,9 +47,11 @@ func HandleMsgChannelOpenTry(ctx sdk.Context, k keeper.Keeper, msg types.MsgChan
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelOpenTry,
sdk.NewAttribute(types.AttributeKeyPortID, msg.PortID),
sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelID),
sdk.NewAttribute(types.AttributeKeySenderPort, msg.PortID), // TODO: double check sender and receiver
sdk.NewAttribute(types.AttributeKeyReceiverPort, msg.Channel.Counterparty.PortID),
sdk.NewAttribute(types.AttributeCounterpartyPortID, msg.Channel.Counterparty.PortID),
sdk.NewAttribute(types.AttributeCounterpartyChannelID, msg.Channel.Counterparty.ChannelID),
sdk.NewAttribute(types.AttributeKeyConnectionID, msg.Channel.ConnectionHops[0]), // TODO: iterate
),
sdk.NewEvent(
sdk.EventTypeMessage,
Expand All @@ -70,7 +75,7 @@ func HandleMsgChannelOpenAck(ctx sdk.Context, k keeper.Keeper, msg types.MsgChan
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelOpenAck,
sdk.NewAttribute(types.AttributeKeySenderPort, msg.PortID),
sdk.NewAttribute(types.AttributeKeyPortID, msg.PortID),
sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelID),
),
sdk.NewEvent(
Expand All @@ -93,7 +98,7 @@ func HandleMsgChannelOpenConfirm(ctx sdk.Context, k keeper.Keeper, msg types.Msg
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelOpenConfirm,
sdk.NewAttribute(types.AttributeKeySenderPort, msg.PortID),
sdk.NewAttribute(types.AttributeKeyPortID, msg.PortID),
sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelID),
),
sdk.NewEvent(
Expand All @@ -116,7 +121,7 @@ func HandleMsgChannelCloseInit(ctx sdk.Context, k keeper.Keeper, msg types.MsgCh
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelCloseInit,
sdk.NewAttribute(types.AttributeKeySenderPort, msg.PortID),
sdk.NewAttribute(types.AttributeKeyPortID, msg.PortID),
sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelID),
),
sdk.NewEvent(
Expand All @@ -139,7 +144,7 @@ func HandleMsgChannelCloseConfirm(ctx sdk.Context, k keeper.Keeper, msg types.Ms
ctx.EventManager().EmitEvents(sdk.Events{
sdk.NewEvent(
types.EventTypeChannelCloseConfirm,
sdk.NewAttribute(types.AttributeKeySenderPort, msg.PortID),
sdk.NewAttribute(types.AttributeKeyPortID, msg.PortID),
sdk.NewAttribute(types.AttributeKeyChannelID, msg.ChannelID),
),
sdk.NewEvent(
Expand Down
9 changes: 5 additions & 4 deletions x/ibc/04-channel/types/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (

// IBC channel events
const (
AttributeKeySenderPort = "sender_port"
AttributeKeyReceiverPort = "receiver_port"
AttributeKeyChannelID = "channel_id"
AttributeKeySequence = "sequence"
AttributeKeyConnectionID = "connection_id"
AttributeKeyPortID = "port_id"
AttributeKeyChannelID = "channel_id"
AttributeCounterpartyPortID = "counterparty_port_id"
AttributeCounterpartyChannelID = "counterparty_channel_id"
)

// IBC channel events vars
Expand Down
8 changes: 8 additions & 0 deletions x/ibc/spec/01_concepts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<!--
order: 1
-->

# Concepts

> NOTE: if you are not familiar with the IBC terminology and concepts, please read
this [document](https://github.com/cosmos/ics/blob/master/ibc/1_IBC_TERMINOLOGY.md) as prerequisite reading.
21 changes: 21 additions & 0 deletions x/ibc/spec/02_state.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
order: 2
-->

# State

The paths for the values stored in state can be found [here](https://github.com/cosmos/ics/blob/master/spec/ics-024-host-requirements/README.md#path-space). Additionally, the SDK adds
a prefix to the path to be able to aggregate the values for querying purposes.
Copy link
Contributor

Choose a reason for hiding this comment

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

This will no longer be true once the new store layout is implemented, correct?


| Prefix | Path | Value type |
|--------|------------------------------------------------------------------------|----------------|
| "0/" | "clients/{identifier}" | ClientState |
| "0/" | "clients/{identifier}/consensusState" | ConsensusState |
| "0/" | "clients/{identifier}/type" | ClientType |
| "0/" | "connections/{identifier}" | ConnectionEnd |
| "0/" | "ports/{identifier}" | CapabilityKey |
| "0/" | "ports/{identifier}/channels/{identifier}" | ChannelEnd |
| "0/" | "ports/{identifier}/channels/{identifier}/key" | CapabilityKey |
| "0/" | "ports/{identifier}/channels/{identifier}/nextSequenceRecv" | uint64 |
| "0/" | "ports/{identifier}/channels/{identifier}/packets/{sequence}" | bytes |
| "0/" | "ports/{identifier}/channels/{identifier}/acknowledgements/{sequence}" | bytes |
80 changes: 80 additions & 0 deletions x/ibc/spec/04_messages.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!--
order: 4
-->

# Messages

In this section we describe the processing of the IBC messages and the corresponding updates to the state.

## ICS 02 - Client

### MsgCreateClient

A light client is created using the `MsgCreateClient`.

```go
type MsgCreateClient struct {
ClientID string
ClientType string
ConsensusState ConsensusState
Signer AccAddress
}
```

This message is expected to fail if:

- `ClientID` is invalid (not alphanumeric or not within 10-20 characters)
- `ClientType` is not registered
- `ConsensusState` is empty
- `Signer` is empty
- A light client with the provided id and type already exist

The message creates and stores a light client with the given ID and consensus type,
stores the validator set as the `Commiter` of the given consensus state and stores
both the consensus state and its commitment root (i.e app hash).

### MsgUpdateClient

A light client is updated with a new header using the `MsgUpdateClient`.

```go
type MsgUpdateClient struct {
ClientID string
Header Header
Signer AccAddress
}
```

This message is expected to fail if:

- `ClientID` is invalid (not alphanumeric or not within 10-20 characters)
- `Header` is empty
- `Signer` is empty
- A Client hasn't been created for the given ID
- the header's client type is different from the registered one
- the client is frozen due to misbehaviour and cannot be updated

The message validates the header and updates the consensus state with the new
height, commitment root and validator sets, which are then stored.

## ICS 03 - Connection
Copy link
Contributor

Choose a reason for hiding this comment

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

Documentation to be added?


## ICS 04 - Channels

### MsgChannelOpenInit

A channel handshake is initiated by a chain A using the `MsgChannelOpenInit`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why specifically a "chain A"?

message.

```go
type MsgChannelOpenInit struct {
PortID string
ChannelID string
Channel Channel
Signer sdk.AccAddress
}
```

This message is expected to fail if:
Copy link
Contributor

Choose a reason for hiding this comment

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

When will it fail?


## ICS 20 - Fungible Token Transfer
5 changes: 5 additions & 0 deletions x/ibc/spec/05_callbacks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--
order: 5
-->

# Callbacks
147 changes: 147 additions & 0 deletions x/ibc/spec/06_events.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<!--
order: 6
-->

# Events

The IBC module emits the following events:

## ICS 02 - Client

### MsgCreateClient

| Type | Attribute Key | Attribute Value |
|---------------|---------------|-----------------|
| create_client | client_id | {clientID} |
| message | module | ibc_client |
| message | action | create_client |
| message | sender | {signer} |

### MsgUpdateClient

| Type | Attribute Key | Attribute Value |
|---------------|---------------|-----------------|
| update_client | client_id | {clientID} |
| message | module | ibc_client |
| message | action | update_client |
| message | sender | {signer} |

### MsgSubmitMisbehaviour

| Type | Attribute Key | Attribute Value |
|---------------------|---------------|---------------------|
| client_misbehaviour | client_id | {clientID} |
| message | module | evidence |
| message | action | client_misbehaviour |
| message | sender | {signer} |

## ICS 03 - Connection

### MsgConnectionOpenInit

| Type | Attribute Key | Attribute Value |
|----------------------|------------------------|-------------------------|
| connection_open_init | connection_id | {connectionID} |
| connection_open_init | client_id | {clientID} |
| connection_open_init | counterparty_client_id | {counterparty.clientID} |
| message | module | ibc_connection |
| message | action | connection_open_init |
| message | sender | {signer} |

### MsgConnectionOpenTry

| Type | Attribute Key | Attribute Value |
|---------------------|---------------|---------------------|
| connection_open_try | connection_id | {connectionID} |
| connection_open_try | client_id | {clientID} |
| message | module | ibc_connection |
| message | action | connection_open_try |
| message | sender | {signer} |

### MsgConnectionOpenAck

| Type | Attribute Key | Attribute Value |
|----------------------|------------------------|-------------------------|
| connection_open_ack | connection_id | {connectionID} |
| connection_open_ack | client_id | {clientID} |
| connection_open_init | counterparty_client_id | {counterparty.clientID} |
| message | module | ibc_connection |
| message | action | connection_open_ack |
| message | sender | {signer} |

### MsgConnectionOpenConfirm

| Type | Attribute Key | Attribute Value |
|-------------------------|---------------|-------------------------|
| connection_open_confirm | connection_id | {connectionID} |
| message | module | ibc_connection |
| message | action | connection_open_confirm |
| message | sender | {signer} |

## ICS 04 - Channel

### MsgChannelOpenInit

| Type | Attribute Key | Attribute Value |
|-------------------|-------------------------|----------------------------------|
| channel_open_init | port_id | {portID} |
| channel_open_init | channel_id | {channelID} |
| channel_open_init | counterparty_port_id | {channel.counterparty.portID} |
| channel_open_init | counterparty_channel_id | {channel.counterparty.channelID} |
| channel_open_init | connection_id | {channel.connectionHops} |
| message | module | ibc_channel |
| message | action | channel_open_init |
| message | sender | {signer} |

### MsgChannelOpenTry

| Type | Attribute Key | Attribute Value |
|------------------|-------------------------|----------------------------------|
| channel_open_try | port_id | {portID} |
| channel_open_try | channel_id | {channelID} |
| channel_open_try | counterparty_port_id | {channel.counterparty.portID} |
| channel_open_try | counterparty_channel_id | {channel.counterparty.channelID} |
| channel_open_try | connection_id | {channel.connectionHops} |
| message | module | ibc_channel |
| message | action | channel_open_try |
| message | sender | {signer} |

### MsgChannelOpenAck

| Type | Attribute Key | Attribute Value |
|------------------|---------------|------------------|
| channel_open_ack | port_id | {portID} |
| channel_open_ack | channel_id | {channelID} |
| message | module | ibc_channel |
| message | action | channel_open_ack |
| message | sender | {signer} |

### MsgChannelOpenConfirm

| Type | Attribute Key | Attribute Value |
|----------------------|---------------|----------------------|
| channel_open_confirm | port_id | {portID} |
| channel_open_confirm | channel_id | {channelID} |
| message | module | ibc_channel |
| message | action | channel_open_confirm |
| message | sender | {signer} |

### MsgChannelCloseInit

| Type | Attribute Key | Attribute Value |
|--------------------|---------------|--------------------|
| channel_close_init | port_id | {portID} |
| channel_close_init | channel_id | {channelID} |
| message | module | ibc_channel |
| message | action | channel_close_init |
| message | sender | {signer} |

### MsgChannelCloseConfirm

| Type | Attribute Key | Attribute Value |
|-----------------------|---------------|-----------------------|
| channel_close_confirm | port_id | {portID} |
| channel_close_confirm | channel_id | {channelID} |
| message | module | ibc_channel |
| message | action | channel_close_confirm |
| message | sender | {signer} |
Loading