Skip to content

Commit 7ac02a6

Browse files
committed
Use channel's real funding amounts when processing RGS data
Neither `channel_announcement`s nor `channel_update`s contain a channel's actual funding amount, complicating scoring as nodes may set an `htlc_maximum_msat` to something less than the funding amount. When scoring, we use `htlc_maximum_msat` anyway if we don't know the funding amount, but its not a perfect proxy. In lightningdevkit/rapid-gossip-sync-server#102 we started including a channel's real funding amount in RGS data, and here we start parsing it and including it in our network graph. Fixes #1559
1 parent d67bd0f commit 7ac02a6

File tree

3 files changed

+26
-15
lines changed

3 files changed

+26
-15
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2521,6 +2521,7 @@ mod tests {
25212521
.network_graph
25222522
.add_channel_from_partial_announcement(
25232523
42,
2524+
None,
25242525
53,
25252526
features,
25262527
$nodes[0].node.get_our_node_id().into(),

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

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,26 @@ where
267267
latest_seen_timestamp
268268
);
269269

270+
let mut funding_sats: Option<u64> = None;
271+
272+
if version >= 2 && has_additional_data {
273+
// forwards compatibility
274+
let additional_data: Vec<u8> = Readable::read(read_cursor)?;
275+
let mut cursor = &additional_data[..];
276+
let funding_sats_read: Result<BigSize, _> = Readable::read(&mut cursor);
277+
funding_sats = funding_sats_read.map(|sats| Some(sats.0)).unwrap_or(None);
278+
if !cursor.is_empty() {
279+
log_gossip!(
280+
self.logger,
281+
"Ignoring {} bytes of additional data in channel announcement",
282+
cursor.len()
283+
);
284+
}
285+
}
286+
270287
let announcement_result = network_graph.add_channel_from_partial_announcement(
271288
short_channel_id,
289+
funding_sats,
272290
backdated_timestamp as u64,
273291
features,
274292
node_id_1,
@@ -286,16 +304,6 @@ where
286304
return Err(lightning_error.into());
287305
}
288306
}
289-
290-
if version >= 2 && has_additional_data {
291-
// forwards compatibility
292-
let additional_data: Vec<u8> = Readable::read(read_cursor)?;
293-
log_gossip!(
294-
self.logger,
295-
"Ignoring {} bytes of additional data in channel announcement",
296-
additional_data.len()
297-
);
298-
}
299307
}
300308

301309
for modification in node_modifications {
@@ -664,7 +672,7 @@ mod tests {
664672
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
665673
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
666674
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
667-
0, 0, 0, 1, 0, 0, 1, 0, 255, 128, 0, 0, 0, 0, 0, 0, 1, 0, 147, 23, 23, 23, 23, 23, 23,
675+
0, 0, 0, 1, 0, 0, 1, 0, 255, 128, 0, 0, 0, 0, 0, 0, 1, 0, 147, 42, 23, 23, 23, 23, 23,
668676
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
669677
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
670678
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
@@ -685,9 +693,11 @@ mod tests {
685693
"Ignoring 255 bytes of additional data in node announcement",
686694
3,
687695
);
696+
// Note that our extra data is 147 bytes long, but the first byte (42) is read as the
697+
// channel's funding amount (as a BigSize).
688698
logger.assert_log_contains(
689699
"lightning_rapid_gossip_sync::processing",
690-
"Ignoring 147 bytes of additional data in channel announcement",
700+
"Ignoring 146 bytes of additional data in channel announcement",
691701
1,
692702
);
693703
logger.assert_log_contains(

lightning/src/routing/gossip.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,8 +2006,8 @@ where
20062006
///
20072007
/// All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
20082008
pub fn add_channel_from_partial_announcement(
2009-
&self, short_channel_id: u64, timestamp: u64, features: ChannelFeatures, node_id_1: NodeId,
2010-
node_id_2: NodeId,
2009+
&self, short_channel_id: u64, capacity_sats: Option<u64>, timestamp: u64,
2010+
features: ChannelFeatures, node_id_1: NodeId, node_id_2: NodeId,
20112011
) -> Result<(), LightningError> {
20122012
if node_id_1 == node_id_2 {
20132013
return Err(LightningError {
@@ -2022,7 +2022,7 @@ where
20222022
one_to_two: None,
20232023
node_two: node_id_2,
20242024
two_to_one: None,
2025-
capacity_sats: None,
2025+
capacity_sats,
20262026
announcement_message: None,
20272027
announcement_received_time: timestamp,
20282028
node_one_counter: u32::max_value(),

0 commit comments

Comments
 (0)