@@ -447,18 +447,22 @@ where
447
447
mod tests {
448
448
use super :: * ;
449
449
use crate :: { DEFAULT_EXPIRY_TIME , InvoiceBuilder , Currency } ;
450
+ use utils:: create_invoice_from_channelmanager;
450
451
use bitcoin_hashes:: sha256:: Hash as Sha256 ;
451
452
use lightning:: ln:: PaymentPreimage ;
452
- use lightning:: ln:: features:: { ChannelFeatures , NodeFeatures } ;
453
+ use lightning:: ln:: features:: { ChannelFeatures , NodeFeatures , InitFeatures } ;
454
+ use lightning:: ln:: functional_test_utils:: * ;
453
455
use lightning:: ln:: msgs:: { ErrorAction , LightningError } ;
454
456
use lightning:: routing:: network_graph:: NodeId ;
455
457
use lightning:: routing:: router:: { Payee , Route , RouteHop } ;
456
458
use lightning:: util:: test_utils:: TestLogger ;
457
459
use lightning:: util:: errors:: APIError ;
458
- use lightning:: util:: events:: Event ;
460
+ use lightning:: util:: events:: { Event , MessageSendEventsProvider } ;
459
461
use secp256k1:: { SecretKey , PublicKey , Secp256k1 } ;
460
462
use std:: cell:: RefCell ;
461
463
use std:: time:: { SystemTime , Duration } ;
464
+ use std:: collections:: LinkedList ;
465
+ use std:: sync:: Mutex ;
462
466
463
467
fn invoice ( payment_preimage : PaymentPreimage ) -> Invoice {
464
468
let payment_hash = Sha256 :: hash ( & payment_preimage. 0 ) ;
@@ -1182,4 +1186,72 @@ mod tests {
1182
1186
}
1183
1187
}
1184
1188
}
1189
+
1190
+ // *** Full Featured Functional Tests with a Real ChannelManager ***
1191
+ struct ManualRouter ( Mutex < LinkedList < Result < Route , LightningError > > > ) ;
1192
+
1193
+ impl Router for ManualRouter {
1194
+ fn find_route ( & self , _payer : & PublicKey , _params : & RouteParameters , _first_hops : Option < & [ & ChannelDetails ] > )
1195
+ -> Result < Route , LightningError > {
1196
+ self . 0 . lock ( ) . unwrap ( ) . pop_front ( ) . unwrap ( )
1197
+ }
1198
+ }
1199
+
1200
+ impl Drop for ManualRouter {
1201
+ fn drop ( & mut self ) {
1202
+ assert ! ( self . 0 . lock( ) . unwrap( ) . is_empty( ) ) ;
1203
+ }
1204
+ }
1205
+
1206
+ #[ test]
1207
+ fn retry_multi_path_single_failed_payment ( ) {
1208
+ // Tests that we can/will retry after a single path of an MPP payment failed immediately
1209
+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1210
+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1211
+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None , None ] ) ;
1212
+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1213
+
1214
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1215
+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1216
+ let chans = nodes[ 0 ] . node . list_usable_channels ( ) ;
1217
+ let mut route = Route {
1218
+ paths : vec ! [
1219
+ vec![ RouteHop {
1220
+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
1221
+ node_features: NodeFeatures :: known( ) ,
1222
+ short_channel_id: chans[ 0 ] . short_channel_id. unwrap( ) ,
1223
+ channel_features: ChannelFeatures :: known( ) ,
1224
+ fee_msat: 10_000 ,
1225
+ cltv_expiry_delta: 100 ,
1226
+ } ] ,
1227
+ vec![ RouteHop {
1228
+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
1229
+ node_features: NodeFeatures :: known( ) ,
1230
+ short_channel_id: chans[ 1 ] . short_channel_id. unwrap( ) ,
1231
+ channel_features: ChannelFeatures :: known( ) ,
1232
+ fee_msat: 100_000_001 , // Our default max-HTLC-value is 10% of the channel value
1233
+ cltv_expiry_delta: 100 ,
1234
+ } ] ,
1235
+ ] ,
1236
+ payee : Some ( Payee :: new ( nodes[ 1 ] . node . get_our_node_id ( ) ) ) ,
1237
+ } ;
1238
+ let mut routes = LinkedList :: new ( ) ;
1239
+ routes. push_back ( Ok ( route. clone ( ) ) ) ;
1240
+ // On retry, split the payment across both channels.
1241
+ route. paths [ 0 ] [ 0 ] . fee_msat = 50_000_001 ;
1242
+ route. paths [ 1 ] [ 0 ] . fee_msat = 50_000_000 ;
1243
+ routes. push_back ( Ok ( route. clone ( ) ) ) ;
1244
+ let route_res = ManualRouter ( Mutex :: new ( routes) ) ;
1245
+
1246
+ let event_handled = core:: cell:: RefCell :: new ( false ) ;
1247
+ let event_handler = |_: & _ | { * event_handled. borrow_mut ( ) = true ; } ;
1248
+ let invoice_payer = InvoicePayer :: new ( nodes[ 0 ] . node , route_res, nodes[ 0 ] . logger , event_handler, RetryAttempts ( 1 ) ) ;
1249
+
1250
+ invoice_payer. pay_invoice ( & create_invoice_from_channelmanager (
1251
+ & nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , Currency :: Bitcoin , Some ( 100_010_000 ) , "Invoice" . to_string ( ) ) . unwrap ( ) ) . unwrap ( ) ;
1252
+ let htlc_msgs = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
1253
+ assert_eq ! ( htlc_msgs. len( ) , 2 ) ;
1254
+ check_added_monitors ! ( nodes[ 0 ] , 2 ) ;
1255
+ assert ! ( !* event_handled. borrow( ) ) ;
1256
+ }
1185
1257
}
0 commit comments