Skip to content

Commit 6e1aa6c

Browse files
committed
Fix a few new (and one old) issues in the new channel_update
We need to always set lowest_inbound_channel_fees to None if there are no channels (and we should ignore the channels which are disabled for the purpose of lowest-fee calculations). Further, we cannot unwrap the channel lookups as they may be for channels which are not related to the channel we are processing an update for. Finally, we can satisfy borrowck much easier since things are on self instead of on a MutexGuard.
1 parent 94df32b commit 6e1aa6c

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,8 @@ impl Readable for NodeAnnouncementInfo {
378378
pub struct NodeInfo {
379379
/// All valid channels a node has announced
380380
pub channels: Vec<u64>,
381-
/// Lowest fees enabling routing via any of the known channels to a node.
382-
/// The two fields (flat and proportional fee) are independent,
381+
/// Lowest fees enabling routing via any of the enabled, known channels to a node.
382+
/// The two fields (flat and proportional fee) are independent,
383383
/// meaning they don't have to refer to the same channel.
384384
pub lowest_inbound_channel_fees: Option<RoutingFees>,
385385
/// More information about a node from node_announcement.
@@ -712,34 +712,28 @@ impl NetworkGraph {
712712
proportional_millionths
713713
});
714714
} else if chan_was_enabled {
715-
let mut lowest_inbound_channel_fee_base_msat = u32::max_value();
716-
let mut lowest_inbound_channel_fee_proportional_millionths = u32::max_value();
717-
718-
{
719-
let node = self.nodes.get(&dest_node_id).unwrap();
720-
721-
for chan_id in node.channels.iter() {
722-
let chan = self.channels.get(chan_id).unwrap();
723-
// Since direction was enabled, the channel indeed had directional info
724-
let chan_info;
725-
if chan.node_one == dest_node_id {
726-
chan_info = chan.two_to_one.as_ref().unwrap();
727-
} else {
728-
chan_info = chan.one_to_two.as_ref().unwrap();
715+
let mut node = self.nodes.get_mut(&dest_node_id).unwrap();
716+
let mut lowest_inbound_channel_fees = None;
717+
718+
for chan_id in node.channels.iter() {
719+
let chan = self.channels.get(chan_id).unwrap();
720+
let chan_info_opt;
721+
if chan.node_one == dest_node_id {
722+
chan_info_opt = chan.two_to_one.as_ref();
723+
} else {
724+
chan_info_opt = chan.one_to_two.as_ref();
725+
}
726+
if let Some(chan_info) = chan_info_opt {
727+
if chan_info.enabled {
728+
let fees = lowest_inbound_channel_fees.get_or_insert(RoutingFees {
729+
base_msat: u32::max_value(), proportional_millionths: u32::max_value() });
730+
fees.base_msat = cmp::min(fees.base_msat, chan_info.fees.base_msat);
731+
fees.proportional_millionths = cmp::min(fees.proportional_millionths, chan_info.fees.proportional_millionths);
729732
}
730-
lowest_inbound_channel_fee_base_msat = cmp::min(lowest_inbound_channel_fee_base_msat, chan_info.fees.base_msat);
731-
lowest_inbound_channel_fee_proportional_millionths = cmp::min(lowest_inbound_channel_fee_proportional_millionths, chan_info.fees.proportional_millionths);
732733
}
733734
}
734735

735-
//TODO: satisfy the borrow-checker without a double-map-lookup :(
736-
let mut_node = self.nodes.get_mut(&dest_node_id).unwrap();
737-
if mut_node.channels.len() > 0 {
738-
mut_node.lowest_inbound_channel_fees = Some(RoutingFees {
739-
base_msat: lowest_inbound_channel_fee_base_msat,
740-
proportional_millionths: lowest_inbound_channel_fee_proportional_millionths
741-
});
742-
}
736+
node.lowest_inbound_channel_fees = lowest_inbound_channel_fees;
743737
}
744738

745739
Ok(msg.contents.excess_data.is_empty())

0 commit comments

Comments
 (0)