Skip to content

Commit 5071b93

Browse files
committed
Advertize known compression algorithms
Add a tlv field in `init` to list supported compression algorithms. This compression will be used in several places, currently in extended gossip queries. Fixes #811
1 parent a00418f commit 5071b93

File tree

3 files changed

+52
-25
lines changed

3 files changed

+52
-25
lines changed

01-messaging.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,20 @@ The `features` field MUST be padded to bytes with 0s.
258258
1. type: 1 (`networks`)
259259
2. data:
260260
* [`...*chain_hash`:`chains`]
261-
261+
1. type: 3 (`compression_algorithms`)
262+
2. data:
263+
* [`...*byte`:`supported_algorithms`]
262264

263265
The optional `networks` indicates the chains the node is interested in.
264266

267+
The optional `compression_algorithms` is a bitfield indicating what compression
268+
algorithms the node supports for [gossip queries](07-routing-gossip.md#query-messages).
269+
270+
| Bit Position | Algorithm |
271+
| ------------- | ---------------------------------------------------- |
272+
| 0 | Uncompressed |
273+
| 1 | [zlib_deflate](https://www.ietf.org/rfc/rfc1950.txt) |
274+
265275
#### Requirements
266276

267277
The sending node:
@@ -271,6 +281,8 @@ The sending node:
271281
- SHOULD NOT set features greater than 13 in `globalfeatures`.
272282
- SHOULD use the minimum length required to represent the `features` field.
273283
- SHOULD set `networks` to all chains it will gossip or open channels for.
284+
- if it sets the `option_compression` feature bit:
285+
- MUST set the `compression_algorithms` field
274286

275287
The receiving node:
276288
- MUST wait to receive `init` before sending any other messages.
@@ -284,6 +296,9 @@ The receiving node:
284296
- MAY fail the connection.
285297
- if the feature vector does not set all known, transitive dependencies:
286298
- MUST fail the connection.
299+
- if it has no `compression_algorithms` in common with the sending node:
300+
- MUST NOT exchange messages that require compression (e.g. gossip queries).
301+
- MAY fail the connection.
287302

288303
#### Rationale
289304

@@ -453,6 +468,7 @@ multi-byte values with big-endian.
453468
Values encoded with BigSize will produce an encoding of either 1, 3, 5, or 9
454469
bytes depending on the size of the integer. The encoding is a piece-wise
455470
function that takes a `uint64` value `x` and produces:
471+
456472
```
457473
uint8(x) if x < 0xfd
458474
0xfd + be16(uint16(x)) if x < 0x10000
@@ -471,6 +487,7 @@ decoded with BigSize should be checked to ensure they are minimally encoded.
471487
### BigSize Decoding Tests
472488

473489
The following is an example of how to execute the BigSize decoding tests.
490+
474491
```golang
475492
func testReadBigSize(t *testing.T, test bigSizeTest) {
476493
var buf [8]byte
@@ -493,6 +510,7 @@ func testReadBigSize(t *testing.T, test bigSizeTest) {
493510
```
494511

495512
A correct implementation should pass against these test vectors:
513+
496514
```json
497515
[
498516
{
@@ -601,6 +619,7 @@ A correct implementation should pass against these test vectors:
601619
### BigSize Encoding Tests
602620

603621
The following is an example of how to execute the BigSize encoding tests.
622+
604623
```golang
605624
func testWriteBigSize(t *testing.T, test bigSizeTest) {
606625
var (
@@ -621,6 +640,7 @@ func testWriteBigSize(t *testing.T, test bigSizeTest) {
621640
```
622641

623642
A correct implementation should pass against the following test vectors:
643+
624644
```json
625645
[
626646
{

07-routing-gossip.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,12 @@ request what gossip should be received.
568568
There are several messages which contain a long array of
569569
`short_channel_id`s (called `encoded_short_ids`) so we utilize a
570570
simple compression scheme: the first byte indicates the encoding, the
571-
rest contains the data.
571+
rest contains the data. The compression algorithms supported by each
572+
node are advertised in the `init` message's `compression_algorithms`
573+
tlv field.
572574

573575
Encoding types:
576+
574577
* `0`: uncompressed array of `short_channel_id` types, in ascending order.
575578
* `1`: array of `short_channel_id` types, in ascending order, compressed with zlib deflate<sup>[1](#reference-1)</sup>
576579

@@ -636,6 +639,7 @@ The sender:
636639
- MUST set `chain_hash` to the 32-byte hash that uniquely identifies the chain
637640
that the `short_channel_id`s refer to.
638641
- MUST set the first byte of `encoded_short_ids` to the encoding type.
642+
- MUST NOT use an encoding not supported by the remote peer.
639643
- MUST encode a whole number of `short_channel_id`s to `encoded_short_ids`
640644
- MAY send this if it receives a `channel_update` for a
641645
`short_channel_id` for which it has no `channel_announcement`.

09-features.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,43 @@ for use of the channel, so the presentation of those features depends
1919
on the feature itself.
2020

2121
The Context column decodes as follows:
22+
2223
* `I`: presented in the `init` message.
2324
* `N`: presented in the `node_announcement` messages
2425
* `C`: presented in the `channel_announcement` message.
2526
* `C-`: presented in the `channel_announcement` message, but always odd (optional).
2627
* `C+`: presented in the `channel_announcement` message, but always even (required).
2728
* `9`: presented in [BOLT 11](11-payment-encoding.md) invoices.
2829

29-
| Bits | Name | Description | Context | Dependencies | Link |
30-
|-------|----------------------------------|-----------------------------------------------------------|----------|-------------------|---------------------------------------|
31-
| 0/1 | `option_data_loss_protect` | Requires or supports extra `channel_reestablish` fields | IN | | [BOLT #2][bolt02-retransmit] |
32-
| 3 | `initial_routing_sync` | Sending node needs a complete routing information dump | I | | [BOLT #7][bolt07-sync] |
33-
| 4/5 | `option_upfront_shutdown_script` | Commits to a shutdown scriptpubkey when opening channel | IN | | [BOLT #2][bolt02-open] |
34-
| 6/7 | `gossip_queries` | More sophisticated gossip control | IN | | [BOLT #7][bolt07-query] |
35-
| 8/9 | `var_onion_optin` | Requires/supports variable-length routing onion payloads | IN9 | | [Routing Onion Specification][bolt04] |
36-
| 10/11 | `gossip_queries_ex` | Gossip queries can include additional information | IN | `gossip_queries` | [BOLT #7][bolt07-query] |
37-
| 12/13 | `option_static_remotekey` | Static key for remote output | IN | | [BOLT #3](03-transactions.md) |
38-
| 14/15 | `payment_secret` | Node supports `payment_secret` field | IN9 | `var_onion_optin` | [Routing Onion Specification][bolt04] |
39-
| 16/17 | `basic_mpp` | Node can receive basic multi-part payments | IN9 | `payment_secret` | [BOLT #4][bolt04-mpp] |
40-
| 18/19 | `option_support_large_channel` | Can create large channels | IN | | [BOLT #2](02-peer-protocol.md#the-open_channel-message) |
41-
| 20/21 | `option_anchor_outputs` | Anchor outputs | IN | `option_static_remotekey` | [BOLT #3](03-transactions.md) |
42-
| 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]|
30+
| Bits | Name | Description | Context | Dependencies | Link |
31+
|-------|-----------------------------------|----------------------------------------------------------|----------|---------------------------|----------------------------------------------------------------------|
32+
| 0/1 | `option_data_loss_protect` | Requires or supports extra `channel_reestablish` fields | IN | | [BOLT #2][bolt02-retransmit] |
33+
| 3 | `initial_routing_sync` | Sending node needs a complete routing information dump | I | | [BOLT #7][bolt07-sync] |
34+
| 4/5 | `option_upfront_shutdown_script` | Commits to a shutdown scriptpubkey when opening channel | IN | | [BOLT #2][bolt02-open] |
35+
| 6/7 | `gossip_queries` | More sophisticated gossip control | IN | | [BOLT #7][bolt07-query] |
36+
| 8/9 | `var_onion_optin` | Requires/supports variable-length routing onion payloads | IN9 | | [Routing Onion Specification][bolt04] |
37+
| 10/11 | `gossip_queries_ex` | Gossip queries can include additional information | IN | `gossip_queries` | [BOLT #7][bolt07-query] |
38+
| 12/13 | `option_static_remotekey` | Static key for remote output | IN | | [BOLT #3](03-transactions.md) |
39+
| 14/15 | `payment_secret` | Node supports `payment_secret` field | IN9 | `var_onion_optin` | [Routing Onion Specification][bolt04] |
40+
| 16/17 | `basic_mpp` | Node can receive basic multi-part payments | IN9 | `payment_secret` | [BOLT #4][bolt04-mpp] |
41+
| 18/19 | `option_support_large_channel` | Can create large channels | IN | | [BOLT #2](02-peer-protocol.md#the-open_channel-message) |
42+
| 20/21 | `option_anchor_outputs` | Anchor outputs | IN | `option_static_remotekey` | [BOLT #3](03-transactions.md) |
43+
| 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]|
44+
| 24/25 | `option_compression` | Compression algorithms advertised in `init` | IN | | [BOLT #1](01-messaging.md#the-init-message) |
4345

4446
## Requirements
4547

4648
The origin node:
47-
* If it supports a feature above, SHOULD set the corresponding odd
48-
bit in all feature fields indicated by the Context column unless
49-
indicated that it must set the even feature bit instead.
50-
* If it requires a feature above, MUST set the corresponding even
51-
feature bit in all feature fields indicated by the Context column,
52-
unless indicated that it must set the odd feature bit instead.
53-
* MUST NOT set feature bits it does not support.
54-
* MUST NOT set feature bits in fields not specified by the table above.
55-
* MUST set all transitive feature dependencies.
49+
50+
* If it supports a feature above, SHOULD set the corresponding odd
51+
bit in all feature fields indicated by the Context column unless
52+
indicated that it must set the even feature bit instead.
53+
* If it requires a feature above, MUST set the corresponding even
54+
feature bit in all feature fields indicated by the Context column,
55+
unless indicated that it must set the odd feature bit instead.
56+
* MUST NOT set feature bits it does not support.
57+
* MUST NOT set feature bits in fields not specified by the table above.
58+
* MUST set all transitive feature dependencies.
5659

5760
The requirements for receiving specific bits are defined in the linked sections in the table above.
5861
The requirements for feature bits that are not defined

0 commit comments

Comments
 (0)