Skip to content

Commit e1f8d96

Browse files
authored
Describe pinned env (#406)
Describe pinned env
1 parent 6979c24 commit e1f8d96

File tree

2 files changed

+95
-4
lines changed

2 files changed

+95
-4
lines changed

node/api/channel_ws_api.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Roles:
3232
| from | string | Participant's account to take tokens from | Yes |
3333
| to | string | Participant's account to add tokens to | Yes |
3434
| amount | integer | Amount of tokens to transfer | Yes |
35+
| block_hash | string | The on-chain block hash to pin the off-chain environment | No |
3536

3637
#### Example
3738
```javascript
@@ -238,6 +239,7 @@ Roles:
238239
| Name | Type | Description | Required |
239240
| ---- | ---- | ----------- | -------- |
240241
| amount | integer | Amount of tokens to deposit in the channel | Yes |
242+
| block_hash | string | The on-chain block hash to pin the off-chain environment | No |
241243

242244
#### Example
243245
```javascript
@@ -376,6 +378,7 @@ Roles:
376378
| Name | Type | Description | Required |
377379
| ---- | ---- | ----------- | -------- |
378380
| amount | integer | Amount of tokens to withdraw form the channel | Yes |
381+
| block_hash | string | The on-chain block hash to pin the off-chain environment | No |
379382

380383
#### Example
381384
```javascript
@@ -516,6 +519,7 @@ Roles:
516519
| vm\_version | integer | contract virtual machine version (vm for which code was compiled) | Yes |
517520
| abi\_version | integer | contract virtual machine abi version | Yes |
518521
| deposit | integer | contract creation deposit | Yes |
522+
| block_hash | string | The on-chain block hash to pin the off-chain environment | No |
519523

520524
#### Example
521525

@@ -544,6 +548,7 @@ Roles:
544548
| call\_data | call data | call data | Yes |
545549
| abi\_version | integer | call abi version | Yes |
546550
| amount | integer | amount of tokens to transfer to contract | Yes |
551+
| block_hash | string | The on-chain block hash to pin the off-chain environment | No |
547552

548553
#### Example
549554

@@ -637,6 +642,11 @@ Roles:
637642

638643
### Closer initiate mutual close
639644
* **method:** `channels.shutdown`
645+
* **params:**
646+
647+
| Name | Type | Description | Required |
648+
| ---- | ---- | ----------- | -------- |
649+
| block_hash | string | The on-chain block hash to pin the off-chain environment | No |
640650

641651
#### Example
642652
```javascript

node/api/channels_api_usage.md

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,58 @@ but are not necessarily part of the channel's life cycle.
7272

7373
Only steps 1 and 4 require chain interactions, step 2 and 3 are off-chain.
7474

75-
### HTTP requests
76-
There are two types of HTTP requests:
75+
### On-chain requests
76+
There are two types of requests:
7777
* Total amount-modifying ones - [deposit](#deposit-transaction) and [withdrawal](#withdraw-transaction)
7878
* [Channel-closing ones](#solo-closing-sequence) - [solo close](#solo-close-on-chain-transaction), [slash](#slash-on-chain-transaction) and [settle](#settle-on-chain-transaction)
7979

80+
### Pinned environment
81+
82+
While on-chain consensus is reached between miners, in off-chain world we
83+
don't have those. State channels are two-party systems that are closer to
84+
proof-of-stake solutions where both participants have equal
85+
stake in the channel, no matter their balances. The channel can make another
86+
step forward only if both parties agree upon the new state or it is produced
87+
via a force progress transaction on-chain that had been based upon a previous
88+
mutually agreed state. This makes channels both trustless and egalitarian.
89+
90+
This trustless model is based upon both participants executing off-chain
91+
updates locally and reaching the same results. This is how consensus is
92+
reached between them. Since off-chain smart contracts can read on-chain
93+
objects like accounts, names, contracts and oracles requests and responses,
94+
the results of their execution rely heavily on the chain environment they are
95+
based on.
96+
97+
Participants are expected to use their own nodes to support their channels.
98+
At the moment using a service hosted by a third party is trustful, thus
99+
potentially undesirable. This leads to both participant's nodes being peers in
100+
a system with an eventual consistency - due to network constraints and forks
101+
both participants can have a different view of the chain.
102+
103+
The combination of participants having different views on the chain and the
104+
off-chain consensus being dependent on it could lead to a fragile system with
105+
a lot of mismatching state hashes of off-chain updates. In order to improve
106+
this there is an optional functionality of setting `block_hash` that defines
107+
the on-chain environment that the update is to be executed in. We call this
108+
shared view of the chain _a pinnned environment_. When a participant wants to
109+
start a new round of updates, one can optionally specify a pinned environment
110+
to execute in. This is how the participant communicates to the other party
111+
what one considers to be a block hash that is safe enough to base an off-chain
112+
update upon. The other party might decide if the block hash is too old or too
113+
new depending on their local view of the chain. If the specified pinned
114+
environment does not meet the expectations, the whole update is rejected as
115+
invalid.
116+
117+
An update might not be pinned to any environment. In that case a placeholder
118+
value for the blockhash is provided:
119+
`"kh_11111111111111111111111111111111273Yts"` or
120+
`"mh_11111111111111111111111111111111273Yts"`. In this case both participants
121+
use whatever they see to be the latest top block.
122+
123+
The `block_hash` is an optional argument to all mutual offchain transactions. If it is
124+
not explicitly provided by the requester, a suitable value is picked for the
125+
client by their FSM.
126+
80127
## Channel open
81128
In order to use a channel, it must be opened. Both parties negotiate parameters for the channel - for example the amounts to participate. Some of those are relevant to the chain and end up in a`channel_create_tx` that is posted on the chain. Once a certain amount of blocks have been mined on top of the one that included it, the channel is considered to be opened.
82129

@@ -92,8 +139,9 @@ Detailed message transcripts from test suites can also be found [here](./example
92139
Each channel has a set of parameters that is required for opening a
93140
connection. Most of those are part of the `channel_create_tx` which is included
94141
in the chain, and the others are metadata used for the connection itself. We
95-
will describe them in two separate groups: one for the channel establishing
96-
and another for optional timeouts.
142+
will describe these in groups which indicate their relation to each other.
143+
144+
#### Channel establishing parameters
97145

98146
| Name | Type | Description | Required for open | Required/Used in reestablish | Part of the `channel_create_tx` |
99147
| ---- | ---- | ----------- | ----------------- | ---------------------------- | ------------------------------- |
@@ -129,6 +177,8 @@ and another for optional timeouts.
129177
participants can have different timeout settings and still doing updates, as
130178
long as no timer fires.
131179

180+
#### Channel timeout values
181+
132182
All timeout values are integers and represent the waiting time in
133183
milliseconds.
134184

@@ -160,6 +210,37 @@ and another for optional timeouts.
160210
We will be using the tool [wscat](https://github.com/websockets/wscat)
161211
We assume the channel's WebSocket listener is set on port 3014 (default one)
162212

213+
#### Channel block hash delta values
214+
215+
A client can specify what is considered by them to be a valid block hash.
216+
Those are defined as deltas according to the latest chain top as seen from
217+
the participant's node. A delta of `0` is the latest top, a delta of `1` is
218+
the previous generation, etc. Each participant can set a delta which defines
219+
a range of accepted heights according to the current top. If the other
220+
participant makes an off-chain update based on a hash which refers to a
221+
block belonging to a generation outside of this range - it will be rejected
222+
as it would be considered unsafe.
223+
224+
Additionally to the delta range check for incoming updates, the FSM also can
225+
pick a correct block hash for the client. This happens when the client
226+
starts a new update round and a block hash is not specified by the client.
227+
Then the FSM checks what is the newest allowed block hash according to the
228+
range. An additional pick offset can be provided for even greater fork
229+
safety.
230+
231+
| Name | Description | Default value |
232+
| ---- | ----------- | ------------- |
233+
| bh_delta_not_newer_than | height delta to be allowed as the newest possible relative to local top | 0 |
234+
| bh_delta_not_older_than | height delta to be allowed as the oldest possible relative to local top | 10 |
235+
| bh_delta_pick | the offset according to `bh_delta_not_newer_than` to use when picking a block hash for the client | 0 |
236+
237+
Restrictions on them are that:
238+
* `bh_delta_not_newer_than >= 0`
239+
* `bh_delta_not_newer_than + bh_delta_pick >= bh_delta_not_older_than`
240+
* if one is set, the other one must also be set
241+
242+
If any of the checks fails, the defaults are used instead.
243+
163244
### Responder WebSocket open
164245
Using the set of prenegotiated parameters the responder connects
165246
```

0 commit comments

Comments
 (0)