@@ -1433,7 +1433,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1433
1433
// b) we don't track UTXOs of channels we know about and remove them if they
1434
1434
// get reorg'd out.
1435
1435
// c) it's unclear how to do so without exposing ourselves to massive DoS risk.
1436
- Self :: remove_channel_in_nodes ( & mut nodes, & entry. get ( ) , short_channel_id) ;
1436
+ self . remove_channel_in_nodes ( & mut nodes, & entry. get ( ) , short_channel_id) ;
1437
1437
* entry. get_mut ( ) = channel_info;
1438
1438
} else {
1439
1439
return Err ( LightningError { err : "Already have knowledge of channel" . to_owned ( ) , action : ErrorAction :: IgnoreDuplicateGossip } ) ;
@@ -1565,7 +1565,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1565
1565
if is_permanent {
1566
1566
if let Some ( chan) = channels. remove ( & short_channel_id) {
1567
1567
let mut nodes = self . nodes . write ( ) . unwrap ( ) ;
1568
- Self :: remove_channel_in_nodes ( & mut nodes, & chan, short_channel_id) ;
1568
+ self . remove_channel_in_nodes ( & mut nodes, & chan, short_channel_id) ;
1569
1569
}
1570
1570
} else {
1571
1571
if let Some ( chan) = channels. get_mut ( & short_channel_id) {
@@ -1646,7 +1646,7 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1646
1646
let mut nodes = self . nodes . write ( ) . unwrap ( ) ;
1647
1647
for scid in scids_to_remove {
1648
1648
let info = channels. remove ( & scid) . expect ( "We just accessed this scid, it should be present" ) ;
1649
- Self :: remove_channel_in_nodes ( & mut nodes, & info, scid) ;
1649
+ self . remove_channel_in_nodes ( & mut nodes, & info, scid) ;
1650
1650
}
1651
1651
}
1652
1652
}
@@ -1780,56 +1780,24 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1780
1780
1781
1781
let mut nodes = self . nodes . write ( ) . unwrap ( ) ;
1782
1782
let node = nodes. get_mut ( & dest_node_id) . unwrap ( ) ;
1783
- let mut updated_lowest_inbound_channel_fee = None ;
1784
1783
if chan_enabled {
1785
1784
let mut base_msat = msg. fee_base_msat ;
1786
1785
let mut proportional_millionths = msg. fee_proportional_millionths ;
1787
1786
if let Some ( fees) = node. lowest_inbound_channel_fees {
1788
1787
base_msat = cmp:: min ( base_msat, fees. base_msat ) ;
1789
1788
proportional_millionths = cmp:: min ( proportional_millionths, fees. proportional_millionths ) ;
1790
1789
}
1791
- updated_lowest_inbound_channel_fee = Some ( RoutingFees {
1792
- base_msat,
1793
- proportional_millionths
1794
- } ) ;
1790
+ self . update_lowest_inbound_channel_fees ( dest_node_id, node, & mut channels, Some ( RoutingFees {
1791
+ base_msat, proportional_millionths
1792
+ } ) ) ;
1795
1793
} else if chan_was_enabled {
1796
- for chan_id in node. channels . iter ( ) {
1797
- let chan = channels. get ( chan_id) . unwrap ( ) ;
1798
- let chan_info_opt;
1799
- if chan. node_one == dest_node_id {
1800
- chan_info_opt = chan. two_to_one . as_ref ( ) ;
1801
- } else {
1802
- chan_info_opt = chan. one_to_two . as_ref ( ) ;
1803
- }
1804
- if let Some ( chan_info) = chan_info_opt {
1805
- if chan_info. enabled {
1806
- let fees = updated_lowest_inbound_channel_fee. get_or_insert ( RoutingFees {
1807
- base_msat : u32:: max_value ( ) , proportional_millionths : u32:: max_value ( ) } ) ;
1808
- fees. base_msat = cmp:: min ( fees. base_msat , chan_info. fees . base_msat ) ;
1809
- fees. proportional_millionths = cmp:: min ( fees. proportional_millionths , chan_info. fees . proportional_millionths ) ;
1810
- }
1811
- }
1812
- }
1813
- }
1814
-
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
- }
1794
+ self . recompute_and_update_lowest_inbound_channel_fees ( dest_node_id, node, & mut channels) ;
1827
1795
}
1828
1796
1829
1797
Ok ( ( ) )
1830
1798
}
1831
1799
1832
- fn remove_channel_in_nodes ( nodes : & mut BTreeMap < NodeId , NodeInfo > , chan : & ChannelInfo , short_channel_id : u64 ) {
1800
+ fn remove_channel_in_nodes ( & self , nodes : & mut BTreeMap < NodeId , NodeInfo > , chan : & ChannelInfo , short_channel_id : u64 ) {
1833
1801
macro_rules! remove_from_node {
1834
1802
( $node_id: expr) => {
1835
1803
if let BtreeEntry :: Occupied ( mut entry) = nodes. entry( $node_id) {
@@ -1842,12 +1810,51 @@ impl<L: Deref> NetworkGraph<L> where L::Target: Logger {
1842
1810
} else {
1843
1811
panic!( "Had channel that pointed to unknown node (ie inconsistent network map)!" ) ;
1844
1812
}
1813
+ if let Some ( node) = nodes. get_mut( & $node_id) {
1814
+ self . recompute_and_update_lowest_inbound_channel_fees( $node_id, node, & mut self . channels. write( ) . unwrap( ) ) ;
1815
+ }
1845
1816
}
1846
1817
}
1847
1818
1848
1819
remove_from_node ! ( chan. node_one) ;
1849
1820
remove_from_node ! ( chan. node_two) ;
1850
1821
}
1822
+
1823
+ fn recompute_and_update_lowest_inbound_channel_fees ( & self , node_id : NodeId , node : & mut NodeInfo , channels : & mut BTreeMap < u64 , ChannelInfo > ) {
1824
+ let mut updated_lowest_inbound_channel_fee = None ;
1825
+ for chan_id in node. channels . iter ( ) {
1826
+ let chan = channels. get ( chan_id) . unwrap ( ) ;
1827
+ let chan_info_opt;
1828
+ if chan. node_one == node_id {
1829
+ chan_info_opt = chan. two_to_one . as_ref ( ) ;
1830
+ } else {
1831
+ chan_info_opt = chan. one_to_two . as_ref ( ) ;
1832
+ }
1833
+ if let Some ( chan_info) = chan_info_opt {
1834
+ if chan_info. enabled {
1835
+ let fees = updated_lowest_inbound_channel_fee. get_or_insert ( RoutingFees {
1836
+ base_msat : u32:: max_value ( ) , proportional_millionths : u32:: max_value ( ) } ) ;
1837
+ fees. base_msat = cmp:: min ( fees. base_msat , chan_info. fees . base_msat ) ;
1838
+ fees. proportional_millionths = cmp:: min ( fees. proportional_millionths , chan_info. fees . proportional_millionths ) ;
1839
+ }
1840
+ }
1841
+ }
1842
+ self . update_lowest_inbound_channel_fees ( node_id, node, channels, updated_lowest_inbound_channel_fee) ;
1843
+ }
1844
+
1845
+ fn update_lowest_inbound_channel_fees ( & self , node_id : NodeId , node : & mut NodeInfo , channels : & mut BTreeMap < u64 , ChannelInfo > , updated_fees : Option < RoutingFees > ) {
1846
+ node. lowest_inbound_channel_fees = updated_fees;
1847
+ for ( _, chan) in channels. iter_mut ( ) {
1848
+ if chan. node_one == node_id {
1849
+ chan. lowest_inbound_channel_fees_to_two = updated_fees;
1850
+ }
1851
+
1852
+ if chan. node_two == node_id {
1853
+ chan. lowest_inbound_channel_fees_to_one = updated_fees;
1854
+ }
1855
+ }
1856
+ }
1857
+
1851
1858
}
1852
1859
1853
1860
impl ReadOnlyNetworkGraph < ' _ > {
0 commit comments