Skip to content

Commit a97b8f7

Browse files
Fix scoring methods to score Paths instead of Vec<RouteHop>s
1 parent a3f7fb2 commit a97b8f7

File tree

4 files changed

+158
-113
lines changed

4 files changed

+158
-113
lines changed

lightning-background-processor/src/lib.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -236,26 +236,21 @@ fn update_scorer<'a, S: 'static + Deref<Target = SC> + Send + Sync, SC: 'a + Wri
236236
let mut score = scorer.lock();
237237
match event {
238238
Event::PaymentPathFailed { ref path, short_channel_id: Some(scid), .. } => {
239-
let path = path.hops.iter().collect::<Vec<_>>();
240-
score.payment_path_failed(&path, *scid);
239+
score.payment_path_failed(path, *scid);
241240
},
242241
Event::PaymentPathFailed { ref path, payment_failed_permanently: true, .. } => {
243242
// Reached if the destination explicitly failed it back. We treat this as a successful probe
244243
// because the payment made it all the way to the destination with sufficient liquidity.
245-
let path = path.hops.iter().collect::<Vec<_>>();
246-
score.probe_successful(&path);
244+
score.probe_successful(path);
247245
},
248246
Event::PaymentPathSuccessful { path, .. } => {
249-
let path = path.hops.iter().collect::<Vec<_>>();
250-
score.payment_path_successful(&path);
247+
score.payment_path_successful(path);
251248
},
252249
Event::ProbeSuccessful { path, .. } => {
253-
let path = path.hops.iter().collect::<Vec<_>>();
254-
score.probe_successful(&path);
250+
score.probe_successful(path);
255251
},
256252
Event::ProbeFailed { path, short_channel_id: Some(scid), .. } => {
257-
let path = path.hops.iter().collect::<Vec<_>>();
258-
score.probe_failed(&path, *scid);
253+
score.probe_failed(path, *scid);
259254
},
260255
_ => {},
261256
}
@@ -916,11 +911,11 @@ mod tests {
916911
&self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId, _usage: ChannelUsage
917912
) -> u64 { unimplemented!(); }
918913

919-
fn payment_path_failed(&mut self, actual_path: &[&RouteHop], actual_short_channel_id: u64) {
914+
fn payment_path_failed(&mut self, actual_path: &Path, actual_short_channel_id: u64) {
920915
if let Some(expectations) = &mut self.event_expectations {
921916
match expectations.pop_front().unwrap() {
922917
TestResult::PaymentFailure { path, short_channel_id } => {
923-
assert_eq!(actual_path, &path.hops.iter().collect::<Vec<_>>()[..]);
918+
assert_eq!(actual_path, &path);
924919
assert_eq!(actual_short_channel_id, short_channel_id);
925920
},
926921
TestResult::PaymentSuccess { path } => {
@@ -936,14 +931,14 @@ mod tests {
936931
}
937932
}
938933

939-
fn payment_path_successful(&mut self, actual_path: &[&RouteHop]) {
934+
fn payment_path_successful(&mut self, actual_path: &Path) {
940935
if let Some(expectations) = &mut self.event_expectations {
941936
match expectations.pop_front().unwrap() {
942937
TestResult::PaymentFailure { path, .. } => {
943938
panic!("Unexpected payment path failure: {:?}", path)
944939
},
945940
TestResult::PaymentSuccess { path } => {
946-
assert_eq!(actual_path, &path.hops.iter().collect::<Vec<_>>()[..]);
941+
assert_eq!(actual_path, &path);
947942
},
948943
TestResult::ProbeFailure { path } => {
949944
panic!("Unexpected probe failure: {:?}", path)
@@ -955,7 +950,7 @@ mod tests {
955950
}
956951
}
957952

958-
fn probe_failed(&mut self, actual_path: &[&RouteHop], _: u64) {
953+
fn probe_failed(&mut self, actual_path: &Path, _: u64) {
959954
if let Some(expectations) = &mut self.event_expectations {
960955
match expectations.pop_front().unwrap() {
961956
TestResult::PaymentFailure { path, .. } => {
@@ -965,15 +960,15 @@ mod tests {
965960
panic!("Unexpected payment path success: {:?}", path)
966961
},
967962
TestResult::ProbeFailure { path } => {
968-
assert_eq!(actual_path, &path.hops.iter().collect::<Vec<_>>()[..]);
963+
assert_eq!(actual_path, &path);
969964
},
970965
TestResult::ProbeSuccess { path } => {
971966
panic!("Unexpected probe success: {:?}", path)
972967
}
973968
}
974969
}
975970
}
976-
fn probe_successful(&mut self, actual_path: &[&RouteHop]) {
971+
fn probe_successful(&mut self, actual_path: &Path) {
977972
if let Some(expectations) = &mut self.event_expectations {
978973
match expectations.pop_front().unwrap() {
979974
TestResult::PaymentFailure { path, .. } => {
@@ -986,7 +981,7 @@ mod tests {
986981
panic!("Unexpected probe failure: {:?}", path)
987982
},
988983
TestResult::ProbeSuccess { path } => {
989-
assert_eq!(actual_path, &path.hops.iter().collect::<Vec<_>>()[..]);
984+
assert_eq!(actual_path, &path);
990985
}
991986
}
992987
}

lightning/src/routing/router.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,19 @@ impl<'a, S: Score> Score for ScorerAccountingForInFlightHtlcs<'a, S> {
137137
}
138138
}
139139

140-
fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) {
140+
fn payment_path_failed(&mut self, path: &Path, short_channel_id: u64) {
141141
self.scorer.payment_path_failed(path, short_channel_id)
142142
}
143143

144-
fn payment_path_successful(&mut self, path: &[&RouteHop]) {
144+
fn payment_path_successful(&mut self, path: &Path) {
145145
self.scorer.payment_path_successful(path)
146146
}
147147

148-
fn probe_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) {
148+
fn probe_failed(&mut self, path: &Path, short_channel_id: u64) {
149149
self.scorer.probe_failed(path, short_channel_id)
150150
}
151151

152-
fn probe_successful(&mut self, path: &[&RouteHop]) {
152+
fn probe_successful(&mut self, path: &Path) {
153153
self.scorer.probe_successful(path)
154154
}
155155
}
@@ -2251,13 +2251,13 @@ fn build_route_from_hops_internal<L: Deref>(
22512251
u64::max_value()
22522252
}
22532253

2254-
fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
2254+
fn payment_path_failed(&mut self, _path: &Path, _short_channel_id: u64) {}
22552255

2256-
fn payment_path_successful(&mut self, _path: &[&RouteHop]) {}
2256+
fn payment_path_successful(&mut self, _path: &Path) {}
22572257

2258-
fn probe_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
2258+
fn probe_failed(&mut self, _path: &Path, _short_channel_id: u64) {}
22592259

2260-
fn probe_successful(&mut self, _path: &[&RouteHop]) {}
2260+
fn probe_successful(&mut self, _path: &Path) {}
22612261
}
22622262

22632263
impl<'a> Writeable for HopScorer {
@@ -5299,10 +5299,10 @@ mod tests {
52995299
if short_channel_id == self.short_channel_id { u64::max_value() } else { 0 }
53005300
}
53015301

5302-
fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
5303-
fn payment_path_successful(&mut self, _path: &[&RouteHop]) {}
5304-
fn probe_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
5305-
fn probe_successful(&mut self, _path: &[&RouteHop]) {}
5302+
fn payment_path_failed(&mut self, _path: &Path, _short_channel_id: u64) {}
5303+
fn payment_path_successful(&mut self, _path: &Path) {}
5304+
fn probe_failed(&mut self, _path: &Path, _short_channel_id: u64) {}
5305+
fn probe_successful(&mut self, _path: &Path) {}
53065306
}
53075307

53085308
struct BadNodeScorer {
@@ -5319,10 +5319,10 @@ mod tests {
53195319
if *target == self.node_id { u64::max_value() } else { 0 }
53205320
}
53215321

5322-
fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
5323-
fn payment_path_successful(&mut self, _path: &[&RouteHop]) {}
5324-
fn probe_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
5325-
fn probe_successful(&mut self, _path: &[&RouteHop]) {}
5322+
fn payment_path_failed(&mut self, _path: &Path, _short_channel_id: u64) {}
5323+
fn payment_path_successful(&mut self, _path: &Path) {}
5324+
fn probe_failed(&mut self, _path: &Path, _short_channel_id: u64) {}
5325+
fn probe_successful(&mut self, _path: &Path) {}
53265326
}
53275327

53285328
#[test]
@@ -5986,14 +5986,12 @@ mod benches {
59865986
let amount = route.get_total_amount();
59875987
if amount < 250_000 {
59885988
for path in route.paths {
5989-
// fixed to use the whole Path in an upcoming commit
5990-
scorer.payment_path_successful(&path.hops.iter().collect::<Vec<_>>());
5989+
scorer.payment_path_successful(&path);
59915990
}
59925991
} else if amount > 750_000 {
59935992
for path in route.paths {
59945993
let short_channel_id = path.hops[path.hops.len() / 2].short_channel_id;
5995-
// fixed to use the whole Path in an upcoming commit
5996-
scorer.payment_path_failed(&path.hops.iter().collect::<Vec<_>>(), short_channel_id);
5994+
scorer.payment_path_failed(&path, short_channel_id);
59975995
}
59985996
}
59995997
}

0 commit comments

Comments
 (0)