-
Notifications
You must be signed in to change notification settings - Fork 32
[IBC] Create initial IBC module #842
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
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3cb2cee
Add test_ibc target
h5law 2a2553a
Add IBC config
h5law 79fba97
Add IBC module interface
h5law 4b47556
Add IBC module mock to consensus e2e test
h5law 73e9b9e
Add IBC commitment types
h5law 76a4c11
Add IBC related errors
h5law 942b32c
Add IBC module start to node startup logic
h5law 78ee9ee
Add initial IBC module
h5law ec7e3e1
Add IBC documentation
h5law 9898ee9
Change newHost() to return only an error
h5law e1db7cd
Update ibc/docs/README.md
h5law 2f6768d
Address comments
h5law 562d088
Add persistence info to doc
h5law 6d9c3a5
Improve validator check
h5law 969616b
Actually create module
h5law 82e5f24
Address comments
h5law b00af8b
Seperate keys into seperate files
h5law d1a4667
Add fuzz test on identifers
h5law 04887e5
Add glossary to readme
h5law cfec3a2
Move mocks into testutils
h5law fde5828
Merge branch 'main' into ibc/initial_module
h5law fe11ef0
Address comment, cache and return length in error
h5law File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,5 +57,8 @@ | |
| "servicer": { | ||
| "enabled": true, | ||
| "chains": ["0001"] | ||
| }, | ||
| "ibc": { | ||
| "enabled": true | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,5 +50,8 @@ | |
| "port": "50832", | ||
| "timeout": 30000, | ||
| "use_cors": false | ||
| }, | ||
| "ibc": { | ||
| "enabled": true | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,5 +50,8 @@ | |
| "port": "50832", | ||
| "timeout": 30000, | ||
| "use_cors": false | ||
| }, | ||
| "ibc": { | ||
| "enabled": true | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,5 +50,8 @@ | |
| "port": "50832", | ||
| "timeout": 30000, | ||
| "use_cors": false | ||
| }, | ||
| "ibc": { | ||
| "enabled": true | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # IBC <!-- omit in toc --> | ||
|
|
||
| - [Definitions](#definitions) | ||
| - ["host"](#host) | ||
| - ["light client"](#light-client) | ||
| - [Overview](#overview) | ||
| - [IBC Module](#ibc-module) | ||
| - [Node Configuration](#node-configuration) | ||
| - [Persistence](#persistence) | ||
| - [Components](#components) | ||
| - [ICS-24 Host Requirements](#ics-24-host-requirements) | ||
|
|
||
| ## Definitions | ||
|
|
||
| ### "host" | ||
|
|
||
| An IBC host refers to the node (host machine) that is running the IBC module. Relayers will interact with the hosts on each chain in order to call any IBC related functions. The IBC host is responsible for storing and interfacing with the IBC state and handling any IBC related transactions. | ||
|
|
||
| ### "light client" | ||
|
|
||
| An IBC light client refers to a consensus state verification algorithm. This is different from the traditional meaning of the term. An IBC light client will be only used for state verification and will lack many of the other features commonly found in traditional light clients. | ||
|
|
||
| ## Overview | ||
|
|
||
|  | ||
|
|
||
| Inter-Blockchain Communication (IBC) is a protocol that enables trustless communication between two chains. It allows these chains to interact by relaying IBC packets. The process involves two IBC-enabled chains, referred to as **chain A** and **chain B**, each running a light client for the other chain on their network. | ||
|
Olshansk marked this conversation as resolved.
|
||
|
|
||
| To transfer native tokens from **chain A** to **chain B**, certain prerequisites must be met. First, a connection between the two chains must be established. Then, a channel and port need to be opened on this connection. Additionally, a light client for the opposing chain should be set up on both ends of the connection. Finally, a relayer is required to facilitate the actual transfer of the packet. | ||
|
|
||
| Once these components are in place, **chain A** can commit an IBC packet to its state, which contains transaction information. It also generates a proof that specifies the inclusion of the packet in the state at a particular height. The relayer submits this proof to **chain B**, where it is verified. If the proof is valid, **chain B** can respond accordingly, such as by sending an IBC token from **chain A** to the designated address on **chain B**. | ||
|
|
||
| ## IBC Module | ||
|
|
||
| Pocket's IBC module is split into numerous components detailed below. The overall module layout is as follows: | ||
|
|
||
| **Note:** Not all of the different ICS components have been fully implemented yet, this is a work in progress. | ||
|
|
||
| ```mermaid | ||
| flowchart TB | ||
|
h5law marked this conversation as resolved.
Olshansk marked this conversation as resolved.
|
||
| subgraph IBC[IBC Module] | ||
| subgraph 23[ICS-23] | ||
| VC[Vector Commitments] | ||
| end | ||
| subgraph 24[ICS-24] | ||
| HR[Host Requirements] | ||
| end | ||
| subgraph I[IBC Interface] | ||
| IF[ICS-25 Handler Interface] | ||
| IR[ICS-26 Routing Module] | ||
| end | ||
| end | ||
| subgraph 2[ICS-02] | ||
| CL[Client Semantics] | ||
| end | ||
| subgraph 3[ICS-03] | ||
| CO[Connection Semantics] | ||
| end | ||
| subgraph 5[ICS-05] | ||
| PA[Port Allocation] | ||
| end | ||
| subgraph 4[ICS-04] | ||
| CP[Channel & Packet Semantics] | ||
| end | ||
| subgraph 20[ICS-20] | ||
| FT[Fungible Token Transfer] | ||
| end | ||
| IBC ---> 2 | ||
| IBC ---> 3 | ||
| IBC ---> 5 | ||
| IBC ---> 4 | ||
| IBC ---> 20 | ||
| ``` | ||
|
|
||
| ### Node Configuration | ||
|
|
||
| Part of the node configurations relating to the IBC module is as follows: | ||
|
|
||
| ```json | ||
| "ibc": { | ||
| "enabled": bool, | ||
| } | ||
| ``` | ||
|
|
||
| If a node enables the IBC module, and is a validator, then the IBC module will automatically create an IBC host on startup. As the host defines the connections, channels and ports - which must stay persistent, the node should be a validator with little risk of suddenly closing any of these while open. Any tokens transferred over a connection/channel/port are unique to that combination they can only be returned over the same combination. | ||
|
|
||
| **If the channel is to close without warning then tokens will be unable to be returned to their source. It is for this reason that only validators are able to become IBC hosts.** | ||
|
h5law marked this conversation as resolved.
|
||
|
|
||
| INVESTIGATE(M7): Look into on-chain POKT slashing/incentive conditions based on the QoS of an IBC host. | ||
|
|
||
| _Note_: Connections, Channels and Ports in IBC are not the same as networking connections, channels and ports. They are stored in the chain state and are used by relayers to signify where each IBC packet should go when being relayed. When closing a channel the IBC host must submit to the state a `ChanCloseInit` IBC packet. If this happens without warning, the funds transferred on this channel will become unrecoverable. | ||
|
Olshansk marked this conversation as resolved.
|
||
|
|
||
| ### Persistence | ||
|
|
||
| [ICS24][ics24] defines the IBC stores and these must be a part of the Pocket networks consensus state. As such the `ibcTree` is defined as one of the state trees used to generate the root hash. This tree contains the relevant information the hosts/relayers need to be able to use IBC, in accordance with ICS-24 and the other ICS components. | ||
|
|
||
| TODO([#854](https://github.com/pokt-network/pocket/issues/854)): Add a local cache for changes to the state for use in the event of the node crashing. | ||
|
|
||
| ## Components | ||
|
|
||
| The [IBC specification][ibc-spec] details numerous Interchain Standards (ICSs) that together form the IBC protocol. The following gives an overview of the different components implemented in Pocket's IBC module. | ||
|
h5law marked this conversation as resolved.
|
||
|
|
||
| ### ICS-24 Host Requirements | ||
|
|
||
| [ICS-24][ics24] defines the requirements for a host chain to be IBC compatible. This includes the definition of a store system to hold IBC related data in a provable (and also a private) fashion. This implementation uses the [SMT][smt] rather than the IAVL tree used by `cosmos-sdk` for its provable stores. ICS-24 also defines the Event Logging system that is used to store and query IBC related events for the relayers to read packet data and timeouts, as only the proofs of these are stored in the chain state. | ||
|
|
||
| See: [ICS-24](./ics24.md) for more details on the specifics of the ICS-24 implementation for Pocket. | ||
|
|
||
| [ibc-spec]: https://github.com/cosmos/ibc | ||
| [ics24]: https://github.com/cosmos/ibc/blob/main/spec/core/ics-024-host-requirements/README.md | ||
| [smt]: https://github.com/pokt-network/smt | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| # ICS-24 Host Requirements <!-- omit in toc --> | ||
|
|
||
| - [Overview](#overview) | ||
| - [Implementation](#implementation) | ||
| - [Paths and Identifiers](#paths-and-identifiers) | ||
| - [Timestamps](#timestamps) | ||
|
|
||
| ## Overview | ||
|
|
||
| [ICS-24][ics24] details the requirements of the host chain, in order for it to be compatible with IBC. A host is defined as a node on a chain that runs the IBC software. A host has the ability to create connections with counterparty chains, open channels, and ports as well as commit proofs to the consensus state of its own chain for the relayer to submit to another chain. The host is responsible to managing and creating clients and all other aspects of the IBC module. | ||
|
|
||
| As token transfers as defined in [ICS-20][ics20] work on a lock and mint pattern, any tokens sent from **chain A** to **chain B** will have a denomination unique to the connection/channel/port combination that the packet was sent over. This means that if a host where to shutdown a connection or channel without warning any tokens yet to be returned to the host chain would be lost. For this reason, only validator nodes are able to become hosts, as they provide the most reliability out of the different node types. | ||
|
|
||
| ## Implementation | ||
|
|
||
| **Note**: The ICS-24 implementation is still a work in progress and is not yet fully implemented. | ||
|
|
||
| ICS-24 has numerous sub components that must be implemented in order for the host to be fully functional. These range from type definitions for identifiers, paths and stores as well as the methods to interact with them. Alongside these ICS-24 also defines the Event Logging system which is used to store the packet data and timeouts for the relayers to read, as only the `CommitmentProof` objects are committed to the chain state. In addition to these numerous other features are part of ICS-24 that are closely linked to other ICS components such as consensus state introspection and client state validation. | ||
|
|
||
| ### Paths and Identifiers | ||
|
|
||
| Paths are defined as bytestrings that are used to access the elements in the different stores. They are built with the function `ApplyPrefix()` which takes a store key as a prefix and a path string and will return the key to access an element in the specific store. The logic for paths can be found in [host/keys.go](../host/keys.go) and [host/prefix.go](../host/prefix.go) | ||
|
|
||
| Identifiers are bytestrings constrained to specific characters and lengths depending on their usages. They are used to identify: channels, clients, connections and ports. Although the minimum length of the identifiers is much less we use a minimum length of 32 bytes and a maximum length that varies depending on the use case to randomly generate identifiers. This allows for an extremely low chance of collision between identifiers. Identifiers have no significance beyond their use to store different elements in the IBC stores and as such there is no need for non-random identifiers. The logic for identifiers can be found in [host/identifiers.go](../host/identifiers.go). | ||
|
|
||
| ### Timestamps | ||
|
|
||
| The `GetTimestamp()` function returns the current unix timestamp of the host machine and is used to calculate timeout periods for packets | ||
|
|
||
| [ics24]: https://github.com/cosmos/ibc/blob/main/spec/core/ics-024-host-requirements/README.md | ||
| [ics20]: https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md | ||
| [smt]: https://github.com/pokt-network/smt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package ibc | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/pokt-network/pocket/shared/modules" | ||
| ) | ||
|
|
||
| var _ modules.IBCHost = &host{} | ||
|
|
||
| type host struct { | ||
| logger *modules.Logger | ||
| } | ||
|
|
||
| // GetTimestamp returns the current unix timestamp | ||
| func (h *host) GetTimestamp() uint64 { | ||
| return uint64(time.Now().Unix()) | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wdyt about adding a persistence (or something) section which covers what network state this module interacts with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added a brief section to cover this but the rest of the persistence info will come in the ICS-24 Store PR as this is where interfacing with persistence actually comes into play