Skip to content

Commit 90fe9c4

Browse files
Merge branch 'feat/integrate-bg-router' (early part) into chore/introduce-submodule
* 'feat/integrate-bg-router' (early part): (21 commits) test: fix raintree message target test [P2P] refactor: unicast router (#844) chore: add TECHDEBT comment Update E2E_FEATURE_LIST.md Update vault_test.go (#862) chore: return early chore: improve debug logging chore: improve comments chore: improve variable naming fix: `p2pModule#Send()` routing logic fix: interim background router bootstrapping chore: router logging improvements fix: return error chore: cleanup unused garbage chore: add missing godoc comments chore: add submodule TECHDEBT comments chore: comment cleanup chore: cleanup unused test utils [IBC] Create initial IBC module (#842) [Persistence] Adds TreeStore logger (#852) ...
2 parents fcb480e + fe42ab3 commit 90fe9c4

54 files changed

Lines changed: 1446 additions & 217 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ test_p2p_raintree: ## Run all p2p raintree related tests
423423
test_p2p_raintree_addrbook: ## Run all p2p raintree addr book related tests
424424
go test ${VERBOSE_TEST} -count=1 -tags=test -run RainTreeAddrBook -count=1 ./p2p/...
425425

426+
.PHONY: test_ibc
427+
test_ibc: ## Run all go unit tests in the IBC module
428+
go test ${VERBOSE_TEST} -count=1 -tags=test -p=1 ./ibc/...
429+
426430
# TIP: For benchmarks, consider appending `-run=^#` to avoid running unit tests in the same package
427431

428432
.PHONY: benchmark_persistence_state_hash

app/client/keybase/hashicorp/vault_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestMain(m *testing.M) {
4242
// pulls an image, creates a container based on it and runs it
4343
resource, err := pool.RunWithOptions(&dockertest.RunOptions{
4444
Repository: "vault",
45-
Tag: "latest",
45+
Tag: "1.13.3",
4646
Env: []string{
4747
"VAULT_DEV_ROOT_TOKEN_ID=dev-only-token",
4848
"VAULT_DEV_LISTEN_ADDRESS=0.0.0.0:8200",

build/config/config.validator1.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,8 @@
5757
"servicer": {
5858
"enabled": true,
5959
"chains": ["0001"]
60+
},
61+
"ibc": {
62+
"enabled": true
6063
}
6164
}

build/config/config.validator2.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
"port": "50832",
5151
"timeout": 30000,
5252
"use_cors": false
53+
},
54+
"ibc": {
55+
"enabled": true
5356
}
5457
}

build/config/config.validator3.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
"port": "50832",
5151
"timeout": 30000,
5252
"use_cors": false
53+
},
54+
"ibc": {
55+
"enabled": true
5356
}
5457
}

build/config/config.validator4.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,8 @@
5050
"port": "50832",
5151
"timeout": 30000,
5252
"use_cors": false
53+
},
54+
"ibc": {
55+
"enabled": true
5356
}
5457
}

consensus/e2e_tests/utils_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/pokt-network/pocket/consensus"
1616
typesCons "github.com/pokt-network/pocket/consensus/types"
1717
"github.com/pokt-network/pocket/internal/testutil"
18+
ibcUtils "github.com/pokt-network/pocket/internal/testutil/ibc"
1819
persistenceMocks "github.com/pokt-network/pocket/persistence/types/mocks"
1920
"github.com/pokt-network/pocket/runtime"
2021
"github.com/pokt-network/pocket/runtime/configs"
@@ -24,7 +25,6 @@ import (
2425
"github.com/pokt-network/pocket/shared"
2526
"github.com/pokt-network/pocket/shared/codec"
2627
coreTypes "github.com/pokt-network/pocket/shared/core/types"
27-
"github.com/pokt-network/pocket/shared/crypto"
2828
cryptoPocket "github.com/pokt-network/pocket/shared/crypto"
2929
"github.com/pokt-network/pocket/shared/messaging"
3030
"github.com/pokt-network/pocket/shared/modules"
@@ -122,13 +122,15 @@ func CreateTestConsensusPocketNode(
122122
telemetryMock := baseTelemetryMock(t, eventsChannel)
123123
loggerMock := baseLoggerMock(t, eventsChannel)
124124
rpcMock := baseRpcMock(t, eventsChannel)
125+
ibcMock := ibcUtils.IbcMockWithHost(t, eventsChannel)
125126

126127
for _, module := range []modules.Module{
127128
p2pMock,
128129
utilityMock,
129130
telemetryMock,
130131
loggerMock,
131132
rpcMock,
133+
ibcMock,
132134
} {
133135
bus.RegisterModule(module)
134136
}
@@ -669,7 +671,6 @@ func waitForProposalMsgs(
669671
maxWaitTime time.Duration,
670672
failOnExtraMessages bool,
671673
) ([]*anypb.Any, error) {
672-
673674
proposalMsgs, err := WaitForNetworkConsensusEvents(t, clck, eventsChannel, typesCons.HotstuffStep(step), consensus.Propose, numExpectedMsgs, maxWaitTime, failOnExtraMessages)
674675
if err != nil {
675676
return nil, err
@@ -751,7 +752,6 @@ func waitForNodeToRequestMissingBlock(
751752
startingHeight uint64,
752753
targetHeight uint64,
753754
) (*anypb.Any, error) {
754-
755755
return &anypb.Any{}, nil
756756
}
757757

@@ -765,7 +765,6 @@ func waitForNodeToReceiveMissingBlock(
765765
allNodes IdToNodeMapping,
766766
blockReq *anypb.Any,
767767
) (*anypb.Any, error) {
768-
769768
return &anypb.Any{}, nil
770769
}
771770

@@ -779,11 +778,10 @@ func waitForNodeToCatchUp(
779778
blockResponse *anypb.Any,
780779
targetHeight uint64,
781780
) error {
782-
783781
return nil
784782
}
785783

786-
func generatePlaceholderBlock(height uint64, leaderAddrr crypto.Address) *coreTypes.Block {
784+
func generatePlaceholderBlock(height uint64, leaderAddrr cryptoPocket.Address) *coreTypes.Block {
787785
blockHeader := &coreTypes.BlockHeader{
788786
Height: height,
789787
StateHash: stateHash,

ibc/docs/README.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# IBC <!-- omit in toc -->
2+
3+
- [Definitions](#definitions)
4+
- ["host"](#host)
5+
- ["light client"](#light-client)
6+
- [Overview](#overview)
7+
- [IBC Module](#ibc-module)
8+
- [Node Configuration](#node-configuration)
9+
- [Persistence](#persistence)
10+
- [Components](#components)
11+
- [ICS-24 Host Requirements](#ics-24-host-requirements)
12+
13+
## Definitions
14+
15+
### "host"
16+
17+
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.
18+
19+
### "light client"
20+
21+
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.
22+
23+
## Overview
24+
25+
![IBC High Level](./high-level-ibc.png)
26+
27+
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.
28+
29+
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.
30+
31+
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**.
32+
33+
## IBC Module
34+
35+
Pocket's IBC module is split into numerous components detailed below. The overall module layout is as follows:
36+
37+
**Note:** Not all of the different ICS components have been fully implemented yet, this is a work in progress.
38+
39+
```mermaid
40+
flowchart TB
41+
subgraph IBC[IBC Module]
42+
subgraph 23[ICS-23]
43+
VC[Vector Commitments]
44+
end
45+
subgraph 24[ICS-24]
46+
HR[Host Requirements]
47+
end
48+
subgraph I[IBC Interface]
49+
IF[ICS-25 Handler Interface]
50+
IR[ICS-26 Routing Module]
51+
end
52+
end
53+
subgraph 2[ICS-02]
54+
CL[Client Semantics]
55+
end
56+
subgraph 3[ICS-03]
57+
CO[Connection Semantics]
58+
end
59+
subgraph 5[ICS-05]
60+
PA[Port Allocation]
61+
end
62+
subgraph 4[ICS-04]
63+
CP[Channel & Packet Semantics]
64+
end
65+
subgraph 20[ICS-20]
66+
FT[Fungible Token Transfer]
67+
end
68+
IBC ---> 2
69+
IBC ---> 3
70+
IBC ---> 5
71+
IBC ---> 4
72+
IBC ---> 20
73+
```
74+
75+
### Node Configuration
76+
77+
Part of the node configurations relating to the IBC module is as follows:
78+
79+
```json
80+
"ibc": {
81+
"enabled": bool,
82+
}
83+
```
84+
85+
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.
86+
87+
**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.**
88+
89+
INVESTIGATE(M7): Look into on-chain POKT slashing/incentive conditions based on the QoS of an IBC host.
90+
91+
_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.
92+
93+
### Persistence
94+
95+
[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.
96+
97+
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.
98+
99+
## Components
100+
101+
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.
102+
103+
### ICS-24 Host Requirements
104+
105+
[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.
106+
107+
See: [ICS-24](./ics24.md) for more details on the specifics of the ICS-24 implementation for Pocket.
108+
109+
[ibc-spec]: https://github.com/cosmos/ibc
110+
[ics24]: https://github.com/cosmos/ibc/blob/main/spec/core/ics-024-host-requirements/README.md
111+
[smt]: https://github.com/pokt-network/smt

ibc/docs/high-level-ibc.png

907 KB
Loading

ibc/docs/ics24.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# ICS-24 Host Requirements <!-- omit in toc -->
2+
3+
- [Overview](#overview)
4+
- [Implementation](#implementation)
5+
- [Paths and Identifiers](#paths-and-identifiers)
6+
- [Timestamps](#timestamps)
7+
8+
## Overview
9+
10+
[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.
11+
12+
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.
13+
14+
## Implementation
15+
16+
**Note**: The ICS-24 implementation is still a work in progress and is not yet fully implemented.
17+
18+
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.
19+
20+
### Paths and Identifiers
21+
22+
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)
23+
24+
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).
25+
26+
### Timestamps
27+
28+
The `GetTimestamp()` function returns the current unix timestamp of the host machine and is used to calculate timeout periods for packets
29+
30+
[ics24]: https://github.com/cosmos/ibc/blob/main/spec/core/ics-024-host-requirements/README.md
31+
[ics20]: https://github.com/cosmos/ibc/blob/main/spec/app/ics-020-fungible-token-transfer/README.md
32+
[smt]: https://github.com/pokt-network/smt

0 commit comments

Comments
 (0)