//! # struct FakeRouter {};
//! # impl<S: routing::Score> Router<S> for FakeRouter {
//! # fn find_route(
-//! # &self, payer: &PublicKey, params: &RouteParameters,
+//! # &self, payer: &PublicKey, params: &RouteParameters, payment_hash: &PaymentHash,
//! # first_hops: Option<&[&ChannelDetails]>, scorer: &S
//! # ) -> Result<Route, LightningError> { unimplemented!() }
//! # }
pub trait Router<S: routing::Score> {
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
fn find_route(
- &self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>,
- scorer: &S
+ &self, payer: &PublicKey, params: &RouteParameters, payment_hash: &PaymentHash,
+ first_hops: Option<&[&ChannelDetails]>, scorer: &S
) -> Result<Route, LightningError>;
}
let payer = self.payer.node_id();
let first_hops = self.payer.first_hops();
let route = self.router.find_route(
- &payer,
- params,
- Some(&first_hops.iter().collect::<Vec<_>>()),
- &self.scorer.lock(),
+ &payer, params, &payment_hash, Some(&first_hops.iter().collect::<Vec<_>>()),
+ &self.scorer.lock()
).map_err(|e| PaymentError::Routing(e))?;
match send_payment(&route) {
let payer = self.payer.node_id();
let first_hops = self.payer.first_hops();
- let route = self.router.find_route(&payer, ¶ms, Some(&first_hops.iter().collect::<Vec<_>>()), &self.scorer.lock());
+ let route = self.router.find_route(
+ &payer, ¶ms, &payment_hash, Some(&first_hops.iter().collect::<Vec<_>>()),
+ &self.scorer.lock()
+ );
if route.is_err() {
log_trace!(self.logger, "Failed to find a route for payment {}; not retrying (attempts: {})", log_bytes!(payment_hash.0), attempts);
return Err(());
impl<S: routing::Score> Router<S> for TestRouter {
fn find_route(
- &self,
- _payer: &PublicKey,
- params: &RouteParameters,
- _first_hops: Option<&[&ChannelDetails]>,
- _scorer: &S,
+ &self, _payer: &PublicKey, params: &RouteParameters, _payment_hash: &PaymentHash,
+ _first_hops: Option<&[&ChannelDetails]>, _scorer: &S
) -> Result<Route, LightningError> {
Ok(Route {
payee: Some(params.payee.clone()), ..Self::route_for_value(params.final_value_msat)
impl<S: routing::Score> Router<S> for FailingRouter {
fn find_route(
- &self,
- _payer: &PublicKey,
- _params: &RouteParameters,
- _first_hops: Option<&[&ChannelDetails]>,
- _scorer: &S,
+ &self, _payer: &PublicKey, _params: &RouteParameters, _payment_hash: &PaymentHash,
+ _first_hops: Option<&[&ChannelDetails]>, _scorer: &S
) -> Result<Route, LightningError> {
Err(LightningError { err: String::new(), action: ErrorAction::IgnoreError })
}
struct ManualRouter(RefCell<VecDeque<Result<Route, LightningError>>>);
impl<S: routing::Score> Router<S> for ManualRouter {
- fn find_route(&self, _payer: &PublicKey, _params: &RouteParameters, _first_hops: Option<&[&ChannelDetails]>, _scorer: &S)
- -> Result<Route, LightningError> {
+ fn find_route(
+ &self, _payer: &PublicKey, _params: &RouteParameters, _payment_hash: &PaymentHash,
+ _first_hops: Option<&[&ChannelDetails]>, _scorer: &S
+ ) -> Result<Route, LightningError> {
self.0.borrow_mut().pop_front().unwrap()
}
}
impl<G, L: Deref, S: routing::Score> Router<S> for DefaultRouter<G, L>
where G: Deref<Target = NetworkGraph>, L::Target: Logger {
fn find_route(
- &self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>,
- scorer: &S
+ &self, payer: &PublicKey, params: &RouteParameters, _payment_hash: &PaymentHash,
+ first_hops: Option<&[&ChannelDetails]>, scorer: &S
) -> Result<Route, LightningError> {
find_route(payer, params, &*self.network_graph, first_hops, &*self.logger, scorer)
}