35
35
//! #
36
36
//! # use lightning::io;
37
37
//! # 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 };
39
39
//! # use lightning::ln::msgs::LightningError;
40
40
//! # use lightning::routing::gossip::NodeId;
41
41
//! # use lightning::routing::router::{Route, RouteHop, RouteParameters};
44
44
//! # use lightning::util::logger::{Logger, Record};
45
45
//! # use lightning::util::ser::{Writeable, Writer};
46
46
//! # use lightning_invoice::Invoice;
47
- //! # use lightning_invoice::payment::{InvoicePayer, Payer, Retry, Router };
47
+ //! # use lightning_invoice::payment::{InvoicePayer, Payer, Retry, ProbingRouter };
48
48
//! # use secp256k1::PublicKey;
49
49
//! # use std::cell::RefCell;
50
50
//! # use std::ops::Deref;
79
79
//! #
80
80
//! # fn notify_payment_path_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
81
81
//! # fn notify_payment_path_successful(&self, path: &[&RouteHop]) { unimplemented!() }
82
+ //! # }
83
+ //! # impl ProbingRouter for FakeRouter {
82
84
//! # fn notify_payment_probe_successful(&self, path: &[&RouteHop]) { unimplemented!() }
83
85
//! # fn notify_payment_probe_failed(&self, path: &[&RouteHop], short_channel_id: u64) { unimplemented!() }
84
86
//! # }
@@ -141,7 +143,7 @@ use bitcoin_hashes::sha256::Hash as Sha256;
141
143
142
144
use crate :: prelude:: * ;
143
145
use lightning:: ln:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
144
- use lightning:: ln:: channelmanager:: { ChannelDetails , InFlightHtlcs , PaymentId , PaymentSendFailure } ;
146
+ use lightning:: ln:: channelmanager:: { ChannelDetails , InFlightHtlcs , PaymentId , PaymentSendFailure , Router } ;
145
147
use lightning:: ln:: msgs:: LightningError ;
146
148
use lightning:: routing:: gossip:: NodeId ;
147
149
use lightning:: routing:: router:: { PaymentParameters , Route , RouteHop , RouteParameters } ;
@@ -175,7 +177,7 @@ use crate::time_utils;
175
177
type ConfiguredTime = time_utils:: Eternity ;
176
178
177
179
/// (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 >
179
181
where
180
182
P :: Target : Payer ,
181
183
L :: Target : Logger ,
@@ -264,17 +266,10 @@ pub trait Payer {
264
266
fn abandon_payment ( & self , payment_id : PaymentId ) ;
265
267
}
266
268
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 {
278
273
/// Lets the router know that a payment probe was successful.
279
274
fn notify_payment_probe_successful ( & self , path : & [ & RouteHop ] ) ;
280
275
/// Lets the router know that a payment probe failed.
@@ -320,7 +315,7 @@ pub enum PaymentError {
320
315
Sending ( PaymentSendFailure ) ,
321
316
}
322
317
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 >
324
319
where
325
320
P :: Target : Payer ,
326
321
L :: Target : Logger ,
@@ -654,7 +649,7 @@ fn has_expired(route_params: &RouteParameters) -> bool {
654
649
} else { false }
655
650
}
656
651
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 >
658
653
where
659
654
P :: Target : Payer ,
660
655
L :: Target : Logger ,
@@ -1781,7 +1776,7 @@ mod tests {
1781
1776
}
1782
1777
}
1783
1778
1784
- impl Router for TestRouter {
1779
+ impl channelmanager :: Router for TestRouter {
1785
1780
fn find_route (
1786
1781
& self , payer : & PublicKey , route_params : & RouteParameters ,
1787
1782
_first_hops : Option < & [ & ChannelDetails ] > , inflight_htlcs : InFlightHtlcs
@@ -1822,7 +1817,9 @@ mod tests {
1822
1817
fn notify_payment_path_successful ( & self , path : & [ & RouteHop ] ) {
1823
1818
self . scorer . lock ( ) . payment_path_successful ( path) ;
1824
1819
}
1820
+ }
1825
1821
1822
+ impl ProbingRouter for TestRouter {
1826
1823
fn notify_payment_probe_successful ( & self , path : & [ & RouteHop ] ) {
1827
1824
self . scorer . lock ( ) . probe_successful ( path) ;
1828
1825
}
@@ -1834,7 +1831,7 @@ mod tests {
1834
1831
1835
1832
struct FailingRouter ;
1836
1833
1837
- impl Router for FailingRouter {
1834
+ impl channelmanager :: Router for FailingRouter {
1838
1835
fn find_route (
1839
1836
& self , _payer : & PublicKey , _params : & RouteParameters , _first_hops : Option < & [ & ChannelDetails ] > ,
1840
1837
_inflight_htlcs : InFlightHtlcs ,
@@ -1845,7 +1842,9 @@ mod tests {
1845
1842
fn notify_payment_path_failed ( & self , _path : & [ & RouteHop ] , _short_channel_id : u64 ) { }
1846
1843
1847
1844
fn notify_payment_path_successful ( & self , _path : & [ & RouteHop ] ) { }
1845
+ }
1848
1846
1847
+ impl ProbingRouter for FailingRouter {
1849
1848
fn notify_payment_probe_successful ( & self , _path : & [ & RouteHop ] ) { }
1850
1849
1851
1850
fn notify_payment_probe_failed ( & self , _path : & [ & RouteHop ] , _short_channel_id : u64 ) { }
@@ -2096,7 +2095,7 @@ mod tests {
2096
2095
// *** Full Featured Functional Tests with a Real ChannelManager ***
2097
2096
struct ManualRouter ( RefCell < VecDeque < Result < Route , LightningError > > > ) ;
2098
2097
2099
- impl Router for ManualRouter {
2098
+ impl channelmanager :: Router for ManualRouter {
2100
2099
fn find_route (
2101
2100
& self , _payer : & PublicKey , _params : & RouteParameters , _first_hops : Option < & [ & ChannelDetails ] > ,
2102
2101
_inflight_htlcs : InFlightHtlcs
@@ -2107,7 +2106,8 @@ mod tests {
2107
2106
fn notify_payment_path_failed ( & self , _path : & [ & RouteHop ] , _short_channel_id : u64 ) { }
2108
2107
2109
2108
fn notify_payment_path_successful ( & self , _path : & [ & RouteHop ] ) { }
2110
-
2109
+ }
2110
+ impl ProbingRouter for ManualRouter {
2111
2111
fn notify_payment_probe_successful ( & self , _path : & [ & RouteHop ] ) { }
2112
2112
2113
2113
fn notify_payment_probe_failed ( & self , _path : & [ & RouteHop ] , _short_channel_id : u64 ) { }
0 commit comments