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

update core IBC docs #7560

Merged
merged 27 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
4ed49ad
update state
colin-axner Oct 15, 2020
2ca034d
add empty concept fields, update callbacks and messages
colin-axner Oct 15, 2020
eb81686
Merge branch 'master' of github.com:cosmos/cosmos-sdk into colin/6134…
colin-axner Oct 19, 2020
96b6bc7
merge master and fix merge conflict
colin-axner Oct 19, 2020
617747e
update client creation, update and upgrade section
colin-axner Oct 19, 2020
35f7562
add packet lifecycle concepts
colin-axner Oct 19, 2020
57cfa53
Merge branch 'master' of github.com:cosmos/cosmos-sdk into colin/6134…
colin-axner Oct 19, 2020
6d23d71
add host and proof section
colin-axner Oct 19, 2020
681aa59
add connection handshake section
colin-axner Oct 19, 2020
d70b87f
add channel handshakes
colin-axner Oct 20, 2020
d0b1e3f
Merge branch 'master' into colin/6134-core-docs
colin-axner Oct 20, 2020
966b05b
Merge branch 'master' into colin/6134-core-docs
colin-axner Oct 26, 2020
e1e3c6a
state transitions
colin-axner Oct 26, 2020
3fe3ac1
Merge branch 'colin/6134-core-docs' of github.com:cosmos/cosmos-sdk i…
colin-axner Oct 26, 2020
7dfe2c0
self review fixes
colin-axner Oct 26, 2020
5636ac5
Merge branch 'master' into colin/6134-core-docs
colin-axner Oct 26, 2020
f3eb008
Apply suggestions from code review
colin-axner Oct 26, 2020
84d39d2
apply @fedekunze review suggestions
colin-axner Oct 26, 2020
43bf376
Merge branch 'colin/6134-core-docs' of github.com:cosmos/cosmos-sdk i…
colin-axner Oct 26, 2020
c87090b
packet data section
colin-axner Oct 26, 2020
9073e26
Apply suggestions from code review
colin-axner Oct 27, 2020
a41dabd
add @cwgoes and @fedekunze review suggestions
colin-axner Oct 27, 2020
2ab66f1
Merge branch 'colin/6134-core-docs' of github.com:cosmos/cosmos-sdk i…
colin-axner Oct 27, 2020
5f90fbb
fix typos
colin-axner Oct 27, 2020
9286e71
Merge branch 'master' into colin/6134-core-docs
colin-axner Oct 27, 2020
651c759
Merge branch 'master' into colin/6134-core-docs
fedekunze Oct 27, 2020
74d4938
Merge branch 'master' into colin/6134-core-docs
mergify[bot] Oct 27, 2020
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
2 changes: 1 addition & 1 deletion x/ibc/core/04-channel/keeper/handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (k Keeper) ChanOpenConfirm(
//
// This section defines the set of functions required to close a channel handshake
// as defined in https://github.com/cosmos/ics/tree/master/spec/ics-004-channel-and-packet-semantics#closing-handshake

//
// ChanCloseInit is called by either module to close their end of the channel. Once
// closed, channels cannot be reopened.
func (k Keeper) ChanCloseInit(
Expand Down
1 change: 1 addition & 0 deletions x/ibc/core/05-port/types/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type IBCModule interface {
) error

// OnRecvPacket must return the acknowledgement bytes
// In the case of an asynchronous acknowledgement, nil should be returned.
OnRecvPacket(
ctx sdk.Context,
packet channeltypes.Packet,
Expand Down
270 changes: 229 additions & 41 deletions x/ibc/core/spec/01_concepts.md

Large diffs are not rendered by default.

32 changes: 18 additions & 14 deletions x/ibc/core/spec/02_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ 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.
The paths for the values stored in state is defined [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.
The client type is not stored since it can be obtained through the client state.

| Prefix | Path | Value type |
|--------|------------------------------------------------------------------------|----------------|
| "0/" | "clients/{identifier}/clientState" | ClientState |
| "0/" | "clients/{identifier}/consensusStates/{height}" | 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 |
| Prefix | Path | Value type |
|--------|-----------------------------------------------------------------------------|----------------|
| "0/" | "clients/{identifier}/clientState" | ClientState |
| "0/" | "clients/{identifier}/consensusStates/{height}" | ConsensusState |
| "0/" | "clients/{identifier}/connections" | []string |
| "0/" | "connections/{identifier}" | ConnectionEnd |
| "0/" | "ports/{identifier}" | CapabilityKey |
| "0/" | "channelEnds/ports/{identifier}/channels/{identifier}" | ChannelEnd |
| "0/" | "capabilities/ports/{identifier}/channels/{identifier}/key" | CapabilityKey |
| "0/" | "seqSends/ports/{identifier}/channels/{identifier}/nextSequenceSend" | uint64 |
| "0/" | "seqRecvs/ports/{identifier}/channels/{identifier}/nextSequenceRecv" | uint64 |
| "0/" | "seqAcks/ports/{identifier}/channels/{identifier}/nextSequenceAck" | uint64 |
| "0/" | "commitments/ports/{identifier}/channels/{identifier}/packets/{sequence}" | bytes |
| "0/" | "receipts/ports/{identifier}/channels/{identifier}/receipts/{sequence}" | bytes |
| "0/" | "acks/ports/{identifier}/channels/{identifier}/acknowledgements/{sequence}" | bytes |
99 changes: 99 additions & 0 deletions x/ibc/core/spec/03_state_transitions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,102 @@ order: 3

# State Transitions

The described state transitions assume successful message exection.

## Create Client

`MsgCreateClient` will initialize and store a `ClientState` and `ConsensusState` in the sub-store
created using the given client identifier.

## Update Client

`MsgUpdateClient` will update the `ClientState` and create a new `ConsensusState` for the
update height.

## Misbehaviour

`MsgSubmitMisbehaviour` will freeze a client.

## Upgrade Client

`MsgUpgradeClient` will upgrade the `ClientState` and `ConsensusState` to the update chain level
parameters and if applicable will update to the new light client implementation.

## Client Update Proposal

An Update Client Proposal will unfreeze a client and set an updated `ClientState` and a new
`ConsensusState`.

## Connection Open Init

`MsgConnectionOpenInit` will initialize a connection state in INIT.

## Connection Open Try

`MsgConnectionOpenTry` will initialize or update a connection state to be in TRYOPEN.

## Connection Open Ack

`MsgConnectionOpenAck` will update a connection state from INIT or TRYOPEN to be in OPEN.

## Connection Open Confirm

`MsgConnectionOpenAck` will update a connection state from TRYOPEN to OPEN.

## Channel Open Init

`MsgChannelOpenInit` will initialize a channel state in INIT. It will create a channel capability
and set all Send, Receive and Ack Sequences to 1 for the channel.

## Channel Open Try

`MsgChannelOpenTry` will initialize or update a channel state to be in TRYOPEN. If the channel
is being initialized, It will create a channel capability and set all Send, Receive and Ack
Sequences to 1 for the channel.

## Channel Open Ack

`MsgChannelOpenAck` will update the channel state to OPEN. It will set the version and channel
identifier for its counterparty.

## Channel Open Confirm

`MsgChannelOpenConfirm` will update the channel state to OPEN.

## Channel Close Init

`MsgChannelCloseInit` will update the channel state to CLOSED.

## Channel Close Confirm

`MsgChannelCloseConfirm` will update the channel state to CLOSED.

## Send Packet

A application calling `ChannelKeeper.SendPacket` will incremenet the next sequence send and set
a hash of the packet as the packet commitment.

## Receive Packet

`MsgRecvPacket` will increment the next sequence receive for ORDERED channels and set a packet
receipt for UNORDERED channels.

## Write Acknowledgement

`WriteAcknowledgement` may be executed synchronously during the execution of `MsgRecvPacket` or
asynchonously by an application module. It writes an acknowledgement to the store.

## Acknowledge Packet

`MsgAcknowledgePacket` deletes the packet commitment and for ORDERED channels increments next
sequences ack.

## Timeout Packet

`MsgTimeoutPacket` deletes the packet commitment and for ORDERED channels sets the channel state
to CLOSED.

## Timeout Packet on Channel Closure

`MsgTimeoutOnClose` deletes the packet commitment and for ORDERED channels sets the channel state
to CLOSED.
47 changes: 35 additions & 12 deletions x/ibc/core/spec/04_messages.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ This message is expected to fail if:
- `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).
The message creates and stores a light client with an initial consensus state for the given client
identifier.

### MsgUpdateClient

Expand All @@ -51,11 +50,36 @@ This message is expected to fail if:
- `Header` is empty or invalid
- `Signer` is empty
- A `ClientState` 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 client is frozen due to misbehaviour and cannot be updated
- The header fails to provide a valid update for the client

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

### MsgUpgradeClient
```go
type MsgUpgradeClient struct {
ClientId string
ClientState *types.Any // proto-packed client state
UpgradeHeight *Height
ProofUpgrade []byte
Signer string
}
```

This message is expected to fail if:

- `ClientId` is invalid (not alphanumeric or not within 10-20 characters)
- `ClientState` is empty or invalid
- `UpgradeHeight` is empty or zero
- `ProofUpgrade` is empty
- `Signer` is empty
- A `ClientState` hasn't been created for the given ID
- The client is frozen due to misbehaviour and cannot be upgraded
- The upgrade proof fails

The message upgrades the client state and consensus state upon successful validation of a
chain upgrade.

### MsgSubmitMisbehaviour

Expand All @@ -77,8 +101,7 @@ This message is expected to fail if:
- A `ClientState` hasn't been created for the given ID
- `Misbehaviour` check failed

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

## ICS 03 - Connection

Expand Down Expand Up @@ -432,7 +455,7 @@ This message is expected to fail if:
- `Packet` fails basic validation
- `Proof` does not prove that the packet has not been received on the counterparty chain.

The message times out a packet on chain B.
The message times out a packet that was sent on chain A and never received on chain B.

### MsgTimeoutOnClose

Expand Down Expand Up @@ -461,7 +484,7 @@ This message is expected to fail if:
- `Proof` does not prove that the packet has not been received on the counterparty chain.
- `ProofClose` does not prove that the counterparty channel end has been closed.

The message times out a packet on chain B.
The message times out a packet that was sent on chain A and never received on chain B.

### MsgAcknowledgement

Expand All @@ -486,4 +509,4 @@ This message is expected to fail if:
- `Acknowledgement` is empty
- `Proof` does not prove that the counterparty received the `Packet`.

The message receives a packet on chain A.
The message acknowledges that the packet sent from chainA was received on chain B.
4 changes: 3 additions & 1 deletion x/ibc/core/spec/05_callbacks.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ order: 5

# Callbacks

Application modules implementing the IBC module must implement the following callbacks as found in [05-port](../core/05-port/types/module.go).
Application modules implementing the IBC module must implement the following callbacks as found in [05-port](../05-port/types/module.go).
More information on how to implement these callbacks can be found in the [implementation guide](../../../../docs/ibc/custom.md).

```go
// IBCModule defines an interface that implements all the callbacks
Expand Down Expand Up @@ -59,6 +60,7 @@ type IBCModule interface {
) error

// OnRecvPacket must return the acknowledgement bytes
// In the case of an asynchronous acknowledgement, nil should be returned.
OnRecvPacket(
ctx sdk.Context,
packet channeltypes.Packet,
Expand Down