Skip to content

Commit 7ad6364

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 7ad6364

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-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: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,27 @@ 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 =
278+
funding_sats_read.map(|sats| Some(sats.0)).ok_or(DecodeError::InvalidValue)?;
279+
if !cursor.is_empty() {
280+
log_gossip!(
281+
self.logger,
282+
"Ignoring {} bytes of additional data in channel announcement",
283+
cursor.len()
284+
);
285+
}
286+
}
287+
270288
let announcement_result = network_graph.add_channel_from_partial_announcement(
271289
short_channel_id,
290+
funding_sats,
272291
backdated_timestamp as u64,
273292
features,
274293
node_id_1,
@@ -286,16 +305,6 @@ where
286305
return Err(lightning_error.into());
287306
}
288307
}
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-
}
299308
}
300309

301310
for modification in node_modifications {
@@ -664,7 +673,7 @@ mod tests {
664673
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,
665674
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,
666675
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,
676+
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,
668677
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
669678
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
670679
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
@@ -685,9 +694,11 @@ mod tests {
685694
"Ignoring 255 bytes of additional data in node announcement",
686695
3,
687696
);
697+
// Note that our extra data is 147 bytes long, but the first byte (42) is read as the
698+
// channel's funding amount (as a BigSize).
688699
logger.assert_log_contains(
689700
"lightning_rapid_gossip_sync::processing",
690-
"Ignoring 147 bytes of additional data in channel announcement",
701+
"Ignoring 146 bytes of additional data in channel announcement",
691702
1,
692703
);
693704
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)