3535//! #
3636//! # use lightning::io;
3737//! # use lightning::ln::{PaymentHash, PaymentPreimage, PaymentSecret};
38- //! # use lightning::ln::channelmanager::{ChannelDetails, InFlightHtlcs, PaymentId, PaymentSendFailure};
38+ //! # use lightning::ln::channelmanager::{ChannelDetails, InFlightHtlcs, PaymentId, PaymentSendFailure, Router };
3939//! # use lightning::ln::msgs::LightningError;
4040//! # use lightning::routing::gossip::NodeId;
4141//! # use lightning::routing::router::{Route, RouteHop, RouteParameters};
4444//! # use lightning::util::logger::{Logger, Record};
4545//! # use lightning::util::ser::{Writeable, Writer};
4646//! # use lightning_invoice::Invoice;
47- //! # use lightning_invoice::payment::{InvoicePayer, Payer, Retry, Router };
47+ //! # use lightning_invoice::payment::{InvoicePayer, Payer, Retry, ProbingRouter };
4848//! # use secp256k1::PublicKey;
4949//! # use std::cell::RefCell;
5050//! # use std::ops::Deref;
7979//! #
8080//! # fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
8181//! # fn notify_payment_path_successful(&self, path: &[&RouteHop]) { unimplemented!() }
82+ //! # }
83+ //! # impl ProbingRouter for FakeRouter {
8284//! # fn notify_payment_probe_successful(&self, path: &[&RouteHop]) { unimplemented!() }
8385//! # fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
8486//! # }
@@ -141,7 +143,7 @@ use bitcoin_hashes::sha256::Hash as Sha256;
141143
142144use crate :: prelude:: * ;
143145use lightning:: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
144- use lightning:: ln:: channelmanager:: { ChannelDetails , InFlightHtlcs , PaymentId , PaymentSendFailure } ;
146+ use lightning:: ln:: channelmanager:: { ChannelDetails , InFlightHtlcs , PaymentId , PaymentSendFailure , Router } ;
145147use lightning:: ln:: msgs:: LightningError ;
146148use lightning:: routing:: gossip:: NodeId ;
147149use lightning:: routing:: router:: { PaymentParameters , Route , RouteHop , RouteParameters } ;
@@ -175,7 +177,7 @@ use crate::time_utils;
175177type ConfiguredTime = time_utils:: Eternity ;
176178
177179/// (C-not exported) generally all users should use the [`InvoicePayer`] type alias.
178- pub struct InvoicePayerUsingTime < P : Deref , R : Router , L : Deref , E : EventHandler , T : Time >
180+ pub struct InvoicePayerUsingTime < P : Deref , R : ProbingRouter , L : Deref , E : EventHandler , T : Time >
179181where
180182 P :: Target : Payer ,
181183 L :: Target : Logger ,
@@ -264,17 +266,10 @@ pub trait Payer {
264266 fn abandon_payment ( & self , payment_id : PaymentId ) ;
265267}
266268
267- /// A trait defining behavior for routing an [`Invoice`] payment.
268- pub trait Router {
269- /// Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
270- fn find_route (
271- & self , payer : & PublicKey , route_params : & RouteParameters ,
272- first_hops : Option < & [ & ChannelDetails ] > , inflight_htlcs : InFlightHtlcs
273- ) -> Result < Route , LightningError > ;
274- /// Lets the router know that payment through a specific path has failed.
275- fn notify_payment_path_failed ( & self , path : & [ & RouteHop ] , short_channel_id : u64 ) ;
276- /// Lets the router know that payment through a specific path was successful.
277- fn notify_payment_path_successful ( & self , path : & [ & RouteHop ] ) ;
269+ /// A trait defining behavior for a [`Router`] implementation that also supports probing.
270+ ///
271+ /// [`Router`]: lightning::ln::channelmanager::Router
272+ pub trait ProbingRouter : Router {
278273 /// Lets the router know that a payment probe was successful.
279274 fn notify_payment_probe_successful ( & self , path : & [ & RouteHop ] ) ;
280275 /// Lets the router know that a payment probe failed.
@@ -320,7 +315,7 @@ pub enum PaymentError {
320315 Sending ( PaymentSendFailure ) ,
321316}
322317
323- impl < P : Deref , R : Router , L : Deref , E : EventHandler , T : Time > InvoicePayerUsingTime < P , R , L , E , T >
318+ impl < P : Deref , R : ProbingRouter , L : Deref , E : EventHandler , T : Time > InvoicePayerUsingTime < P , R , L , E , T >
324319where
325320 P :: Target : Payer ,
326321 L :: Target : Logger ,
@@ -654,7 +649,7 @@ fn has_expired(route_params: &RouteParameters) -> bool {
654649 } else { false }
655650}
656651
657- impl < P : Deref , R : Router , L : Deref , E : EventHandler , T : Time > EventHandler for InvoicePayerUsingTime < P , R , L , E , T >
652+ impl < P : Deref , R : ProbingRouter , L : Deref , E : EventHandler , T : Time > EventHandler for InvoicePayerUsingTime < P , R , L , E , T >
658653where
659654 P :: Target : Payer ,
660655 L :: Target : Logger ,
@@ -1781,7 +1776,7 @@ mod tests {
17811776 }
17821777 }
17831778
1784- impl Router for TestRouter {
1779+ impl channelmanager :: Router for TestRouter {
17851780 fn find_route (
17861781 & self , payer : & PublicKey , route_params : & RouteParameters ,
17871782 _first_hops : Option < & [ & ChannelDetails ] > , inflight_htlcs : InFlightHtlcs
@@ -1822,7 +1817,9 @@ mod tests {
18221817 fn notify_payment_path_successful ( & self , path : & [ & RouteHop ] ) {
18231818 self . scorer . lock ( ) . payment_path_successful ( path) ;
18241819 }
1820+ }
18251821
1822+ impl ProbingRouter for TestRouter {
18261823 fn notify_payment_probe_successful ( & self , path : & [ & RouteHop ] ) {
18271824 self . scorer . lock ( ) . probe_successful ( path) ;
18281825 }
@@ -1834,7 +1831,7 @@ mod tests {
18341831
18351832 struct FailingRouter ;
18361833
1837- impl Router for FailingRouter {
1834+ impl channelmanager :: Router for FailingRouter {
18381835 fn find_route (
18391836 & self , _payer : & PublicKey , _params : & RouteParameters , _first_hops : Option < & [ & ChannelDetails ] > ,
18401837 _inflight_htlcs : InFlightHtlcs ,
@@ -1845,7 +1842,9 @@ mod tests {
18451842 fn notify_payment_path_failed ( & self , _path : & [ & RouteHop ] , _short_channel_id : u64 ) { }
18461843
18471844 fn notify_payment_path_successful ( & self , _path : & [ & RouteHop ] ) { }
1845+ }
18481846
1847+ impl ProbingRouter for FailingRouter {
18491848 fn notify_payment_probe_successful ( & self , _path : & [ & RouteHop ] ) { }
18501849
18511850 fn notify_payment_probe_failed ( & self , _path : & [ & RouteHop ] , _short_channel_id : u64 ) { }
@@ -2096,7 +2095,7 @@ mod tests {
20962095 // *** Full Featured Functional Tests with a Real ChannelManager ***
20972096 struct ManualRouter ( RefCell < VecDeque < Result < Route , LightningError > > > ) ;
20982097
2099- impl Router for ManualRouter {
2098+ impl channelmanager :: Router for ManualRouter {
21002099 fn find_route (
21012100 & self , _payer : & PublicKey , _params : & RouteParameters , _first_hops : Option < & [ & ChannelDetails ] > ,
21022101 _inflight_htlcs : InFlightHtlcs
@@ -2107,7 +2106,8 @@ mod tests {
21072106 fn notify_payment_path_failed ( & self , _path : & [ & RouteHop ] , _short_channel_id : u64 ) { }
21082107
21092108 fn notify_payment_path_successful ( & self , _path : & [ & RouteHop ] ) { }
2110-
2109+ }
2110+ impl ProbingRouter for ManualRouter {
21112111 fn notify_payment_probe_successful ( & self , _path : & [ & RouteHop ] ) { }
21122112
21132113 fn notify_payment_probe_failed ( & self , _path : & [ & RouteHop ] , _short_channel_id : u64 ) { }
0 commit comments