Skip to content

Commit 51d146c

Browse files
committed
Make payment_path_failed path type bindings-mappable
The bindings don't currently support passing `Vec`s of objects which it mappes as "opaque types". This is because it will require clones to convert its own list of references to Rust's list of objects. In the near future we should resolve this limitation, allowing us to revert this (and make `find_route`'s method signature similarly cleaner), but for now we must avoid `Vec<OpaqueType>`.
1 parent 2ec427f commit 51d146c

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

lightning-invoice/src/payment.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
//! # fn channel_penalty_msat(
7272
//! # &self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId
7373
//! # ) -> u64 { 0 }
74-
//! # fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, _short_channel_id: u64) {}
74+
//! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
7575
//! # }
7676
//! #
7777
//! # struct FakeLogger {};
@@ -415,7 +415,8 @@ where
415415
all_paths_failed, payment_id, payment_hash, rejected_by_dest, path, short_channel_id, retry, ..
416416
} => {
417417
if let Some(short_channel_id) = short_channel_id {
418-
self.scorer.lock().payment_path_failed(path, *short_channel_id);
418+
let t = path.iter().collect::<Vec<_>>();
419+
self.scorer.lock().payment_path_failed(&t, *short_channel_id);
419420
}
420421

421422
if *rejected_by_dest {
@@ -1099,7 +1100,7 @@ mod tests {
10991100
&self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId
11001101
) -> u64 { 0 }
11011102

1102-
fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, short_channel_id: u64) {
1103+
fn payment_path_failed(&mut self, _path: &[&RouteHop], short_channel_id: u64) {
11031104
if let Some(expected_short_channel_id) = self.expectations.pop_front() {
11041105
assert_eq!(short_channel_id, expected_short_channel_id);
11051106
}

lightning/src/routing/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub trait Score {
3030
fn channel_penalty_msat(&self, short_channel_id: u64, source: &NodeId, target: &NodeId) -> u64;
3131

3232
/// Handles updating channel penalties after failing to route through a channel.
33-
fn payment_path_failed(&mut self, path: &Vec<RouteHop>, short_channel_id: u64);
33+
fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64);
3434
}
3535

3636
/// A scorer that is accessed under a lock.
@@ -70,7 +70,7 @@ impl<S: Score, T: DerefMut<Target=S>> Score for T {
7070
self.deref().channel_penalty_msat(short_channel_id, source, target)
7171
}
7272

73-
fn payment_path_failed(&mut self, path: &Vec<RouteHop>, short_channel_id: u64) {
73+
fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) {
7474
self.deref_mut().payment_path_failed(path, short_channel_id)
7575
}
7676
}

lightning/src/routing/router.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4552,7 +4552,7 @@ mod tests {
45524552
if short_channel_id == self.short_channel_id { u64::max_value() } else { 0 }
45534553
}
45544554

4555-
fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, _short_channel_id: u64) {}
4555+
fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
45564556
}
45574557

45584558
struct BadNodeScorer {
@@ -4564,7 +4564,7 @@ mod tests {
45644564
if *target == self.node_id { u64::max_value() } else { 0 }
45654565
}
45664566

4567-
fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, _short_channel_id: u64) {}
4567+
fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
45684568
}
45694569

45704570
#[test]

lightning/src/routing/scorer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ impl<T: Time> routing::Score for ScorerUsingTime<T> {
220220
self.params.base_penalty_msat + failure_penalty_msat
221221
}
222222

223-
fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, short_channel_id: u64) {
223+
fn payment_path_failed(&mut self, _path: &[&RouteHop], short_channel_id: u64) {
224224
let failure_penalty_msat = self.params.failure_penalty_msat;
225225
let half_life = self.params.failure_penalty_half_life;
226226
self.channel_failures

0 commit comments

Comments
 (0)