X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-invoice%2Fsrc%2Fpayment.rs;h=ee85fab0b5dbe8081d3b21e367c36125c28ecf92;hb=7bc52aa62cb3c32f51b242ad3fa0ae16aee80cec;hp=21d7def4a51e9feadac7b4e6c7488b5714f98409;hpb=ca76d0675b5e3b123a92e19937d2f64b91355773;p=rust-lightning diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index 21d7def4..ee85fab0 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -77,10 +77,10 @@ //! # first_hops: Option<&[&ChannelDetails]>, _inflight_htlcs: InFlightHtlcs //! # ) -> Result { unimplemented!() } //! # -//! # fn notify_payment_path_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64) { unimplemented!() } -//! # fn notify_payment_path_successful(&self, path: Vec<&RouteHop>) { unimplemented!() } -//! # fn notify_payment_probe_successful(&self, path: Vec<&RouteHop>) { unimplemented!() } -//! # fn notify_payment_probe_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64) { unimplemented!() } +//! # fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() } +//! # fn notify_payment_path_successful(&self, path: &[&RouteHop]) { unimplemented!() } +//! # fn notify_payment_probe_successful(&self, path: &[&RouteHop]) { unimplemented!() } +//! # fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() } //! # } //! # //! # struct FakeScorer {} @@ -149,6 +149,7 @@ use lightning::routing::router::{PaymentParameters, Route, RouteHop, RouteParame use lightning::util::errors::APIError; use lightning::util::events::{Event, EventHandler}; use lightning::util::logger::Logger; +use lightning::util::ser::Writeable; use time_utils::Time; use crate::sync::Mutex; @@ -273,13 +274,13 @@ pub trait Router { first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs ) -> Result; /// Lets the router know that payment through a specific path has failed. - fn notify_payment_path_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64); + fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64); /// Lets the router know that payment through a specific path was successful. - fn notify_payment_path_successful(&self, path: Vec<&RouteHop>); + fn notify_payment_path_successful(&self, path: &[&RouteHop]); /// Lets the router know that a payment probe was successful. - fn notify_payment_probe_successful(&self, path: Vec<&RouteHop>); + fn notify_payment_probe_successful(&self, path: &[&RouteHop]); /// Lets the router know that a payment probe failed. - fn notify_payment_probe_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64); + fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64); } /// Strategies available to retry payment path failures for an [`Invoice`]. @@ -680,7 +681,7 @@ where } => { if let Some(short_channel_id) = short_channel_id { let path = path.iter().collect::>(); - self.router.notify_payment_path_failed(path, *short_channel_id) + self.router.notify_payment_path_failed(&path, *short_channel_id) } if payment_id.is_none() { @@ -703,7 +704,7 @@ where }, Event::PaymentPathSuccessful { path, .. } => { let path = path.iter().collect::>(); - self.router.notify_payment_path_successful(path); + self.router.notify_payment_path_successful(&path); }, Event::PaymentSent { payment_hash, .. } => { let mut payment_cache = self.payment_cache.lock().unwrap(); @@ -715,13 +716,13 @@ where Event::ProbeSuccessful { payment_hash, path, .. } => { log_trace!(self.logger, "Probe payment {} of {}msat was successful", log_bytes!(payment_hash.0), path.last().unwrap().fee_msat); let path = path.iter().collect::>(); - self.router.notify_payment_probe_successful(path); + self.router.notify_payment_probe_successful(&path); }, Event::ProbeFailed { payment_hash, path, short_channel_id, .. } => { if let Some(short_channel_id) = short_channel_id { log_trace!(self.logger, "Probe payment {} of {}msat failed at channel {}", log_bytes!(payment_hash.0), path.last().unwrap().fee_msat, *short_channel_id); let path = path.iter().collect::>(); - self.router.notify_payment_probe_failed(path, *short_channel_id); + self.router.notify_payment_probe_failed(&path, *short_channel_id); } }, _ => {}, @@ -741,12 +742,12 @@ pub struct InFlightHtlcs(HashMap<(u64, bool), u64>); impl InFlightHtlcs { /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel /// id. - pub fn used_liquidity_msat(&self, source: &NodeId, target: &NodeId, channel_scid: u64) -> Option<&u64> { - self.0.get(&(channel_scid, source < target)) + pub fn used_liquidity_msat(&self, source: &NodeId, target: &NodeId, channel_scid: u64) -> Option { + self.0.get(&(channel_scid, source < target)).map(|v| *v) } } -impl lightning::util::ser::Writeable for InFlightHtlcs { +impl Writeable for InFlightHtlcs { fn write(&self, writer: &mut W) -> Result<(), io::Error> { self.0.write(writer) } } @@ -1844,20 +1845,20 @@ mod tests { }) } - fn notify_payment_path_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64) { - self.scorer.lock().payment_path_failed(&path, short_channel_id); + fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) { + self.scorer.lock().payment_path_failed(path, short_channel_id); } - fn notify_payment_path_successful(&self, path: Vec<&RouteHop>) { - self.scorer.lock().payment_path_successful(&path); + fn notify_payment_path_successful(&self, path: &[&RouteHop]) { + self.scorer.lock().payment_path_successful(path); } - fn notify_payment_probe_successful(&self, path: Vec<&RouteHop>) { - self.scorer.lock().probe_successful(&path); + fn notify_payment_probe_successful(&self, path: &[&RouteHop]) { + self.scorer.lock().probe_successful(path); } - fn notify_payment_probe_failed(&self, path: Vec<&RouteHop>, short_channel_id: u64) { - self.scorer.lock().probe_failed(&path, short_channel_id); + fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64) { + self.scorer.lock().probe_failed(path, short_channel_id); } } @@ -1871,13 +1872,13 @@ mod tests { Err(LightningError { err: String::new(), action: ErrorAction::IgnoreError }) } - fn notify_payment_path_failed(&self, _path: Vec<&RouteHop>, _short_channel_id: u64) {} + fn notify_payment_path_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {} - fn notify_payment_path_successful(&self, _path: Vec<&RouteHop>) {} + fn notify_payment_path_successful(&self, _path: &[&RouteHop]) {} - fn notify_payment_probe_successful(&self, _path: Vec<&RouteHop>) {} + fn notify_payment_probe_successful(&self, _path: &[&RouteHop]) {} - fn notify_payment_probe_failed(&self, _path: Vec<&RouteHop>, _short_channel_id: u64) {} + fn notify_payment_probe_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {} } struct TestScorer { @@ -1912,7 +1913,7 @@ mod tests { #[cfg(c_bindings)] impl lightning::util::ser::Writeable for TestScorer { - fn write(&self, _: &mut W) -> Result<(), std::io::Error> { unreachable!(); } + fn write(&self, _: &mut W) -> Result<(), lightning::io::Error> { unreachable!(); } } impl Score for TestScorer { @@ -2133,13 +2134,13 @@ mod tests { self.0.borrow_mut().pop_front().unwrap() } - fn notify_payment_path_failed(&self, _path: Vec<&RouteHop>, _short_channel_id: u64) {} + fn notify_payment_path_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {} - fn notify_payment_path_successful(&self, _path: Vec<&RouteHop>) {} + fn notify_payment_path_successful(&self, _path: &[&RouteHop]) {} - fn notify_payment_probe_successful(&self, _path: Vec<&RouteHop>) {} + fn notify_payment_probe_successful(&self, _path: &[&RouteHop]) {} - fn notify_payment_probe_failed(&self, _path: Vec<&RouteHop>, _short_channel_id: u64) {} + fn notify_payment_probe_failed(&self, _path: &[&RouteHop], _short_channel_id: u64) {} } impl ManualRouter { fn expect_find_route(&self, result: Result) {