//! # first_hops: Option<&[&ChannelDetails]>, _inflight_htlcs: InFlightHtlcs
//! # ) -> Result<Route, LightningError> { 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 {}
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;
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
) -> Result<Route, LightningError>;
/// 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`].
},
PaymentSendFailure::PartialFailure { failed_paths_retry, payment_id, results } => {
// If a `PartialFailure` event returns a result that is an `Ok()`, it means that
- // part of our payment is retried. When we receive `MonitorUpdateFailed`, it
+ // part of our payment is retried. When we receive `MonitorUpdateInProgress`, it
// means that we are still waiting for our channel monitor update to be completed.
for (result, path) in results.iter().zip(route.paths.into_iter()) {
match result {
- Ok(_) | Err(APIError::MonitorUpdateFailed) => {
+ Ok(_) | Err(APIError::MonitorUpdateInProgress) => {
self.process_path_inflight_htlcs(payment_hash, path);
},
_ => {},
},
Err(PaymentSendFailure::PartialFailure { failed_paths_retry, results, .. }) => {
// If a `PartialFailure` error contains a result that is an `Ok()`, it means that
- // part of our payment is retried. When we receive `MonitorUpdateFailed`, it
+ // part of our payment is retried. When we receive `MonitorUpdateInProgress`, it
// means that we are still waiting for our channel monitor update to complete.
for (result, path) in results.iter().zip(route.unwrap().paths.into_iter()) {
match result {
- Ok(_) | Err(APIError::MonitorUpdateFailed) => {
+ Ok(_) | Err(APIError::MonitorUpdateInProgress) => {
self.process_path_inflight_htlcs(payment_hash, path);
},
_ => {},
} => {
if let Some(short_channel_id) = short_channel_id {
let path = path.iter().collect::<Vec<_>>();
- 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() {
},
Event::PaymentPathSuccessful { path, .. } => {
let path = path.iter().collect::<Vec<_>>();
- 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();
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::<Vec<_>>();
- 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::<Vec<_>>();
- self.router.notify_payment_probe_failed(path, *short_channel_id);
+ self.router.notify_payment_probe_failed(&path, *short_channel_id);
}
},
_ => {},
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<u64> {
+ self.0.get(&(channel_scid, source < target)).map(|v| *v)
}
}
-impl lightning::util::ser::Writeable for InFlightHtlcs {
+impl Writeable for InFlightHtlcs {
fn write<W: lightning::util::ser::Writer>(&self, writer: &mut W) -> Result<(), io::Error> { self.0.write(writer) }
}
use std::time::{SystemTime, Duration};
use time_utils::tests::SinceEpoch;
use DEFAULT_EXPIRY_TIME;
- use lightning::util::errors::APIError::{ChannelUnavailable, MonitorUpdateFailed};
+ use lightning::util::errors::APIError::{ChannelUnavailable, MonitorUpdateInProgress};
fn invoice(payment_preimage: PaymentPreimage) -> Invoice {
let payment_hash = Sha256::hash(&payment_preimage.0);
.fails_with_partial_failure(
retry.clone(), OnAttempt(1),
Some(vec![
- Err(ChannelUnavailable { err: "abc".to_string() }), Err(MonitorUpdateFailed)
+ Err(ChannelUnavailable { err: "abc".to_string() }), Err(MonitorUpdateInProgress)
]))
.expect_send(Amount::ForInvoice(final_value_msat));
invoice_payer.pay_invoice(&invoice_to_pay).unwrap();
let inflight_map = invoice_payer.create_inflight_map();
- // Only the second path, which failed with `MonitorUpdateFailed` should be added to our
+ // Only the second path, which failed with `MonitorUpdateInProgress` should be added to our
// inflight map because retries are disabled.
assert_eq!(inflight_map.0.len(), 2);
}
.fails_with_partial_failure(
retry.clone(), OnAttempt(1),
Some(vec![
- Ok(()), Err(MonitorUpdateFailed)
+ Ok(()), Err(MonitorUpdateInProgress)
]))
.expect_send(Amount::ForInvoice(final_value_msat));
})
}
- 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);
}
}
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 {
#[cfg(c_bindings)]
impl lightning::util::ser::Writeable for TestScorer {
- fn write<W: lightning::util::ser::Writer>(&self, _: &mut W) -> Result<(), std::io::Error> { unreachable!(); }
+ fn write<W: lightning::util::ser::Writer>(&self, _: &mut W) -> Result<(), lightning::io::Error> { unreachable!(); }
}
impl Score for TestScorer {
}
fn fails_on_attempt(self, attempt: usize) -> Self {
- let failure = PaymentSendFailure::ParameterError(APIError::MonitorUpdateFailed);
+ let failure = PaymentSendFailure::ParameterError(APIError::MonitorUpdateInProgress);
self.fails_with(failure, OnAttempt(attempt))
}
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<Route, LightningError>) {