Skip to content

Commit c573e04

Browse files
committed
BOLT 7: variable message onion message support.
These use onion encoding for simple one-way messaging: there are no error returns. Any reply is done with an enclosed blinded path. Note that this defines the message system, not the contents of messages (e.g. invoice requests from offers). Signed-off-by: Rusty Russell <[email protected]>
1 parent a9db80e commit c573e04

File tree

4 files changed

+137
-3
lines changed

4 files changed

+137
-3
lines changed

01-messaging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ The messages are grouped logically into five groups, ordered by the most signifi
4949
- Setup & Control (types `0`-`31`): messages related to connection setup, control, supported features, and error reporting (described below)
5050
- Channel (types `32`-`127`): messages used to setup and tear down micropayment channels (described in [BOLT #2](02-peer-protocol.md))
5151
- Commitment (types `128`-`255`): messages related to updating the current commitment transaction, which includes adding, revoking, and settling HTLCs as well as updating fees and exchanging signatures (described in [BOLT #2](02-peer-protocol.md))
52-
- Routing (types `256`-`511`): messages containing node and channel announcements, as well as any active route exploration (described in [BOLT #7](07-routing-gossip.md))
52+
- Routing (types `256`-`511`): messages containing node and channel announcements, as well as any active route exploration or messaging (described in [BOLT #7](07-routing-gossip.md))
5353
- Custom (types `32768`-`65535`): experimental and application-specific messages
5454

5555
The size of the message is required by the transport layer to fit into a 2-byte unsigned int; therefore, the maximum possible size is 65535 bytes.

04-onion-routing.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ A node:
5151
* [Legacy HopData Payload Format](#legacy-hop_data-payload-format)
5252
* [TLV Payload Format](#tlv_payload-format)
5353
* [Basic Multi-Part Payments](#basic-multi-part-payments)
54+
* [Onion Messages](#onion-messages)
5455
* [Accepting and Forwarding a Payment](#accepting-and-forwarding-a-payment)
5556
* [Payload for the Last Node](#payload-for-the-last-node)
5657
* [Non-strict Forwarding](#non-strict-forwarding)
@@ -367,6 +368,86 @@ otherwise meets the amount criterion (eg. some other failure, or
367368
invoice timeout), however if it were to fulfill only some of them,
368369
intermediary nodes could simply claim the remaining ones.
369370

371+
### Onion Messages
372+
373+
Onion messages have an onion with an alternate `hop_payload`
374+
format: a `bigsize` followed by a `onionmsg_payload`. Note that there
375+
is no legacy format, thus a `bigsize` of 0 means no payload.
376+
377+
1. tlvs: `onionmsg_payload`
378+
2. types:
379+
1. type: 4 (`next_node_id`)
380+
2. data:
381+
* [`point`:`node_id`]
382+
1. type: 6 (`next_short_channel_id`)
383+
2. data:
384+
* [`short_channel_id`:`short_channel_id`]
385+
1. type: 8 (`reply_path`)
386+
2. data:
387+
* [`point`:`blinding`]
388+
* [`...*onionmsg_path`:`path`]
389+
1. type: 10 (`enctlv`)
390+
2. data:
391+
* [`...*byte`:`enctlv`]
392+
1. type: 12 (`blinding`)
393+
2. data:
394+
* [`point`:`blinding`]
395+
396+
1. tlvs: `encmsg_tlvs`
397+
2. types:
398+
1. type: 4 (`next_node_id`)
399+
2. data:
400+
* [`point`:`node_id`]
401+
1. type: 6 (`next_short_channel_id`)
402+
2. data:
403+
* [`short_channel_id`:`short_channel_id`]
404+
405+
1. subtype: `onionmsg_path`
406+
2. data:
407+
* [`point`:`node_id`]
408+
* [`u16`:`enclen`]
409+
* [`enclen*byte`:`enctlv`]
410+
411+
#### Requirements
412+
413+
The writer:
414+
- For the non-final nodes' `onionmsg_payload`:
415+
- MUST include exactly one of `next_short_channel_id`, `next_node_id`
416+
or `enctlv` indicating the next node.
417+
- For the final node's `onionmsg_payload`:
418+
- if the final node is permitted to reply:
419+
- MUST set `reply_path` `blinding` to the initial blinding factor for the `next_node_id`
420+
- For the first `reply_path` `path`:
421+
- MUST set `node_id` to the first node in the reply path.
422+
- For the remaining `reply_path` `path`:
423+
- MUST set `node_id` to the blinded node id to encrypt the onion hop for.
424+
- Within `reply_path` `path`:
425+
- MUST encrypt `enctlv` as detailed in (FIXME: reference to t-bast's blinded path section:
426+
`ChaChaPoly-1305` encryption using an all-zero nonce).
427+
- MUST set `enctlv` to a valid `encmsg_tlvs` containing exactly one of either
428+
`next_node_id` or `next_short_channel_id`.
429+
- otherwise:
430+
- MUST NOT set `reply_path`.
431+
432+
The reader:
433+
- if `enctlv` is present:
434+
- MUST extract the shared secret from the given `blinding` parameter and decrypt `enctlv`.
435+
- MUST drop the message if `enctlv` is not a valid TLV.
436+
- MUST use `next_short_channel_id` or `next_node_id` from `enctlv`.
437+
- Otherwise:
438+
- MUST use `next_short_channel_id` or `next_node_id` from `onionmsg_payload`.
439+
440+
- if it is not the final node according to the onion encryption:
441+
- if `next_short_channel_id` or `next_node_id` is found:
442+
- SHOULD forward the message using `onion_message` to the indicated peer if possible.
443+
444+
- otherwise:
445+
- if it wants to send a reply:
446+
- MUST create an onion encoding using `reply_path`.
447+
- MUST send the reply via `onion_message` to the node indicated by
448+
the first element of `reply_path` `path` using `reply_path` `blinding`.
449+
450+
370451
# Accepting and Forwarding a Payment
371452

372453
Once a node has decoded the payload it either accepts the payment locally, or forwards it to the peer indicated as the next hop in the payload.

07-routing-gossip.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# BOLT #7: P2P Node and Channel Discovery
1+
# BOLT #7: P2P Node and Channel Discovery and Onion Messages
22

33
This specification describes simple node discovery, channel discovery, and channel update mechanisms that do not rely on a third-party to disseminate the information.
44

@@ -33,6 +33,7 @@ To support channel and node discovery, three *gossip messages* are supported:
3333
* [HTLC Fees](#htlc-fees)
3434
* [Pruning the Network View](#pruning-the-network-view)
3535
* [Recommendations for Routing](#recommendations-for-routing)
36+
* [Onion Messages](#onion-messages)
3637
* [References](#references)
3738

3839
## Definition of `short_channel_id`
@@ -1119,7 +1120,58 @@ A->D's `update_add_htlc` message would be:
11191120
And D->C's `update_add_htlc` would again be the same as B->C's direct payment
11201121
above.
11211122

1122-
## References
1123+
# Onion Messages
1124+
1125+
Onion messages allow peers to use existing connections to query for
1126+
invoices (see [BOLT 12](12-offer-encoding.md)). Like gossip messages,
1127+
they are not associated with a particular local channel. Like HTLCs,
1128+
they use [BOLT 4](04-onion-routing.md#onion-messages) protocol for
1129+
end-to-end encryption.
1130+
1131+
Onion messages are unreliable: in particular, they are designed to
1132+
be cheap to process and require no storage to forward. As a result,
1133+
there is no error returned from intermediary nodes.
1134+
1135+
To enable messaging via blinded paths, there is an optional `blinding`
1136+
parameter which allows decryption of the `enctlv` field inside the
1137+
`onionmsg`'s `onionmsg_payload`.
1138+
1139+
## The `onion_message` Message
1140+
1141+
1. type: 385 (`onion_message`) (`option_onion_messages`)
1142+
2. data:
1143+
* [`u16`:`len`]
1144+
* [`len*byte`:`onionmsg`]
1145+
* [`onion_message_tlvs`:`onion_message_tlvs`]
1146+
1147+
1. tlvs: `onion_message_tlvs`
1148+
2. types:
1149+
1. type: 2 (`blinding`)
1150+
2. data:
1151+
* [`point`:`blinding`]
1152+
1153+
## Requirements
1154+
1155+
The writer:
1156+
- MUST populate the per-hop payloads as described in [BOLT 4](04-onion-routing.md#onion-messages).
1157+
- SHOULD retry via a different route if it expects a response and
1158+
doesn't receive one after a reasonable period.
1159+
- SHOULD set `len` to 1366 or 32834.
1160+
1161+
The reader:
1162+
- MUST handle the per-hop payloads as described in [BOLT 4](04-onion-routing.md#onion-messages).
1163+
- SHOULD accept onion messages from peers without an established channel.
1164+
- MAY rate-limit messages by dropping them.
1165+
1166+
## Rationale
1167+
1168+
`len` allows larger messages to be sent than the standard 1300 bytes
1169+
allowed for an HTLC onion, but this should be used sparingly as it is
1170+
reduces anonymity set, hence the recommendation that it either look
1171+
like an HTLC onion, or if larger, be a fixed size.
1172+
1173+
1174+
# References
11231175

11241176
1. <a id="reference-1">[RFC 1950 "ZLIB Compressed Data Format Specification version 3.3](https://www.ietf.org/rfc/rfc1950.txt)</a>
11251177
2. <a id="reference-2">[Maximum Compression Factor](https://zlib.net/zlib_tech.html)</a>

09-features.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ The Context column decodes as follows:
4040
| 18/19 | `option_support_large_channel` | Can create large channels | IN | | [BOLT #2](02-peer-protocol.md#the-open_channel-message) |
4141
| 20/21 | `option_anchor_outputs` | Anchor outputs | IN | `option_static_remotekey` | [BOLT #3](03-transactions.md) |
4242
| 22/23 | `option_anchors_zero_fee_htlc_tx` | Anchor commitment type with zero fee HTLC transactions | IN | | [BOLT #3][bolt03-htlc-tx], [lightning-dev][ml-sighash-single-harmful]|
43+
| 102/103 | `option_onion_messages` | Can forward onion messages | IN9 | | [BOLT #7](07-routing-gossip.md#onion-messages) |
4344

4445
## Requirements
4546

0 commit comments

Comments
 (0)