Skip to content

Commit 04c0512

Browse files
committed
Swap Vec<&RouteHop> parameters for slices
In c353c3e, new scorer-updating methods were added to the `Router` object, however they were passed as a `Vec` of references. We use the list-of-references pattern to make bindings simpler (by not requiring allocations per entry), however there's no reason prefer to passing a `Vec` over a slice, given the `Vec` doesn't hold ownership of the objects anyway.
1 parent dc28f9b commit 04c0512

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

lightning-invoice/src/payment.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@
7777
//! # first_hops: Option<&[&ChannelDetails]>, _inflight_htlcs: InFlightHtlcs
7878
//! # ) -> Result<Route, LightningError> { unimplemented!() }
7979
//! #
80-
//! # fn notify_payment_path_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64) { unimplemented!() }
81-
//! # fn notify_payment_path_successful(&self, path: Vec<&RouteHop>) { unimplemented!() }
82-
//! # fn notify_payment_probe_successful(&self, path: Vec<&RouteHop>) { unimplemented!() }
83-
//! # fn notify_payment_probe_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64) { unimplemented!() }
80+
//! # fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
81+
//! # fn notify_payment_path_successful(&self, path: &[&RouteHop]) { unimplemented!() }
82+
//! # fn notify_payment_probe_successful(&self, path: &[&RouteHop]) { unimplemented!() }
83+
//! # fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
8484
//! # }
8585
//! #
8686
//! # struct FakeScorer {}
@@ -273,13 +273,13 @@ pub trait Router {
273273
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
274274
) -> Result<Route, LightningError>;
275275
/// Lets the router know that payment through a specific path has failed.
276-
fn notify_payment_path_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64);
276+
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64);
277277
/// Lets the router know that payment through a specific path was successful.
278-
fn notify_payment_path_successful(&self, path: Vec<&RouteHop>);
278+
fn notify_payment_path_successful(&self, path: &[&RouteHop]);
279279
/// Lets the router know that a payment probe was successful.
280-
fn notify_payment_probe_successful(&self, path: Vec<&RouteHop>);
280+
fn notify_payment_probe_successful(&self, path: &[&RouteHop]);
281281
/// Lets the router know that a payment probe failed.
282-
fn notify_payment_probe_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64);
282+
fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64);
283283
}
284284

285285
/// Strategies available to retry payment path failures for an [`Invoice`].
@@ -680,7 +680,7 @@ where
680680
} => {
681681
if let Some(short_channel_id) = short_channel_id {
682682
let path = path.iter().collect::<Vec<_>>();
683-
self.router.notify_payment_path_failed(path, *short_channel_id)
683+
self.router.notify_payment_path_failed(&path, *short_channel_id)
684684
}
685685

686686
if payment_id.is_none() {
@@ -703,7 +703,7 @@ where
703703
},
704704
Event::PaymentPathSuccessful { path, .. } => {
705705
let path = path.iter().collect::<Vec<_>>();
706-
self.router.notify_payment_path_successful(path);
706+
self.router.notify_payment_path_successful(&path);
707707
},
708708
Event::PaymentSent { payment_hash, .. } => {
709709
let mut payment_cache = self.payment_cache.lock().unwrap();
@@ -715,13 +715,13 @@ where
715715
Event::ProbeSuccessful { payment_hash, path, .. } => {
716716
log_trace!(self.logger, "Probe payment {} of {}msat was successful", log_bytes!(payment_hash.0), path.last().unwrap().fee_msat);
717717
let path = path.iter().collect::<Vec<_>>();
718-
self.router.notify_payment_probe_successful(path);
718+
self.router.notify_payment_probe_successful(&path);
719719
},
720720
Event::ProbeFailed { payment_hash, path, short_channel_id, .. } => {
721721
if let Some(short_channel_id) = short_channel_id {
722722
log_trace!(self.logger, "Probe payment {} of {}msat failed at channel {}", log_bytes!(payment_hash.0), path.last().unwrap().fee_msat, *short_channel_id);
723723
let path = path.iter().collect::<Vec<_>>();
724-
self.router.notify_payment_probe_failed(path, *short_channel_id);
724+
self.router.notify_payment_probe_failed(&path, *short_channel_id);
725725
}
726726
},
727727
_ => {},
@@ -1844,19 +1844,19 @@ mod tests {
18441844
})
18451845
}
18461846

1847-
fn notify_payment_path_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64) {
1847+
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) {
18481848
self.scorer.lock().payment_path_failed(&path, short_channel_id);
18491849
}
18501850

1851-
fn notify_payment_path_successful(&self, path: Vec<&RouteHop>) {
1851+
fn notify_payment_path_successful(&self, path: &[&RouteHop]) {
18521852
self.scorer.lock().payment_path_successful(&path);
18531853
}
18541854

1855-
fn notify_payment_probe_successful(&self, path: Vec<&RouteHop>) {
1855+
fn notify_payment_probe_successful(&self, path: &[&RouteHop]) {
18561856
self.scorer.lock().probe_successful(&path);
18571857
}
18581858

1859-
fn notify_payment_probe_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64) {
1859+
fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64) {
18601860
self.scorer.lock().probe_failed(&path, short_channel_id);
18611861
}
18621862
}
@@ -1871,13 +1871,13 @@ mod tests {
18711871
Err(LightningError { err: String::new(), action: ErrorAction::IgnoreError })
18721872
}
18731873

1874-
fn notify_payment_path_failed(&self, _path: Vec<&RouteHop>, _short_channel_id: u64) {}
1874+
fn notify_payment_path_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
18751875

1876-
fn notify_payment_path_successful(&self, _path: Vec<&RouteHop>) {}
1876+
fn notify_payment_path_successful(&self, _path: &[&RouteHop]) {}
18771877

1878-
fn notify_payment_probe_successful(&self, _path: Vec<&RouteHop>) {}
1878+
fn notify_payment_probe_successful(&self, _path: &[&RouteHop]) {}
18791879

1880-
fn notify_payment_probe_failed(&self, _path: Vec<&RouteHop>, _short_channel_id: u64) {}
1880+
fn notify_payment_probe_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
18811881
}
18821882

18831883
struct TestScorer {
@@ -2133,13 +2133,13 @@ mod tests {
21332133
self.0.borrow_mut().pop_front().unwrap()
21342134
}
21352135

2136-
fn notify_payment_path_failed(&self, _path: Vec<&RouteHop>, _short_channel_id: u64) {}
2136+
fn notify_payment_path_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
21372137

2138-
fn notify_payment_path_successful(&self, _path: Vec<&RouteHop>) {}
2138+
fn notify_payment_path_successful(&self, _path: &[&RouteHop]) {}
21392139

2140-
fn notify_payment_probe_successful(&self, _path: Vec<&RouteHop>) {}
2140+
fn notify_payment_probe_successful(&self, _path: &[&RouteHop]) {}
21412141

2142-
fn notify_payment_probe_failed(&self, _path: Vec<&RouteHop>, _short_channel_id: u64) {}
2142+
fn notify_payment_probe_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {}
21432143
}
21442144
impl ManualRouter {
21452145
fn expect_find_route(&self, result: Result<Route, LightningError>) {

lightning-invoice/src/utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,19 +483,19 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref> Router for DefaultR
483483
)
484484
}
485485

486-
fn notify_payment_path_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64) {
486+
fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) {
487487
self.scorer.lock().payment_path_failed(&path, short_channel_id);
488488
}
489489

490-
fn notify_payment_path_successful(&self, path: Vec<&RouteHop>) {
490+
fn notify_payment_path_successful(&self, path: &[&RouteHop]) {
491491
self.scorer.lock().payment_path_successful(&path);
492492
}
493493

494-
fn notify_payment_probe_successful(&self, path: Vec<&RouteHop>) {
494+
fn notify_payment_probe_successful(&self, path: &[&RouteHop]) {
495495
self.scorer.lock().probe_successful(&path);
496496
}
497497

498-
fn notify_payment_probe_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64) {
498+
fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64) {
499499
self.scorer.lock().probe_failed(&path, short_channel_id);
500500
}
501501
}

0 commit comments

Comments
 (0)