@@ -35,7 +35,7 @@ use crate::offers::invoice_request::UnsignedInvoiceRequest;
35
35
use crate :: onion_message:: { DefaultMessageRouter , Destination , MessageRouter , OnionMessagePath } ;
36
36
use crate :: routing:: gossip:: { EffectiveCapacity , NetworkGraph , NodeId , RoutingFees } ;
37
37
use 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:: { find_route, DefaultRouter , InFlightHtlcs , Path , Route , RouteParameters , RouteHintHop , Router , ScorerAccountingForInFlightHtlcs } ;
39
39
use crate :: routing:: scoring:: { ChannelUsage , ScoreUpdate , ScoreLookUp } ;
40
40
use crate :: sync:: RwLock ;
41
41
use crate :: util:: config:: UserConfig ;
@@ -103,14 +103,29 @@ impl chaininterface::FeeEstimator for TestFeeEstimator {
103
103
}
104
104
105
105
pub struct TestRouter < ' a > {
106
+ pub router : DefaultRouter <
107
+ Arc < NetworkGraph < & ' a TestLogger > > ,
108
+ & ' a TestLogger ,
109
+ & ' a RwLock < TestScorer > ,
110
+ ( ) ,
111
+ TestScorer ,
112
+ > ,
106
113
pub network_graph : Arc < NetworkGraph < & ' a TestLogger > > ,
107
114
pub next_routes : Mutex < VecDeque < ( RouteParameters , Result < Route , LightningError > ) > > ,
108
115
pub scorer : & ' a RwLock < TestScorer > ,
109
116
}
110
117
111
118
impl < ' a > TestRouter < ' a > {
112
- pub fn new ( network_graph : Arc < NetworkGraph < & ' a TestLogger > > , scorer : & ' a RwLock < TestScorer > ) -> Self {
113
- Self { network_graph, next_routes : Mutex :: new ( VecDeque :: new ( ) ) , scorer }
119
+ pub fn new (
120
+ network_graph : Arc < NetworkGraph < & ' a TestLogger > > , logger : & ' a TestLogger ,
121
+ scorer : & ' a RwLock < TestScorer >
122
+ ) -> Self {
123
+ Self {
124
+ router : DefaultRouter :: new ( network_graph. clone ( ) , logger, [ 42u8 ; 32 ] , scorer, ( ) ) ,
125
+ network_graph,
126
+ next_routes : Mutex :: new ( VecDeque :: new ( ) ) ,
127
+ scorer,
128
+ }
114
129
}
115
130
116
131
pub fn expect_find_route ( & self , query : RouteParameters , result : Result < Route , LightningError > ) {
@@ -184,38 +199,36 @@ impl<'a> Router for TestRouter<'a> {
184
199
}
185
200
return find_route_res;
186
201
}
187
- let logger = TestLogger :: new ( ) ;
188
- find_route (
189
- payer, params, & self . network_graph , first_hops, & logger,
190
- & ScorerAccountingForInFlightHtlcs :: new ( self . scorer . read ( ) . unwrap ( ) , & inflight_htlcs) , & Default :: default ( ) ,
191
- & [ 42 ; 32 ]
192
- )
202
+
203
+ self . router . find_route ( payer, params, first_hops, inflight_htlcs)
193
204
}
194
205
195
206
fn create_blinded_payment_paths <
196
207
ES : EntropySource + ?Sized , T : secp256k1:: Signing + secp256k1:: Verification
197
208
> (
198
- & self , _recipient : PublicKey , _first_hops : Vec < ChannelDetails > , _tlvs : ReceiveTlvs ,
199
- _amount_msats : u64 , _entropy_source : & ES , _secp_ctx : & Secp256k1 < T >
209
+ & self , recipient : PublicKey , first_hops : Vec < ChannelDetails > , tlvs : ReceiveTlvs ,
210
+ amount_msats : u64 , entropy_source : & ES , secp_ctx : & Secp256k1 < T >
200
211
) -> Result < Vec < ( BlindedPayInfo , BlindedPath ) > , ( ) > {
201
- unreachable ! ( )
212
+ self . router . create_blinded_payment_paths (
213
+ recipient, first_hops, tlvs, amount_msats, entropy_source, secp_ctx
214
+ )
202
215
}
203
216
}
204
217
205
218
impl < ' a > MessageRouter for TestRouter < ' a > {
206
219
fn find_path (
207
- & self , _sender : PublicKey , _peers : Vec < PublicKey > , _destination : Destination
220
+ & self , sender : PublicKey , peers : Vec < PublicKey > , destination : Destination
208
221
) -> Result < OnionMessagePath , ( ) > {
209
- unreachable ! ( )
222
+ self . router . find_path ( sender , peers , destination )
210
223
}
211
224
212
225
fn create_blinded_paths <
213
226
ES : EntropySource + ?Sized , T : secp256k1:: Signing + secp256k1:: Verification
214
227
> (
215
- & self , _recipient : PublicKey , _peers : Vec < PublicKey > , _entropy_source : & ES ,
216
- _secp_ctx : & Secp256k1 < T >
228
+ & self , recipient : PublicKey , peers : Vec < PublicKey > , entropy_source : & ES ,
229
+ secp_ctx : & Secp256k1 < T >
217
230
) -> Result < Vec < BlindedPath > , ( ) > {
218
- unreachable ! ( )
231
+ self . router . create_blinded_paths ( recipient , peers , entropy_source , secp_ctx )
219
232
}
220
233
}
221
234
0 commit comments