@@ -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:: { 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 ;
@@ -104,14 +104,29 @@ impl chaininterface::FeeEstimator for TestFeeEstimator {
104
104
}
105
105
106
106
pub struct TestRouter < ' a > {
107
+ pub router : DefaultRouter <
108
+ Arc < NetworkGraph < & ' a TestLogger > > ,
109
+ & ' a TestLogger ,
110
+ & ' a RwLock < TestScorer > ,
111
+ ( ) ,
112
+ TestScorer ,
113
+ > ,
107
114
pub network_graph : Arc < NetworkGraph < & ' a TestLogger > > ,
108
115
pub next_routes : Mutex < VecDeque < ( RouteParameters , Result < Route , LightningError > ) > > ,
109
116
pub scorer : & ' a RwLock < TestScorer > ,
110
117
}
111
118
112
119
impl < ' 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
+ }
115
130
}
116
131
117
132
pub fn expect_find_route ( & self , query : RouteParameters , result : Result < Route , LightningError > ) {
@@ -185,38 +200,36 @@ impl<'a> Router for TestRouter<'a> {
185
200
}
186
201
return find_route_res;
187
202
}
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)
194
205
}
195
206
196
207
fn create_blinded_payment_paths <
197
208
ES : EntropySource + ?Sized , T : secp256k1:: Signing + secp256k1:: Verification
198
209
> (
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 >
201
212
) -> 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
+ )
203
216
}
204
217
}
205
218
206
219
impl < ' a > MessageRouter for TestRouter < ' a > {
207
220
fn find_path (
208
- & self , _sender : PublicKey , _peers : Vec < PublicKey > , _destination : Destination
221
+ & self , sender : PublicKey , peers : Vec < PublicKey > , destination : Destination
209
222
) -> Result < OnionMessagePath , ( ) > {
210
- unreachable ! ( )
223
+ self . router . find_path ( sender , peers , destination )
211
224
}
212
225
213
226
fn create_blinded_paths <
214
227
ES : EntropySource + ?Sized , T : secp256k1:: Signing + secp256k1:: Verification
215
228
> (
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 >
218
231
) -> Result < Vec < BlindedPath > , ( ) > {
219
- unreachable ! ( )
232
+ self . router . create_blinded_paths ( recipient , peers , entropy_source , secp_ctx )
220
233
}
221
234
}
222
235
0 commit comments