Skip to content

Commit bc86304

Browse files
authored
Merge pull request #910 from rustyrussell/zeroconf-as-alias
Explicitly allow funding_locked early, and support alias scids (feat 46/47/50/51)
2 parents c74a3bb + 34e9cd9 commit bc86304

File tree

4 files changed

+105
-34
lines changed

4 files changed

+105
-34
lines changed

02-peer-protocol.md

Lines changed: 86 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ operation, and closing.
1212
* [The `accept_channel` Message](#the-accept_channel-message)
1313
* [The `funding_created` Message](#the-funding_created-message)
1414
* [The `funding_signed` Message](#the-funding_signed-message)
15-
* [The `funding_locked` Message](#the-funding_locked-message)
15+
* [The `channel_ready` Message](#the-channel_ready-message)
1616
* [Channel Close](#channel-close)
1717
* [Closing Initiation: `shutdown`](#closing-initiation-shutdown)
1818
* [Closing Negotiation: `closing_signed`](#closing-negotiation-closing_signed)
@@ -70,8 +70,8 @@ must broadcast the funding transaction to the Bitcoin network. After
7070
the `funding_signed` message is sent/received, both sides should wait
7171
for the funding transaction to enter the blockchain and reach the
7272
specified depth (number of confirmations). After both sides have sent
73-
the `funding_locked` message, the channel is established and can begin
74-
normal operation. The `funding_locked` message includes information
73+
the `channel_ready` message, the channel is established and can begin
74+
normal operation. The `channel_ready` message includes information
7575
that will be used to construct channel authentication proofs.
7676

7777

@@ -82,8 +82,8 @@ that will be used to construct channel authentication proofs.
8282
| A |--(3)-- funding_created --->| B |
8383
| |<-(4)-- funding_signed -----| |
8484
| | | |
85-
| |--(5)--- funding_locked ---->| |
86-
| |<-(6)--- funding_locked -----| |
85+
| |--(5)--- channel_ready ---->| |
86+
| |<-(6)--- channel_ready -----| |
8787
+-------+ +-------+
8888

8989
- where node A is 'funder' and node B is 'fundee'
@@ -207,12 +207,16 @@ definitions they reuse even feature bits, but they are not an
207207
arbitrary combination (they represent the persistent features which
208208
affect the channel operation).
209209

210-
The currently defined types are:
210+
The currently defined basic types are:
211211
- no features (no bits set)
212212
- `option_static_remotekey` (bit 12)
213213
- `option_anchor_outputs` and `option_static_remotekey` (bits 20 and 12)
214214
- `option_anchors_zero_fee_htlc_tx` and `option_static_remotekey` (bits 22 and 12)
215215

216+
Each basic type has the following variations allowed:
217+
- `option_scid_alias` (bit 46)
218+
- `option_zeroconf` (bit 50)
219+
216220
#### Requirements
217221

218222
The sending node:
@@ -239,6 +243,8 @@ The sending node:
239243
- MUST set it to a defined type representing the type it wants.
240244
- MUST use the smallest bitmap possible to represent the channel type.
241245
- SHOULD NOT set it to a type containing a feature which was not negotiated.
246+
- if `announce_channel` is `true` (not `0`):
247+
- MUST NOT send `channel_type` with the `option_scid_alias` bit set.
242248

243249
The sending node SHOULD:
244250
- set `to_self_delay` sufficient to ensure the sender can irreversibly spend a commitment transaction output, in case of misbehavior by the receiver.
@@ -276,7 +282,9 @@ are not valid secp256k1 pubkeys in compressed format.
276282
- the funder's amount for the initial commitment transaction is not sufficient for full [fee payment](03-transactions.md#fee-payment).
277283
- 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)).
278284
- `funding_satoshis` is greater than or equal to 2^24 and the receiver does not support `option_support_large_channel`.
279-
- It supports `channel_type`, `channel_type` was set, and the `type` is not suitable.
285+
- It supports `channel_type` and `channel_type` was set:
286+
- if `type` is not suitable.
287+
- if `type` includes `option_zeroconf` and it does not trust the sender to open an unconfirmed channel.
280288

281289
The receiving node MUST NOT:
282290
- consider funds received, using `push_msat`, to be received until the funding transaction has reached sufficient depth.
@@ -344,8 +352,10 @@ The `temporary_channel_id` MUST be the same as the `temporary_channel_id` in
344352
the `open_channel` message.
345353

346354
The sender:
347-
- SHOULD set `minimum_depth` to a number of blocks it considers reasonable to
348-
avoid double-spending of the funding transaction.
355+
- if `channel_type` includes `option_zeroconf`:
356+
- MUST set `minimum_depth` to zero.
357+
- otherwise:
358+
- SHOULD set `minimum_depth` to a number of blocks it considers reasonable to avoid double-spending of the funding transaction.
349359
- MUST set `channel_reserve_satoshis` greater than or equal to `dust_limit_satoshis` from the `open_channel` message.
350360
- MUST set `dust_limit_satoshis` less than or equal to `channel_reserve_satoshis` from the `open_channel` message.
351361
- if `option_channel_type` was negotiated:
@@ -463,31 +473,67 @@ use `option_static_remotekey`, `option_anchor_outputs` or
463473
`option_static_remotekey`, and the superior one is favored if more than one
464474
is negotiated.
465475

466-
### The `funding_locked` Message
476+
### The `channel_ready` Message
477+
478+
This message (which used to be called `funding_locked`) indicates that the funding transaction has sufficient confirms for channel use. Once both nodes have sent this, the channel enters normal operating mode.
467479

468-
This message indicates that the funding transaction has reached the `minimum_depth` asked for in `accept_channel`. Once both nodes have sent this, the channel enters normal operating mode.
480+
Note that the opener is free to send this message at any time (since it presumably trusts itself), but the
481+
accepter would usually wait until the funding has reached the `minimum_depth` asked for in `accept_channel`.
469482

470-
1. type: 36 (`funding_locked`)
483+
1. type: 36 (`channel_ready`)
471484
2. data:
472485
* [`channel_id`:`channel_id`]
473-
* [`point`:`next_per_commitment_point`]
486+
* [`point`:`second_per_commitment_point`]
487+
* [`channel_ready_tlvs`:`tlvs`]
488+
489+
1. `tlv_stream`: `channel_ready_tlvs`
490+
2. types:
491+
1. type: 1 (`short_channel_id`)
492+
2. data:
493+
* [`short_channel_id`:`alias`]
474494

475495
#### Requirements
476496

477-
The sender MUST:
478-
- NOT send `funding_locked` unless outpoint of given by `funding_txid` and
497+
The sender:
498+
- MUST NOT send `channel_ready` unless outpoint of given by `funding_txid` and
479499
`funding_output_index` in the `funding_created` message pays exactly `funding_satoshis` to the scriptpubkey specified in [BOLT #3](03-transactions.md#funding-transaction-output).
480-
- wait until the funding transaction has reached `minimum_depth` before
481-
sending this message.
482-
- set `next_per_commitment_point` to the per-commitment point to be used
483-
for the following commitment transaction, derived as specified in
500+
- if it is not the node opening the channel:
501+
- SHOULD wait until the funding transaction has reached `minimum_depth` before
502+
sending this message.
503+
- MUST set `second_per_commitment_point` to the per-commitment point to be used
504+
for commitment transaction #1, derived as specified in
484505
[BOLT #3](03-transactions.md#per-commitment-secret-requirements).
506+
- if `option_scid_alias` was negotiated:
507+
- MUST set `short_channel_id` `alias`.
508+
- otherwise:
509+
- MAY set `short_channel_id` `alias`.
510+
- if it sets `alias`:
511+
- if the `announce_channel` bit was set in `open_channel`:
512+
- SHOULD initially set `alias` to value not related to the real `short_channel_id`.
513+
- otherwise:
514+
- MUST set `alias` to a value not related to the real `short_channel_id`.
515+
- MUST NOT send the same `alias` for multiple peers or use an alias which
516+
collides with a `short_channel_id` of a channel on the same node.
517+
- MUST always recognize the `alias` as a `short_channel_id` for incoming HTLCs to this channel.
518+
- if `channel_type` has `option_scid_alias` set:
519+
- MUST NOT allow incoming HTLCs to this channel using the real `short_channel_id`
520+
- MAY send multiple `channel_ready` messages to the same peer with different `alias` values.
521+
- otherwise:
522+
- MUST wait until the funding transaction has reached `minimum_depth` before sending this message.
523+
524+
525+
The sender:
485526

486527
A non-funding node (fundee):
487528
- SHOULD forget the channel if it does not see the correct funding
488-
transaction after a timeout of 2016 blocks.
529+
transaction after a timeout of 2016 blocks.
489530

490-
From the point of waiting for `funding_locked` onward, either node MAY
531+
The receiver:
532+
- MAY use any of the `alias` it received, in BOLT 11 `r` fields.
533+
- if `channel_type` has `option_scid_alias` set:
534+
- MUST NOT use the real `short_channel_id` in BOLT 11 `r` fields.
535+
536+
From the point of waiting for `channel_ready` onward, either node MAY
491537
send an `error` and fail the channel if it does not receive a required response from the
492538
other node after a reasonable timeout.
493539

@@ -503,6 +549,16 @@ to broadcast the commitment transaction to get his funds back and open a new
503549
channel. To avoid this, the funder should ensure the funding transaction
504550
confirms in the next 2016 blocks.
505551

552+
The `alias` here is both required for routing (since there real
553+
short_channel_id is unknown until confirmation), and useful to provide
554+
one or more aliases, even once there is a real `short_channel_id` for
555+
a public channel.
556+
557+
While a node can send multiple `alias`, it must remember all of the
558+
ones it has sent so it can use them should they be requested by
559+
incoming HTLCs. The recipient only need remember one, for use in
560+
`r` route hints in BOLT 11 invoices.
561+
506562
## Channel Close
507563

508564
Nodes can negotiate a mutual close of the connection, which unlike a
@@ -543,7 +599,7 @@ along with the `scriptpubkey` it wants to be paid to.
543599
A sending node:
544600
- if it hasn't sent a `funding_created` (if it is a funder) or a `funding_signed` (if it is a fundee):
545601
- MUST NOT send a `shutdown`
546-
- MAY send a `shutdown` before a `funding_locked`, i.e. before the funding transaction has reached `minimum_depth`.
602+
- MAY send a `shutdown` before a `channel_ready`, i.e. before the funding transaction has reached `minimum_depth`.
547603
- if there are updates pending on the receiving node's commitment transaction:
548604
- MUST NOT send a `shutdown`.
549605
- MUST NOT send multiple `shutdown` messages.
@@ -566,7 +622,7 @@ A receiving node:
566622
- SHOULD send an `error` and fail the channel.
567623
- if the `scriptpubkey` is not in one of the above forms:
568624
- SHOULD send a `warning`.
569-
- if it hasn't sent a `funding_locked` yet:
625+
- if it hasn't sent a `channel_ready` yet:
570626
- MAY reply to a `shutdown` message with a `shutdown`
571627
- once there are no outstanding updates on the peer, UNLESS it has already sent a `shutdown`:
572628
- MUST reply to a `shutdown` message with a `shutdown`
@@ -716,7 +772,7 @@ the closing transaction will likely never reach miners.
716772

717773
## Normal Operation
718774

719-
Once both nodes have exchanged `funding_locked` (and optionally [`announcement_signatures`](07-routing-gossip.md#the-announcement_signatures-message)), the channel can be used to make payments via Hashed Time Locked Contracts.
775+
Once both nodes have exchanged `channel_ready` (and optionally [`announcement_signatures`](07-routing-gossip.md#the-announcement_signatures-message)), the channel can be used to make payments via Hashed Time Locked Contracts.
720776

721777
Changes are sent in batches: one or more `update_` messages are sent before a
722778
`commitment_signed` message, as in the following diagram:
@@ -1370,11 +1426,12 @@ The sending node:
13701426
A node:
13711427
- if `next_commitment_number` is 1 in both the `channel_reestablish` it
13721428
sent and received:
1373-
- MUST retransmit `funding_locked`.
1429+
- MUST retransmit `channel_ready`.
13741430
- otherwise:
1375-
- MUST NOT retransmit `funding_locked`.
1431+
- MUST NOT retransmit `channel_ready`, but MAY send `channel_ready` with
1432+
a different `short_channel_id` `alias` field.
13761433
- upon reconnection:
1377-
- MUST ignore any redundant `funding_locked` it receives.
1434+
- MUST ignore any redundant `channel_ready` it receives.
13781435
- if `next_commitment_number` is equal to the commitment number of
13791436
the last `commitment_signed` message the receiving node has sent:
13801437
- MUST reuse the same commitment number for its next `commitment_signed`.
@@ -1442,7 +1499,7 @@ atomic: if it doesn't complete, it starts again. The only exception
14421499
is if the `funding_signed` message is sent but not received. In
14431500
this case, the funder will forget the channel, and presumably open
14441501
a new one upon reconnection; meanwhile, the other node will eventually forget
1445-
the original channel, due to never receiving `funding_locked` or seeing
1502+
the original channel, due to never receiving `channel_ready` or seeing
14461503
the funding transaction on-chain.
14471504

14481505
There's no acknowledgment for `error`, so if a reconnect occurs it's
@@ -1478,7 +1535,7 @@ commitment number 0 is created during opening.
14781535
`commitment_signed` for commitment number 1 is send and then
14791536
the revocation for commitment number 0 is received.
14801537

1481-
`funding_locked` is implicitly acknowledged by the start of normal
1538+
`channel_ready` is implicitly acknowledged by the start of normal
14821539
operation, which is known to have begun after a `commitment_signed` has been
14831540
received — hence, the test for a `next_commitment_number` greater
14841541
than 1.

04-onion-routing.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,15 @@ An _intermediate hop_ MUST NOT, but the _final node_:
11181118
- if the `amt_to_forward` does NOT correspond with the `incoming_htlc_amt` from the
11191119
final node's HTLC:
11201120
- MUST return a `final_incorrect_htlc_amount` error.
1121+
- if it returns a `channel_update`:
1122+
- MUST set `short_channel_id` to the `short_channel_id` used by the incoming onion.
1123+
1124+
### Rationale
1125+
1126+
In the case of multiple short_channel_id aliases, the `channel_update`
1127+
`short_channel_id` should refer to the one the original sender is
1128+
expecting, to both avoid confusion and to avoid leaking information
1129+
about other aliases (or the real location of the channel UTXO).
11211130

11221131
## Receiving Failure Codes
11231132

07-routing-gossip.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ The `announcement_signatures` message is created by constructing a `channel_anno
8585
A node:
8686
- if the `open_channel` message has the `announce_channel` bit set AND a `shutdown` message has not been sent:
8787
- MUST send the `announcement_signatures` message.
88-
- MUST NOT send `announcement_signatures` messages until `funding_locked`
88+
- MUST NOT send `announcement_signatures` messages until `channel_ready`
8989
has been sent and received AND the funding transaction has at least six confirmations.
9090
- otherwise:
9191
- MUST NOT send the `announcement_signatures` message.
@@ -104,8 +104,8 @@ A recipient node:
104104
`error` and fail the channel.
105105
- if it has sent AND received a valid `announcement_signatures` message:
106106
- SHOULD queue the `channel_announcement` message for its peers.
107-
- if it has not sent funding_locked:
108-
- MAY defer handling the announcement_signatures until after it has sent funding_locked
107+
- if it has not sent `channel_ready`:
108+
- MAY defer handling the announcement_signatures until after it has sent `channel_ready`
109109
- otherwise:
110110
- MUST ignore it.
111111

@@ -167,7 +167,7 @@ The origin node:
167167
- for the _Bitcoin blockchain_:
168168
- MUST set `chain_hash` value (encoded in hex) equal to `6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000`.
169169
- MUST set `short_channel_id` to refer to the confirmed funding transaction,
170-
as specified in [BOLT #2](02-peer-protocol.md#the-funding_locked-message).
170+
as specified in [BOLT #2](02-peer-protocol.md#the-channel_ready-message).
171171
- Note: the corresponding output MUST be a P2WSH, as described in [BOLT #3](03-transactions.md#funding-transaction-output).
172172
- MUST set `node_id_1` and `node_id_2` to the public keys of the two nodes
173173
operating the channel, such that `node_id_1` is the lexicographically-lesser of the
@@ -445,10 +445,12 @@ or `node_id_2` otherwise.
445445
### Requirements
446446

447447
The origin node:
448-
- MUST NOT send a created `channel_update` before `funding_locked` has been received.
448+
- MUST NOT send a created `channel_update` before `channel_ready` has been received.
449449
- MAY create a `channel_update` to communicate the channel parameters to the
450450
channel peer, even though the channel has not yet been announced (i.e. the
451451
`announce_channel` bit was not set).
452+
- MUST set the `short_channel_id` to either an `alias` it has
453+
received from the peer, or the real channel `short_channel_id`.
452454
- MUST NOT forward such a `channel_update` to other peers, for privacy
453455
reasons.
454456
- Note: such a `channel_update`, one not preceded by a

09-features.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ The Context column decodes as follows:
4242
| 22/23 | `option_anchors_zero_fee_htlc_tx` | Anchor commitment type with zero fee HTLC transactions | IN | `option_static_remotekey` | [BOLT #3][bolt03-htlc-tx], [lightning-dev][ml-sighash-single-harmful]|
4343
| 26/27 | `option_shutdown_anysegwit` | Future segwit versions allowed in `shutdown` | IN | | [BOLT #2][bolt02-shutdown] |
4444
| 44/45 | `option_channel_type` | Node supports the `channel_type` field in open/accept | IN | | [BOLT #2](02-peer-protocol.md#the-open_channel-message) |
45+
| 46/47 | `option_scid_alias` | Supply channel aliases for routing | IN | | [BOLT #2][bolt02-channel-ready] |
4546
| 48/49 | `option_payment_metadata` | Payment metadata in tlv record | 9 | | [BOLT #11](11-payment-encoding.md#tagged-fields)
47+
| 50/51 | `option_zeroconf` | Understands zeroconf channel types | IN | `option_scid_alias` | [BOLT #2][bolt02-channel-ready] |
4648

4749
## Definitions
4850

@@ -90,6 +92,7 @@ This work is licensed under a [Creative Commons Attribution 4.0 International Li
9092
[bolt02-open]: 02-peer-protocol.md#the-open_channel-message
9193
[bolt03-htlc-tx]: 03-transactions.md#htlc-timeout-and-htlc-success-transactions
9294
[bolt02-shutdown]: 02-peer-protocol.md#closing-initiation-shutdown
95+
[bolt02-channel-ready]: 02-peer-protocol.md#the-channel_ready-message
9396
[bolt04]: 04-onion-routing.md
9497
[bolt07-sync]: 07-routing-gossip.md#initial-sync
9598
[bolt07-query]: 07-routing-gossip.md#query-messages

0 commit comments

Comments
 (0)