Skip to content

Commit cc9fc65

Browse files
authored
Merge pull request #3098 from arik-so/arik/gossip-v2-parsing
Parse v2 gossip
2 parents 3ec0dcd + ab0c35f commit cc9fc65

File tree

3 files changed

+351
-29
lines changed

3 files changed

+351
-29
lines changed

lightning-rapid-gossip-sync/README.md

+35-11
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,24 @@ updates are known.
1212

1313
Essentially, the serialization structure is as follows:
1414

15-
1. Fixed prefix bytes `76, 68, 75, 1` (the first three bytes are ASCII for `LDK`)
15+
1. Fixed prefix bytes `76, 68, 75` (the first three bytes are ASCII for `LDK`)
1616
- The purpose of this prefix is to identify the serialization format, should other rapid gossip
1717
sync formats arise in the future
18-
- The fourth byte is the protocol version in case our format gets updated
19-
2. Chain hash (32 bytes)
20-
3. Latest seen timestamp (`u32`)
21-
4. An unsigned int indicating the number of node IDs to follow
22-
5. An array of compressed node ID pubkeys (all pubkeys are presumed to be standard
18+
2. Version byte
19+
- Currently supported versions are 1 and 2
20+
3. Chain hash (32 bytes)
21+
4. Latest seen timestamp (`u32`)
22+
5. Version 2 only:
23+
- A byte indicating the number of default node features
24+
- An array of node features
25+
6. An unsigned int indicating the number of node IDs to follow
26+
7. An array of compressed node ID pubkeys (all pubkeys are presumed to be standard
2327
compressed 33-byte-serializations)
24-
6. An unsigned int indicating the number of channel announcement messages to follow
25-
7. An array of significantly stripped down customized channel announcements
26-
8. An unsigned int indicating the number of channel update messages to follow
27-
9. A series of default values used for non-incremental channel updates
28+
- Version 2 only: Each pubkey is optionally followed by supplemental feature or address information.
29+
8. An unsigned int indicating the number of channel announcement messages to follow
30+
9. An array of significantly stripped down customized channel announcements
31+
10. An unsigned int indicating the number of channel update messages to follow
32+
11. A series of default values used for non-incremental channel updates
2833
- The values are defined as follows:
2934
1. `default_cltv_expiry_delta`
3035
2. `default_htlc_minimum_msat`
@@ -33,7 +38,7 @@ Essentially, the serialization structure is as follows:
3338
5. `default_htlc_maximum_msat` (`u64`, and if the default is no maximum, `u64::MAX`)
3439
- The defaults are calculated by the server based on the frequency among non-incremental
3540
updates within a given delta set
36-
10. An array of customized channel updates
41+
12. An array of customized channel updates
3742

3843
You will also notice that `NodeAnnouncement` messages are omitted altogether as the node IDs are
3944
implicitly extracted from the channel announcements and updates.
@@ -42,6 +47,25 @@ The data is then applied to the current network graph, artificially dated to the
4247
latest seen message less one week, be it an announcement or an update, from the server's
4348
perspective. The network graph should not be pruned until the graph sync completes.
4449

50+
### Custom Node Announcement (V2 Only)
51+
52+
In version 2 of the RGS protocol, node IDs may be followed by supplemental feature and socket address data. The presence
53+
of those additional fields is indicated by utilizing the unused bits of the 33-byte-pubkey parity byte as follows:
54+
55+
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
56+
|-----------------|----------|--------------|--------------|--------------|--------------|------------|------------------|
57+
| Additional data | Reminder | Feature data | Feature data | Feature data | Address data | Always set | Odd y-coordinate |
58+
59+
Note that bit indices 3-5 all indicate feature data. Specifically, if none of the bits are set, that means there is
60+
no feature data that follows the pubkey. If a subset of them are set, the bit triplet is interpreted as an index (less
61+
one) of the default node features that were supplied prior. If all three bits are set, a custom feature combination is
62+
sent.
63+
64+
If there have been no changes to a node, bit index 6 can be set to function as a reminder absent any address or feature
65+
data.
66+
67+
Lastly, bit index 7 indicates the presence of additional data, which will allow forwards compatibility.
68+
4569
### Custom Channel Announcement
4670

4771
To achieve compactness and avoid data repetition, we're sending a significantly stripped down

lightning-rapid-gossip-sync/src/lib.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,18 @@ pub enum GraphSyncError {
9292
LightningError(LightningError),
9393
}
9494

95-
impl From<lightning::io::Error> for GraphSyncError {
96-
fn from(error: lightning::io::Error) -> Self {
95+
impl From<io::Error> for GraphSyncError {
96+
fn from(error: io::Error) -> Self {
9797
Self::DecodeError(DecodeError::Io(error.kind()))
9898
}
9999
}
100100

101+
impl From<bitcoin::secp256k1::Error> for GraphSyncError {
102+
fn from(_: bitcoin::secp256k1::Error) -> Self {
103+
Self::DecodeError(DecodeError::InvalidValue)
104+
}
105+
}
106+
101107
impl From<DecodeError> for GraphSyncError {
102108
fn from(error: DecodeError) -> Self {
103109
Self::DecodeError(error)

0 commit comments

Comments
 (0)