@@ -707,37 +707,43 @@ 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
+ // Both fees correspond to the same channel.
712
+ pub lowest_inbound_channel_fees_to_one : Option < RoutingFees > ,
713
+ // Lowest fees to enter the second direction, based on the cheapest channel to the source node.
714
+ // Both fees correspond to the same channel.
715
+ pub lowest_inbound_channel_fees_to_two : Option < RoutingFees > ,
710
716
}
711
717
712
718
impl ChannelInfo {
713
719
/// Returns a [`DirectedChannelInfo`] for the channel directed to the given `target` from a
714
720
/// returned `source`, or `None` if `target` is not one of the channel's counterparties.
715
721
pub fn as_directed_to ( & self , target : & NodeId ) -> Option < ( DirectedChannelInfo , & NodeId ) > {
716
- let ( direction, source) = {
722
+ let ( direction, source, lowest_inbound_channel_fees ) = {
717
723
if target == & self . node_one {
718
- ( self . two_to_one . as_ref ( ) , & self . node_two )
724
+ ( self . two_to_one . as_ref ( ) , & self . node_two , self . lowest_inbound_channel_fees_to_two )
719
725
} else if target == & self . node_two {
720
- ( self . one_to_two . as_ref ( ) , & self . node_one )
726
+ ( self . one_to_two . as_ref ( ) , & self . node_one , self . lowest_inbound_channel_fees_to_one )
721
727
} else {
722
728
return None ;
723
729
}
724
730
} ;
725
- Some ( ( DirectedChannelInfo :: new ( self , direction) , source) )
731
+ Some ( ( DirectedChannelInfo :: new ( self , direction, lowest_inbound_channel_fees ) , source) )
726
732
}
727
733
728
734
/// Returns a [`DirectedChannelInfo`] for the channel directed from the given `source` to a
729
735
/// returned `target`, or `None` if `source` is not one of the channel's counterparties.
730
736
pub fn as_directed_from ( & self , source : & NodeId ) -> Option < ( DirectedChannelInfo , & NodeId ) > {
731
- let ( direction, target) = {
737
+ let ( direction, target, lowest_inbound_channel_fees ) = {
732
738
if source == & self . node_one {
733
- ( self . one_to_two . as_ref ( ) , & self . node_two )
739
+ ( self . one_to_two . as_ref ( ) , & self . node_two , self . lowest_inbound_channel_fees_to_two )
734
740
} else if source == & self . node_two {
735
- ( self . two_to_one . as_ref ( ) , & self . node_one )
741
+ ( self . two_to_one . as_ref ( ) , & self . node_one , self . lowest_inbound_channel_fees_to_one )
736
742
} else {
737
743
return None ;
738
744
}
739
745
} ;
740
- Some ( ( DirectedChannelInfo :: new ( self , direction) , target) )
746
+ Some ( ( DirectedChannelInfo :: new ( self , direction, lowest_inbound_channel_fees ) , target) )
741
747
}
742
748
743
749
/// Returns a [`ChannelUpdateInfo`] based on the direction implied by the channel_flag.
@@ -770,6 +776,8 @@ impl Writeable for ChannelInfo {
770
776
( 8 , self . two_to_one, required) ,
771
777
( 10 , self . capacity_sats, required) ,
772
778
( 12 , self . announcement_message, required) ,
779
+ ( 14 , self . lowest_inbound_channel_fees_to_one, option) ,
780
+ ( 16 , self . lowest_inbound_channel_fees_to_two, option) ,
773
781
} ) ;
774
782
Ok ( ( ) )
775
783
}
@@ -803,6 +811,8 @@ impl Readable for ChannelInfo {
803
811
let mut two_to_one_wrap: Option < ChannelUpdateInfoDeserWrapper > = None ;
804
812
init_tlv_field_var ! ( capacity_sats, required) ;
805
813
init_tlv_field_var ! ( announcement_message, required) ;
814
+ init_tlv_field_var ! ( lowest_inbound_channel_fees_to_one, option) ;
815
+ init_tlv_field_var ! ( lowest_inbound_channel_fees_to_two, option) ;
806
816
read_tlv_fields ! ( reader, {
807
817
( 0 , features, required) ,
808
818
( 1 , announcement_received_time, ( default_value, 0 ) ) ,
@@ -812,6 +822,8 @@ impl Readable for ChannelInfo {
812
822
( 8 , two_to_one_wrap, ignorable) ,
813
823
( 10 , capacity_sats, required) ,
814
824
( 12 , announcement_message, required) ,
825
+ ( 14 , lowest_inbound_channel_fees_to_one, option) ,
826
+ ( 16 , lowest_inbound_channel_fees_to_two, option) ,
815
827
} ) ;
816
828
817
829
Ok ( ChannelInfo {
@@ -823,6 +835,8 @@ impl Readable for ChannelInfo {
823
835
capacity_sats : init_tlv_based_struct_field ! ( capacity_sats, required) ,
824
836
announcement_message : init_tlv_based_struct_field ! ( announcement_message, required) ,
825
837
announcement_received_time : init_tlv_based_struct_field ! ( announcement_received_time, ( default_value, 0 ) ) ,
838
+ lowest_inbound_channel_fees_to_one : init_tlv_based_struct_field ! ( lowest_inbound_channel_fees_to_one, option) ,
839
+ lowest_inbound_channel_fees_to_two : init_tlv_based_struct_field ! ( lowest_inbound_channel_fees_to_two, option) ,
826
840
} )
827
841
}
828
842
}
@@ -835,11 +849,12 @@ pub struct DirectedChannelInfo<'a> {
835
849
direction : Option < & ' a ChannelUpdateInfo > ,
836
850
htlc_maximum_msat : u64 ,
837
851
effective_capacity : EffectiveCapacity ,
852
+ lowest_inbound_channel_fees : Option < RoutingFees > ,
838
853
}
839
854
840
855
impl < ' a > DirectedChannelInfo < ' a > {
841
856
#[ inline]
842
- fn new ( channel : & ' a ChannelInfo , direction : Option < & ' a ChannelUpdateInfo > ) -> Self {
857
+ fn new ( channel : & ' a ChannelInfo , direction : Option < & ' a ChannelUpdateInfo > , lowest_inbound_channel_fees : Option < RoutingFees > ) -> Self {
843
858
let htlc_maximum_msat = direction. map ( |direction| direction. htlc_maximum_msat ) ;
844
859
let capacity_msat = channel. capacity_sats . map ( |capacity_sats| capacity_sats * 1000 ) ;
845
860
@@ -858,7 +873,7 @@ impl<'a> DirectedChannelInfo<'a> {
858
873
} ;
859
874
860
875
Self {
861
- channel, direction, htlc_maximum_msat, effective_capacity
876
+ channel, direction, htlc_maximum_msat, effective_capacity, lowest_inbound_channel_fees ,
862
877
}
863
878
}
864
879
@@ -882,6 +897,10 @@ impl<'a> DirectedChannelInfo<'a> {
882
897
self . effective_capacity
883
898
}
884
899
900
+ pub fn lowest_inbound_channel_fees ( & self ) -> Option < RoutingFees > {
901
+ self . lowest_inbound_channel_fees
902
+ }
903
+
885
904
/// Returns `Some` if [`ChannelUpdateInfo`] is available in the direction.
886
905
pub ( super ) fn with_update ( self ) -> Option < DirectedChannelInfoWithUpdate < ' a > > {
887
906
match self . direction {
@@ -917,6 +936,10 @@ impl<'a> DirectedChannelInfoWithUpdate<'a> {
917
936
/// Returns the [`EffectiveCapacity`] of the channel in the direction.
918
937
#[ inline]
919
938
pub ( super ) fn effective_capacity ( & self ) -> EffectiveCapacity { self . inner . effective_capacity ( ) }
939
+
940
+ #[ inline]
941
+ pub ( super ) fn lowest_inbound_channel_fees ( & self ) -> Option < RoutingFees > { self . inner . lowest_inbound_channel_fees ( ) }
942
+
920
943
}
921
944
922
945
impl < ' a > fmt:: Debug for DirectedChannelInfoWithUpdate < ' a > {
@@ -1382,6 +1405,8 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1382
1405
capacity_sats : None ,
1383
1406
announcement_message : None ,
1384
1407
announcement_received_time : timestamp,
1408
+ lowest_inbound_channel_fees_to_one : None ,
1409
+ lowest_inbound_channel_fees_to_two : None ,
1385
1410
} ;
1386
1411
1387
1412
self . add_channel_between_nodes ( short_channel_id, channel_info, None )
@@ -1524,6 +1549,8 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1524
1549
announcement_message : if msg. excess_data . len ( ) <= MAX_EXCESS_BYTES_FOR_RELAY
1525
1550
{ full_msg. cloned ( ) } else { None } ,
1526
1551
announcement_received_time,
1552
+ lowest_inbound_channel_fees_to_one : None ,
1553
+ lowest_inbound_channel_fees_to_two : None ,
1527
1554
} ;
1528
1555
1529
1556
self . add_channel_between_nodes ( msg. short_channel_id , chan_info, utxo_value)
@@ -1752,22 +1779,20 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1752
1779
}
1753
1780
1754
1781
let mut nodes = self . nodes . write ( ) . unwrap ( ) ;
1782
+ let node = nodes. get_mut ( & dest_node_id) . unwrap ( ) ;
1783
+ let mut updated_lowest_inbound_channel_fee = None ;
1755
1784
if chan_enabled {
1756
- let node = nodes. get_mut ( & dest_node_id) . unwrap ( ) ;
1757
1785
let mut base_msat = msg. fee_base_msat ;
1758
1786
let mut proportional_millionths = msg. fee_proportional_millionths ;
1759
1787
if let Some ( fees) = node. lowest_inbound_channel_fees {
1760
1788
base_msat = cmp:: min ( base_msat, fees. base_msat ) ;
1761
1789
proportional_millionths = cmp:: min ( proportional_millionths, fees. proportional_millionths ) ;
1762
1790
}
1763
- node . lowest_inbound_channel_fees = Some ( RoutingFees {
1791
+ updated_lowest_inbound_channel_fee = Some ( RoutingFees {
1764
1792
base_msat,
1765
1793
proportional_millionths
1766
1794
} ) ;
1767
1795
} 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
1796
for chan_id in node. channels . iter ( ) {
1772
1797
let chan = channels. get ( chan_id) . unwrap ( ) ;
1773
1798
let chan_info_opt;
@@ -1778,15 +1803,27 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1778
1803
}
1779
1804
if let Some ( chan_info) = chan_info_opt {
1780
1805
if chan_info. enabled {
1781
- let fees = lowest_inbound_channel_fees . get_or_insert ( RoutingFees {
1806
+ let fees = updated_lowest_inbound_channel_fee . get_or_insert ( RoutingFees {
1782
1807
base_msat : u32:: max_value ( ) , proportional_millionths : u32:: max_value ( ) } ) ;
1783
1808
fees. base_msat = cmp:: min ( fees. base_msat , chan_info. fees . base_msat ) ;
1784
1809
fees. proportional_millionths = cmp:: min ( fees. proportional_millionths , chan_info. fees . proportional_millionths ) ;
1785
1810
}
1786
1811
}
1787
1812
}
1813
+ }
1788
1814
1789
- node. lowest_inbound_channel_fees = lowest_inbound_channel_fees;
1815
+ if updated_lowest_inbound_channel_fee. is_some ( ) {
1816
+ node. lowest_inbound_channel_fees = updated_lowest_inbound_channel_fee;
1817
+
1818
+ for ( _, chan) in channels. iter_mut ( ) {
1819
+ if chan. node_one == dest_node_id {
1820
+ chan. lowest_inbound_channel_fees_to_two = updated_lowest_inbound_channel_fee;
1821
+ }
1822
+
1823
+ if chan. node_two == dest_node_id {
1824
+ chan. lowest_inbound_channel_fees_to_one = updated_lowest_inbound_channel_fee;
1825
+ }
1826
+ }
1790
1827
}
1791
1828
1792
1829
Ok ( ( ) )
@@ -3019,6 +3056,8 @@ mod tests {
3019
3056
capacity_sats : None ,
3020
3057
announcement_message : None ,
3021
3058
announcement_received_time : 87654 ,
3059
+ lowest_inbound_channel_fees_to_one : None ,
3060
+ lowest_inbound_channel_fees_to_two : None ,
3022
3061
} ;
3023
3062
3024
3063
let mut encoded_chan_info: Vec < u8 > = Vec :: new ( ) ;
@@ -3037,6 +3076,8 @@ mod tests {
3037
3076
capacity_sats : None ,
3038
3077
announcement_message : None ,
3039
3078
announcement_received_time : 87654 ,
3079
+ lowest_inbound_channel_fees_to_one : None ,
3080
+ lowest_inbound_channel_fees_to_two : None ,
3040
3081
} ;
3041
3082
3042
3083
let mut encoded_chan_info: Vec < u8 > = Vec :: new ( ) ;
0 commit comments