Skip to content

Commit 27de157

Browse files
committed
BOLT 2: define channel_type, make negotiation explicit.
This is extracted from channel_upgrade (#868), but used for opening negotiation as suggested by @Roasbeef on the last spec meeting. It's a trivial change, fully backwards compatible, but now each channel has a channel_type, which defines its behavior, rather than an ad-hoc set of "sticky" feature bits. It also means both peers can *support* a feature without endorsing it. Signed-off-by: Rusty Russell <[email protected]>
1 parent fdc078f commit 27de157

File tree

1 file changed

+45
-11
lines changed

1 file changed

+45
-11
lines changed

02-peer-protocol.md

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,9 @@ the funding transaction and both versions of the commitment transaction.
130130
1. type: 0 (`upfront_shutdown_script`)
131131
2. data:
132132
* [`...*byte`:`shutdown_scriptpubkey`]
133+
1. type: 1 (`channel_type`)
134+
2. data:
135+
* [`...*byte`:`type`]
133136

134137
The `chain_hash` value denotes the exact blockchain that the opened channel will
135138
reside within. This is usually the genesis hash of the respective blockchain.
@@ -197,6 +200,19 @@ know this node will accept `funding_satoshis` greater than or equal to 2^24.
197200
Since it's broadcast in the `node_announcement` message other nodes can use it to identify peers
198201
willing to accept large channel even before exchanging the `init` message with them.
199202

203+
#### Defined Channel Types
204+
205+
Channel types are an explicit enumeration: for convenience of future
206+
definitions they reuse even feature bits, but they are not an
207+
arbitrary combination (they represent the persistent features which
208+
affect the channel operation).
209+
210+
The currently defined types are:
211+
- no features (no bits set)
212+
- `option_static_remotekey` (bit 12)
213+
- `option_anchor_outputs` and `option_static_remotekey` (bits 20 and 12)
214+
- `option_anchors_zero_fee_htlc_tx` and `option_static_remotekey` (bits 22 and 12)
215+
200216
#### Requirements
201217

202218
The sending node:
@@ -217,6 +233,10 @@ The sending node:
217233
- MAY include `upfront_shutdown_script`.
218234
- if it includes `open_channel_tlvs`:
219235
- MUST include `upfront_shutdown_script`.
236+
- if it includes `channel_type`:
237+
- MUST set it to a defined type representing the type it wants.
238+
- MUST use the smallest bitmap possible to represent the channel type.
239+
- SHOULD NOT set it to a type containing a feature which was not negotiated.
220240

221241
The sending node SHOULD:
222242
- set `to_self_delay` sufficient to ensure the sender can irreversibly spend a commitment transaction output, in case of misbehavior by the receiver.
@@ -252,6 +272,7 @@ are not valid secp256k1 pubkeys in compressed format.
252272
- the funder's amount for the initial commitment transaction is not sufficient for full [fee payment](03-transactions.md#fee-payment).
253273
- both `to_local` and `to_remote` amounts for the initial commitment transaction are less than or equal to `channel_reserve_satoshis` (see [BOLT 3](03-transactions.md#commitment-transaction-outputs)).
254274
- `funding_satoshis` is greater than or equal to 2^24 and the receiver does not support `option_support_large_channel`.
275+
- It supports `channel_type`, `channel_type` was set, and the `type` is not suitable.
255276

256277
The receiving node MUST NOT:
257278
- consider funds received, using `push_msat`, to be received until the funding transaction has reached sufficient depth.
@@ -305,6 +326,9 @@ funding transaction and both versions of the commitment transaction.
305326
1. type: 0 (`upfront_shutdown_script`)
306327
2. data:
307328
* [`...*byte`:`shutdown_scriptpubkey`]
329+
1. type: 1 (`channel_type`)
330+
2. data:
331+
* [`...*byte`:`type`]
308332

309333
#### Requirements
310334

@@ -316,14 +340,20 @@ The sender:
316340
avoid double-spending of the funding transaction.
317341
- MUST set `channel_reserve_satoshis` greater than or equal to `dust_limit_satoshis` from the `open_channel` message.
318342
- MUST set `dust_limit_satoshis` less than or equal to `channel_reserve_satoshis` from the `open_channel` message.
343+
- if it sets `channel_type`:
344+
- MUST set it to the `channel_type` from `open_channel`
319345

320346
The receiver:
321347
- if `minimum_depth` is unreasonably large:
322348
- MAY reject the channel.
323349
- if `channel_reserve_satoshis` is less than `dust_limit_satoshis` within the `open_channel` message:
324-
- MUST reject the channel.
350+
- MUST reject the channel.
325351
- if `channel_reserve_satoshis` from the `open_channel` message is less than `dust_limit_satoshis`:
326-
- MUST reject the channel.
352+
- MUST reject the channel.
353+
- if `channel_type` is set, and `channel_type` was set in `open_channel`, and they are not equal types:
354+
- MUST reject the channel.
355+
356+
327357
Other fields have the same requirements as their counterparts in `open_channel`.
328358

329359
### The `funding_created` Message
@@ -382,14 +412,18 @@ This message introduces the `channel_id` to identify the channel. It's derived f
382412
#### Requirements
383413

384414
Both peers:
385-
- if `option_static_remotekey`, `option_anchor_outputs` or
386-
`option_anchors_zero_fee_htlc_tx` was negotiated:
387-
- `option_static_remotekey`, `option_anchor_outputs` or
388-
`option_anchors_zero_fee_htlc_tx` applies to all commitment transactions
415+
- if `channel_type` was present in both `open_channel` and `accept_channel`:
416+
- This is the `channel_type` (they must be equal, required above)
389417
- otherwise:
390-
- `option_static_remotekey`, `option_anchor_outputs` or
391-
`option_anchors_zero_fee_htlc_tx` does not apply to any commitment
392-
transactions
418+
- if `option_anchors_zero_fee_htlc_tx` was negotiated:
419+
- the `channel_type` is `option_anchors_zero_fee_htlc_tx` and `option_static_remotekey` (bits 22 and 12)
420+
- otherwise, if `option_anchor_outputs` was negotiated:
421+
- the `channel_type` is `option_anchor_outputs` and `option_static_remotekey` (bits 20 and 12)
422+
- otherwise, if `option_static_remotekey` was negotiated:
423+
- the `channel_type` is `option_static_remotekey` (bit 12)
424+
- otherwise:
425+
- the `channel_type` is empty
426+
- MUST use that `channel_type` for all commitment transactions.
393427

394428
The sender MUST set:
395429
- `channel_id` by exclusive-OR of the `funding_txid` and the `funding_output_index` from the `funding_created` message.
@@ -503,7 +537,7 @@ A sending node:
503537
- MUST NOT send a `shutdown`.
504538
- MUST NOT send an `update_add_htlc` after a `shutdown`.
505539
- if no HTLCs remain in either commitment transaction:
506-
- MUST NOT send any `update` message after a `shutdown`.
540+
- MUST NOT send any `update` message after a `shutdown`.
507541
- SHOULD fail to route any HTLC added after it has sent `shutdown`.
508542
- if it sent a non-zero-length `shutdown_scriptpubkey` in `open_channel` or `accept_channel`:
509543
- MUST send the same value in `scriptpubkey`.
@@ -516,7 +550,7 @@ A sending node:
516550
4. `OP_0` `32` 32-bytes (version 0 pay to witness script hash), OR
517551
5. if (and only if) `option_shutdown_anysegwit` is negotiated:
518552
* `OP_1` through `OP_16` inclusive, followed by a single push of 2 to 40 bytes
519-
(witness program versions 1 through 16)
553+
(witness program versions 1 through 16)
520554

521555
A receiving node:
522556
- if it hasn't received a `funding_signed` (if it is a funder) or a `funding_created` (if it is a fundee):

0 commit comments

Comments
 (0)