@@ -707,37 +707,45 @@ pub struct ChannelInfo {
707
707
/// (which we can probably assume we are - no-std environments probably won't have a full
708
708
/// network graph in memory!).
709
709
announcement_received_time : u64 ,
710
+ /// Lowest fees to enter the first direction, based on the cheapest channel to the source node.
711
+ /// The two fields (flat and proportional fee) are independent,
712
+ /// meaning they don't have to refer to the same channel.
713
+ pub lowest_inbound_channel_fees_to_one : Option < RoutingFees > ,
714
+ /// Lowest fees to enter the second direction, based on the cheapest channel to the source node.
715
+ /// The two fields (flat and proportional fee) are independent,
716
+ /// meaning they don't have to refer to the same channel.
717
+ pub lowest_inbound_channel_fees_to_two : Option < RoutingFees > ,
710
718
}
711
719
712
720
impl ChannelInfo {
713
721
/// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target` from a
714
722
/// returned `source`, or `None` if `target` is not one of the channel's counterparties.
715
723
pub fn as_directed_to ( & self , target : & NodeId ) -> Option < ( DirectedChannelInfo , & NodeId ) > {
716
- let ( direction, source) = {
724
+ let ( direction, source, lowest_inbound_channel_fees ) = {
717
725
if target == & self . node_one {
718
- ( self . two_to_one . as_ref ( ) , & self . node_two )
726
+ ( self . two_to_one . as_ref ( ) , & self . node_two , self . lowest_inbound_channel_fees_to_two )
719
727
} else if target == & self . node_two {
720
- ( self . one_to_two . as_ref ( ) , & self . node_one )
728
+ ( self . one_to_two . as_ref ( ) , & self . node_one , self . lowest_inbound_channel_fees_to_one )
721
729
} else {
722
730
return None ;
723
731
}
724
732
} ;
725
- Some ( ( DirectedChannelInfo :: new ( self , direction) , source) )
733
+ Some ( ( DirectedChannelInfo :: new ( self , direction, lowest_inbound_channel_fees ) , source) )
726
734
}
727
735
728
736
/// Returns a [`DirectedChannelInfo`] for the channel directed from the given `source` to a
729
737
/// returned `target`, or `None` if `source` is not one of the channel's counterparties.
730
738
pub fn as_directed_from ( & self , source : & NodeId ) -> Option < ( DirectedChannelInfo , & NodeId ) > {
731
- let ( direction, target) = {
739
+ let ( direction, target, lowest_inbound_channel_fees ) = {
732
740
if source == & self . node_one {
733
- ( self . one_to_two . as_ref ( ) , & self . node_two )
741
+ ( self . one_to_two . as_ref ( ) , & self . node_two , self . lowest_inbound_channel_fees_to_two )
734
742
} else if source == & self . node_two {
735
- ( self . two_to_one . as_ref ( ) , & self . node_one )
743
+ ( self . two_to_one . as_ref ( ) , & self . node_one , self . lowest_inbound_channel_fees_to_one )
736
744
} else {
737
745
return None ;
738
746
}
739
747
} ;
740
- Some ( ( DirectedChannelInfo :: new ( self , direction) , target) )
748
+ Some ( ( DirectedChannelInfo :: new ( self , direction, lowest_inbound_channel_fees ) , target) )
741
749
}
742
750
743
751
/// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
@@ -770,6 +778,8 @@ impl Writeable for ChannelInfo {
770
778
( 8 , self . two_to_one, required) ,
771
779
( 10 , self . capacity_sats, required) ,
772
780
( 12 , self . announcement_message, required) ,
781
+ ( 14 , self . lowest_inbound_channel_fees_to_one, option) ,
782
+ ( 16 , self . lowest_inbound_channel_fees_to_two, option) ,
773
783
} ) ;
774
784
Ok ( ( ) )
775
785
}
@@ -803,6 +813,8 @@ impl Readable for ChannelInfo {
803
813
let mut two_to_one_wrap: Option < ChannelUpdateInfoDeserWrapper > = None ;
804
814
init_tlv_field_var ! ( capacity_sats, required) ;
805
815
init_tlv_field_var ! ( announcement_message, required) ;
816
+ init_tlv_field_var ! ( lowest_inbound_channel_fees_to_one, option) ;
817
+ init_tlv_field_var ! ( lowest_inbound_channel_fees_to_two, option) ;
806
818
read_tlv_fields ! ( reader, {
807
819
( 0 , features, required) ,
808
820
( 1 , announcement_received_time, ( default_value, 0 ) ) ,
@@ -812,6 +824,8 @@ impl Readable for ChannelInfo {
812
824
( 8 , two_to_one_wrap, ignorable) ,
813
825
( 10 , capacity_sats, required) ,
814
826
( 12 , announcement_message, required) ,
827
+ ( 14 , lowest_inbound_channel_fees_to_one, option) ,
828
+ ( 16 , lowest_inbound_channel_fees_to_two, option) ,
815
829
} ) ;
816
830
817
831
Ok ( ChannelInfo {
@@ -823,6 +837,8 @@ impl Readable for ChannelInfo {
823
837
capacity_sats : init_tlv_based_struct_field ! ( capacity_sats, required) ,
824
838
announcement_message : init_tlv_based_struct_field ! ( announcement_message, required) ,
825
839
announcement_received_time : init_tlv_based_struct_field ! ( announcement_received_time, ( default_value, 0 ) ) ,
840
+ lowest_inbound_channel_fees_to_one : init_tlv_based_struct_field ! ( lowest_inbound_channel_fees_to_one, option) ,
841
+ lowest_inbound_channel_fees_to_two : init_tlv_based_struct_field ! ( lowest_inbound_channel_fees_to_two, option) ,
826
842
} )
827
843
}
828
844
}
@@ -835,11 +851,12 @@ pub struct DirectedChannelInfo<'a> {
835
851
direction : Option < & ' a ChannelUpdateInfo > ,
836
852
htlc_maximum_msat : u64 ,
837
853
effective_capacity : EffectiveCapacity ,
854
+ lowest_inbound_channel_fees : Option < RoutingFees > ,
838
855
}
839
856
840
857
impl < ' a > DirectedChannelInfo < ' a > {
841
858
#[ inline]
842
- fn new ( channel : & ' a ChannelInfo , direction : Option < & ' a ChannelUpdateInfo > ) -> Self {
859
+ fn new ( channel : & ' a ChannelInfo , direction : Option < & ' a ChannelUpdateInfo > , lowest_inbound_channel_fees : Option < RoutingFees > ) -> Self {
843
860
let htlc_maximum_msat = direction. map ( |direction| direction. htlc_maximum_msat ) ;
844
861
let capacity_msat = channel. capacity_sats . map ( |capacity_sats| capacity_sats * 1000 ) ;
845
862
@@ -858,7 +875,7 @@ impl<'a> DirectedChannelInfo<'a> {
858
875
} ;
859
876
860
877
Self {
861
- channel, direction, htlc_maximum_msat, effective_capacity
878
+ channel, direction, htlc_maximum_msat, effective_capacity, lowest_inbound_channel_fees ,
862
879
}
863
880
}
864
881
@@ -882,6 +899,13 @@ impl<'a> DirectedChannelInfo<'a> {
882
899
self . effective_capacity
883
900
}
884
901
902
+ /// Returns the [`Option<RoutingFees>`] to reach the channel in the direction.
903
+ ///
904
+ /// This is based on the known and enabled channels to the entry node.
905
+ pub fn lowest_inbound_channel_fees ( & self ) -> Option < RoutingFees > {
906
+ self . lowest_inbound_channel_fees
907
+ }
908
+
885
909
/// Returns `Some` if [`ChannelUpdateInfo`] is available in the direction.
886
910
pub ( super ) fn with_update ( self ) -> Option < DirectedChannelInfoWithUpdate < ' a > > {
887
911
match self . direction {
@@ -917,6 +941,10 @@ impl<'a> DirectedChannelInfoWithUpdate<'a> {
917
941
/// Returns the [`EffectiveCapacity`] of the channel in the direction.
918
942
#[ inline]
919
943
pub ( super ) fn effective_capacity ( & self ) -> EffectiveCapacity { self . inner . effective_capacity ( ) }
944
+
945
+ #[ inline]
946
+ pub ( super ) fn lowest_inbound_channel_fees ( & self ) -> Option < RoutingFees > { self . inner . lowest_inbound_channel_fees ( ) }
947
+
920
948
}
921
949
922
950
impl < ' a > fmt:: Debug for DirectedChannelInfoWithUpdate < ' a > {
@@ -1382,6 +1410,8 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1382
1410
capacity_sats : None ,
1383
1411
announcement_message : None ,
1384
1412
announcement_received_time : timestamp,
1413
+ lowest_inbound_channel_fees_to_one : None ,
1414
+ lowest_inbound_channel_fees_to_two : None ,
1385
1415
} ;
1386
1416
1387
1417
self . add_channel_between_nodes ( short_channel_id, channel_info, None )
@@ -1524,6 +1554,8 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1524
1554
announcement_message : if msg. excess_data . len ( ) <= MAX_EXCESS_BYTES_FOR_RELAY
1525
1555
{ full_msg. cloned ( ) } else { None } ,
1526
1556
announcement_received_time,
1557
+ lowest_inbound_channel_fees_to_one : None ,
1558
+ lowest_inbound_channel_fees_to_two : None ,
1527
1559
} ;
1528
1560
1529
1561
self . add_channel_between_nodes ( msg. short_channel_id , chan_info, utxo_value)
@@ -1752,22 +1784,20 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1752
1784
}
1753
1785
1754
1786
let mut nodes = self . nodes . write ( ) . unwrap ( ) ;
1787
+ let node = nodes. get_mut ( & dest_node_id) . unwrap ( ) ;
1788
+ let mut updated_lowest_inbound_channel_fee = None ;
1755
1789
if chan_enabled {
1756
- let node = nodes. get_mut ( & dest_node_id) . unwrap ( ) ;
1757
1790
let mut base_msat = msg. fee_base_msat ;
1758
1791
let mut proportional_millionths = msg. fee_proportional_millionths ;
1759
1792
if let Some ( fees) = node. lowest_inbound_channel_fees {
1760
1793
base_msat = cmp:: min ( base_msat, fees. base_msat ) ;
1761
1794
proportional_millionths = cmp:: min ( proportional_millionths, fees. proportional_millionths ) ;
1762
1795
}
1763
- node . lowest_inbound_channel_fees = Some ( RoutingFees {
1796
+ updated_lowest_inbound_channel_fee = Some ( RoutingFees {
1764
1797
base_msat,
1765
1798
proportional_millionths
1766
1799
} ) ;
1767
1800
} else if chan_was_enabled {
1768
- let node = nodes. get_mut ( & dest_node_id) . unwrap ( ) ;
1769
- let mut lowest_inbound_channel_fees = None ;
1770
-
1771
1801
for chan_id in node. channels . iter ( ) {
1772
1802
let chan = channels. get ( chan_id) . unwrap ( ) ;
1773
1803
let chan_info_opt;
@@ -1778,15 +1808,27 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1778
1808
}
1779
1809
if let Some ( chan_info) = chan_info_opt {
1780
1810
if chan_info. enabled {
1781
- let fees = lowest_inbound_channel_fees . get_or_insert ( RoutingFees {
1811
+ let fees = updated_lowest_inbound_channel_fee . get_or_insert ( RoutingFees {
1782
1812
base_msat : u32:: max_value ( ) , proportional_millionths : u32:: max_value ( ) } ) ;
1783
1813
fees. base_msat = cmp:: min ( fees. base_msat , chan_info. fees . base_msat ) ;
1784
1814
fees. proportional_millionths = cmp:: min ( fees. proportional_millionths , chan_info. fees . proportional_millionths ) ;
1785
1815
}
1786
1816
}
1787
1817
}
1818
+ }
1788
1819
1789
- node. lowest_inbound_channel_fees = lowest_inbound_channel_fees;
1820
+ if updated_lowest_inbound_channel_fee. is_some ( ) {
1821
+ node. lowest_inbound_channel_fees = updated_lowest_inbound_channel_fee;
1822
+
1823
+ for ( _, chan) in channels. iter_mut ( ) {
1824
+ if chan. node_one == dest_node_id {
1825
+ chan. lowest_inbound_channel_fees_to_two = updated_lowest_inbound_channel_fee;
1826
+ }
1827
+
1828
+ if chan. node_two == dest_node_id {
1829
+ chan. lowest_inbound_channel_fees_to_one = updated_lowest_inbound_channel_fee;
1830
+ }
1831
+ }
1790
1832
}
1791
1833
1792
1834
Ok ( ( ) )
@@ -3019,6 +3061,8 @@ mod tests {
3019
3061
capacity_sats : None ,
3020
3062
announcement_message : None ,
3021
3063
announcement_received_time : 87654 ,
3064
+ lowest_inbound_channel_fees_to_one : None ,
3065
+ lowest_inbound_channel_fees_to_two : None ,
3022
3066
} ;
3023
3067
3024
3068
let mut encoded_chan_info: Vec < u8 > = Vec :: new ( ) ;
@@ -3037,6 +3081,8 @@ mod tests {
3037
3081
capacity_sats : None ,
3038
3082
announcement_message : None ,
3039
3083
announcement_received_time : 87654 ,
3084
+ lowest_inbound_channel_fees_to_one : None ,
3085
+ lowest_inbound_channel_fees_to_two : None ,
3040
3086
} ;
3041
3087
3042
3088
let mut encoded_chan_info: Vec < u8 > = Vec :: new ( ) ;
0 commit comments