Skip to content

Commit eb1e6fb

Browse files
Review changes
1 parent 44262b6 commit eb1e6fb

File tree

1 file changed

+43
-29
lines changed

1 file changed

+43
-29
lines changed

lightning/src/routing/network_graph.rs

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -540,30 +540,30 @@ impl NetworkGraph {
540540
None
541541
}
542542

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)
547547
pub fn score_payment_sent_for_route(&mut self, route: Vec<Vec<RouteHop>>) -> Result<bool, LightningError> {
548+
let mut channel_down: bool = false;
548549
for path in route {
549550
for route_hop in path {
550551
let short_channel_id = route_hop.short_channel_id;
551552
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;
559555
} 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;
564558
}
565559
}
566560
}
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+
}
567567
Ok(true)
568568
}
569569

@@ -573,9 +573,6 @@ impl NetworkGraph {
573573
/// against a list of at fault nodes that determines whether the node's channel score should be
574574
/// penalized for failing to execute or rewarded for executing properly.
575575
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-
}
579576
for path in route {
580577
for route_hop in path {
581578
let short_channel_id = route_hop.short_channel_id;
@@ -1808,24 +1805,41 @@ mod tests {
18081805
let channel_info = network.channels.get_mut(&chan_id).unwrap();
18091806
// Assign a DirectionalChannelInfo and ChannelScore object to one_to_two of
18101807
// 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 {
18121813
payment_sent_score: 0,
18131814
payment_failed_score: 0,
18141815
};
1816+
18151817
let dummy_routing_fee = RoutingFees {
18161818
base_msat: 0,
18171819
proportional_millionths: 0,
18181820
};
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 {
18201832
last_update: 0,
18211833
enabled: true,
18221834
cltv_expiry_delta: 0,
18231835
htlc_minimum_msat: 0,
18241836
fees: dummy_routing_fee,
18251837
last_update_message: None,
1826-
channel_score: chan_score,
1838+
channel_score: chan_score_2,
18271839
};
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);
18291843
let dir_one_to_two = channel_info.one_to_two.as_mut().unwrap();
18301844
assert_eq!(dir_one_to_two.channel_score.payment_sent_score, 0);
18311845
assert_eq!(dir_one_to_two.channel_score.payment_failed_score, 0);
@@ -1835,13 +1849,13 @@ mod tests {
18351849
// Assume a payment is made, and node 1 is learning of a PaymentSent event. It now calls
18361850
// its score_payment_sent_for_route on itself.
18371851
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+
};
18451859
let sent_paths: Vec<RouteHop> = vec![route_hop];
18461860
let sent_route: Vec<Vec<RouteHop>> = vec![sent_paths];
18471861
let mut network = net_graph_msg_handler.network_graph.write().unwrap();

0 commit comments

Comments
 (0)