Skip to content

Use channel's real funding amounts when processing RGS data #3924

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2521,6 +2521,7 @@ mod tests {
.network_graph
.add_channel_from_partial_announcement(
42,
None,
53,
features,
$nodes[0].node.get_our_node_id().into(),
Expand Down
34 changes: 22 additions & 12 deletions lightning-rapid-gossip-sync/src/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,26 @@ where
latest_seen_timestamp
);

let mut funding_sats: Option<u64> = None;

if version >= 2 && has_additional_data {
// forwards compatibility
let additional_data: Vec<u8> = Readable::read(read_cursor)?;
let mut cursor = &additional_data[..];
let funding_sats_read: BigSize = Readable::read(&mut cursor)?;
funding_sats = Some(funding_sats_read.0);
if !cursor.is_empty() {
log_gossip!(
self.logger,
"Ignoring {} bytes of additional data in channel announcement",
cursor.len()
);
}
}

let announcement_result = network_graph.add_channel_from_partial_announcement(
short_channel_id,
funding_sats,
backdated_timestamp as u64,
features,
node_id_1,
Expand All @@ -286,16 +304,6 @@ where
return Err(lightning_error.into());
}
}

if version >= 2 && has_additional_data {
// forwards compatibility
let additional_data: Vec<u8> = Readable::read(read_cursor)?;
log_gossip!(
self.logger,
"Ignoring {} bytes of additional data in channel announcement",
additional_data.len()
);
}
}

for modification in node_modifications {
Expand Down Expand Up @@ -664,7 +672,7 @@ mod tests {
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,
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,
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,
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,
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,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
Expand All @@ -685,9 +693,11 @@ mod tests {
"Ignoring 255 bytes of additional data in node announcement",
3,
);
// Note that our extra data is 147 bytes long, but the first byte (42) is read as the
// channel's funding amount (as a BigSize).
logger.assert_log_contains(
"lightning_rapid_gossip_sync::processing",
"Ignoring 147 bytes of additional data in channel announcement",
"Ignoring 146 bytes of additional data in channel announcement",
1,
);
logger.assert_log_contains(
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/routing/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2006,8 +2006,8 @@ where
///
/// All other parameters as used in [`msgs::UnsignedChannelAnnouncement`] fields.
pub fn add_channel_from_partial_announcement(
&self, short_channel_id: u64, timestamp: u64, features: ChannelFeatures, node_id_1: NodeId,
node_id_2: NodeId,
&self, short_channel_id: u64, capacity_sats: Option<u64>, timestamp: u64,
features: ChannelFeatures, node_id_1: NodeId, node_id_2: NodeId,
) -> Result<(), LightningError> {
if node_id_1 == node_id_2 {
return Err(LightningError {
Expand All @@ -2022,7 +2022,7 @@ where
one_to_two: None,
node_two: node_id_2,
two_to_one: None,
capacity_sats: None,
capacity_sats,
announcement_message: None,
announcement_received_time: timestamp,
node_one_counter: u32::max_value(),
Expand Down
Loading