@@ -378,8 +378,8 @@ impl Readable for NodeAnnouncementInfo {
378
378
pub struct NodeInfo {
379
379
/// All valid channels a node has announced
380
380
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,
383
383
/// meaning they don't have to refer to the same channel.
384
384
pub lowest_inbound_channel_fees : Option < RoutingFees > ,
385
385
/// More information about a node from node_announcement.
@@ -712,34 +712,28 @@ impl NetworkGraph {
712
712
proportional_millionths
713
713
} ) ;
714
714
} 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 ) ;
729
732
}
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 ) ;
732
733
}
733
734
}
734
735
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;
743
737
}
744
738
745
739
Ok ( msg. contents . excess_data . is_empty ( ) )
0 commit comments