@@ -35,7 +35,7 @@ use crate::offers::invoice_request::UnsignedInvoiceRequest;
3535use crate :: onion_message:: { DefaultMessageRouter , Destination , MessageRouter , OnionMessagePath } ;
3636use crate :: routing:: gossip:: { EffectiveCapacity , NetworkGraph , NodeId , RoutingFees } ;
3737use crate :: routing:: utxo:: { UtxoLookup , UtxoLookupError , UtxoResult } ;
38- use crate :: routing:: router:: { find_route , InFlightHtlcs , Path , Route , RouteParameters , RouteHintHop , Router , ScorerAccountingForInFlightHtlcs } ;
38+ use crate :: routing:: router:: { DefaultRouter , InFlightHtlcs , Path , Route , RouteParameters , RouteHintHop , Router , ScorerAccountingForInFlightHtlcs } ;
3939use crate :: routing:: scoring:: { ChannelUsage , ScoreUpdate , ScoreLookUp } ;
4040use crate :: sync:: RwLock ;
4141use crate :: util:: config:: UserConfig ;
@@ -104,14 +104,29 @@ impl chaininterface::FeeEstimator for TestFeeEstimator {
104104}
105105
106106pub struct TestRouter < ' a > {
107+ pub router : DefaultRouter <
108+ Arc < NetworkGraph < & ' a TestLogger > > ,
109+ & ' a TestLogger ,
110+ & ' a RwLock < TestScorer > ,
111+ ( ) ,
112+ TestScorer ,
113+ > ,
107114 pub network_graph : Arc < NetworkGraph < & ' a TestLogger > > ,
108115 pub next_routes : Mutex < VecDeque < ( RouteParameters , Result < Route , LightningError > ) > > ,
109116 pub scorer : & ' a RwLock < TestScorer > ,
110117}
111118
112119impl < ' a > TestRouter < ' a > {
113- pub fn new ( network_graph : Arc < NetworkGraph < & ' a TestLogger > > , scorer : & ' a RwLock < TestScorer > ) -> Self {
114- Self { network_graph, next_routes : Mutex :: new ( VecDeque :: new ( ) ) , scorer }
120+ pub fn new (
121+ network_graph : Arc < NetworkGraph < & ' a TestLogger > > , logger : & ' a TestLogger ,
122+ scorer : & ' a RwLock < TestScorer >
123+ ) -> Self {
124+ Self {
125+ router : DefaultRouter :: new ( network_graph. clone ( ) , logger, [ 42u8 ; 32 ] , scorer, ( ) ) ,
126+ network_graph,
127+ next_routes : Mutex :: new ( VecDeque :: new ( ) ) ,
128+ scorer,
129+ }
115130 }
116131
117132 pub fn expect_find_route ( & self , query : RouteParameters , result : Result < Route , LightningError > ) {
@@ -185,38 +200,36 @@ impl<'a> Router for TestRouter<'a> {
185200 }
186201 return find_route_res;
187202 }
188- let logger = TestLogger :: new ( ) ;
189- find_route (
190- payer, params, & self . network_graph , first_hops, & logger,
191- & ScorerAccountingForInFlightHtlcs :: new ( self . scorer . read ( ) . unwrap ( ) , & inflight_htlcs) , & Default :: default ( ) ,
192- & [ 42 ; 32 ]
193- )
203+
204+ self . router . find_route ( payer, params, first_hops, inflight_htlcs)
194205 }
195206
196207 fn create_blinded_payment_paths <
197208 ES : EntropySource + ?Sized , T : secp256k1:: Signing + secp256k1:: Verification
198209 > (
199- & self , _recipient : PublicKey , _first_hops : Vec < ChannelDetails > , _tlvs : ReceiveTlvs ,
200- _amount_msats : u64 , _entropy_source : & ES , _secp_ctx : & Secp256k1 < T >
210+ & self , recipient : PublicKey , first_hops : Vec < ChannelDetails > , tlvs : ReceiveTlvs ,
211+ amount_msats : u64 , entropy_source : & ES , secp_ctx : & Secp256k1 < T >
201212 ) -> Result < Vec < ( BlindedPayInfo , BlindedPath ) > , ( ) > {
202- unreachable ! ( )
213+ self . router . create_blinded_payment_paths (
214+ recipient, first_hops, tlvs, amount_msats, entropy_source, secp_ctx
215+ )
203216 }
204217}
205218
206219impl < ' a > MessageRouter for TestRouter < ' a > {
207220 fn find_path (
208- & self , _sender : PublicKey , _peers : Vec < PublicKey > , _destination : Destination
221+ & self , sender : PublicKey , peers : Vec < PublicKey > , destination : Destination
209222 ) -> Result < OnionMessagePath , ( ) > {
210- unreachable ! ( )
223+ self . router . find_path ( sender , peers , destination )
211224 }
212225
213226 fn create_blinded_paths <
214227 ES : EntropySource + ?Sized , T : secp256k1:: Signing + secp256k1:: Verification
215228 > (
216- & self , _recipient : PublicKey , _peers : Vec < PublicKey > , _entropy_source : & ES ,
217- _secp_ctx : & Secp256k1 < T >
229+ & self , recipient : PublicKey , peers : Vec < PublicKey > , entropy_source : & ES ,
230+ secp_ctx : & Secp256k1 < T >
218231 ) -> Result < Vec < BlindedPath > , ( ) > {
219- unreachable ! ( )
232+ self . router . create_blinded_paths ( recipient , peers , entropy_source , secp_ctx )
220233 }
221234}
222235
0 commit comments