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