@@ -540,30 +540,30 @@ impl NetworkGraph {
540
540
None
541
541
}
542
542
543
- /// Increments payment_sent_score for appropriate DirectionalChannelInfos on the network graph.
544
- /// The appropriate directional channel is indentified by the RouteHop, which includes a
545
- /// PublicKey field. This is matched against the two PublicKey fields in ChannelInfo and is
546
- /// used to increment the score.
543
+ /// Increments payment_sent_score for both DirectionalChannelInfos on any channel that
544
+ /// cooperatively executed a successful payment. In the future, this could be more nuanced (eg
545
+ /// only score the direction that cooperates, bring in other parameters for the channel_score
546
+ /// field within DirectionalChannelInfo)
547
547
pub fn score_payment_sent_for_route ( & mut self , route : Vec < Vec < RouteHop > > ) -> Result < bool , LightningError > {
548
+ let mut channel_down: bool = false ;
548
549
for path in route {
549
550
for route_hop in path {
550
551
let short_channel_id = route_hop. short_channel_id ;
551
552
if let Some ( channel) = self . channels . get_mut ( & short_channel_id) {
552
- let directional_channel_info = if route_hop. pubkey == channel. node_one {
553
- channel. one_to_two . as_mut ( ) . unwrap ( )
554
- } else {
555
- channel. two_to_one . as_mut ( ) . unwrap ( )
556
- } ;
557
- let channel_score = & mut directional_channel_info. channel_score ;
558
- channel_score. payment_sent_score += 1 ;
553
+ channel. one_to_two . as_mut ( ) . unwrap ( ) . channel_score . payment_sent_score += 1 ;
554
+ channel. two_to_one . as_mut ( ) . unwrap ( ) . channel_score . payment_sent_score += 1 ;
559
555
} else {
560
- return Err ( LightningError {
561
- err : "PaymentSent event occurred for this channel, but the channel was closed before scoring" ,
562
- action : ErrorAction :: IgnoreError
563
- } ) ;
556
+ channel_down = true ;
557
+ continue ;
564
558
}
565
559
}
566
560
}
561
+ if channel_down {
562
+ return Err ( LightningError {
563
+ err : "PaymentSent event occurred for this channel, but the channel was closed before scoring" ,
564
+ action : ErrorAction :: IgnoreError
565
+ } ) ;
566
+ }
567
567
Ok ( true )
568
568
}
569
569
@@ -573,9 +573,6 @@ impl NetworkGraph {
573
573
/// against a list of at fault nodes that determines whether the node's channel score should be
574
574
/// penalized for failing to execute or rewarded for executing properly.
575
575
pub fn score_payment_failed_for_route ( & mut self , route : Vec < Vec < RouteHop > > , faultive_nodes : Vec < PublicKey > ) -> Result < bool , LightningError > {
576
- if faultive_nodes. len ( ) == 0 {
577
- return self . score_payment_sent_for_route ( route)
578
- }
579
576
for path in route {
580
577
for route_hop in path {
581
578
let short_channel_id = route_hop. short_channel_id ;
@@ -1808,24 +1805,41 @@ mod tests {
1808
1805
let channel_info = network. channels . get_mut ( & chan_id) . unwrap ( ) ;
1809
1806
// Assign a DirectionalChannelInfo and ChannelScore object to one_to_two of
1810
1807
// channel_info
1811
- let chan_score = ChannelScore {
1808
+ let chan_score_1 = ChannelScore {
1809
+ payment_sent_score : 0 ,
1810
+ payment_failed_score : 0 ,
1811
+ } ;
1812
+ let chan_score_2 = ChannelScore {
1812
1813
payment_sent_score : 0 ,
1813
1814
payment_failed_score : 0 ,
1814
1815
} ;
1816
+
1815
1817
let dummy_routing_fee = RoutingFees {
1816
1818
base_msat : 0 ,
1817
1819
proportional_millionths : 0 ,
1818
1820
} ;
1819
- let dir_chan_info = DirectionalChannelInfo {
1821
+ let dir_chan_info_1 = DirectionalChannelInfo {
1822
+ last_update : 0 ,
1823
+ enabled : true ,
1824
+ cltv_expiry_delta : 0 ,
1825
+ htlc_minimum_msat : 0 ,
1826
+ fees : dummy_routing_fee,
1827
+ last_update_message : None ,
1828
+ channel_score : chan_score_1,
1829
+ } ;
1830
+
1831
+ let dir_chan_info_2 = DirectionalChannelInfo {
1820
1832
last_update : 0 ,
1821
1833
enabled : true ,
1822
1834
cltv_expiry_delta : 0 ,
1823
1835
htlc_minimum_msat : 0 ,
1824
1836
fees : dummy_routing_fee,
1825
1837
last_update_message : None ,
1826
- channel_score : chan_score ,
1838
+ channel_score : chan_score_2 ,
1827
1839
} ;
1828
- channel_info. one_to_two = Some ( dir_chan_info) ;
1840
+
1841
+ channel_info. one_to_two = Some ( dir_chan_info_1) ;
1842
+ channel_info. two_to_one = Some ( dir_chan_info_2) ;
1829
1843
let dir_one_to_two = channel_info. one_to_two . as_mut ( ) . unwrap ( ) ;
1830
1844
assert_eq ! ( dir_one_to_two. channel_score. payment_sent_score, 0 ) ;
1831
1845
assert_eq ! ( dir_one_to_two. channel_score. payment_failed_score, 0 ) ;
@@ -1835,13 +1849,13 @@ mod tests {
1835
1849
// Assume a payment is made, and node 1 is learning of a PaymentSent event. It now calls
1836
1850
// its score_payment_sent_for_route on itself.
1837
1851
let route_hop = RouteHop {
1838
- pubkey : node_id_1,
1839
- node_features : NodeFeatures :: empty ( ) ,
1840
- short_channel_id : 0 ,
1841
- channel_features : ChannelFeatures :: empty ( ) ,
1842
- fee_msat : 0 ,
1843
- cltv_expiry_delta : 0 ,
1844
- } ;
1852
+ pubkey : node_id_1,
1853
+ node_features : NodeFeatures :: empty ( ) ,
1854
+ short_channel_id : 0 ,
1855
+ channel_features : ChannelFeatures :: empty ( ) ,
1856
+ fee_msat : 0 ,
1857
+ cltv_expiry_delta : 0 ,
1858
+ } ;
1845
1859
let sent_paths: Vec < RouteHop > = vec ! [ route_hop] ;
1846
1860
let sent_route: Vec < Vec < RouteHop > > = vec ! [ sent_paths] ;
1847
1861
let mut network = net_graph_msg_handler. network_graph . write ( ) . unwrap ( ) ;
0 commit comments