Skip to content

Commit 268370c

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 f1c4bc8 commit 268370c

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
@@ -4553,7 +4553,7 @@ mod tests {
45534553
if short_channel_id == self.short_channel_id { u64::max_value() } else { 0 }
45544554
}
45554555

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

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

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

45714571
#[test]

lightning/src/routing/scorer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl routing::Score for Scorer {
149149
self.params.base_penalty_msat + failure_penalty_msat
150150
}
151151

152-
fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, short_channel_id: u64) {
152+
fn payment_path_failed(&mut self, _path: &[&RouteHop], short_channel_id: u64) {
153153
let failure_penalty_msat = self.params.failure_penalty_msat;
154154
#[cfg(not(feature = "no-std"))]
155155
{

0 commit comments

Comments
 (0)