@@ -414,16 +414,20 @@ where
414414mod tests {
415415 use super :: * ;
416416 use crate :: { DEFAULT_EXPIRY_TIME , InvoiceBuilder , Currency } ;
417+ use utils:: create_invoice_from_channelmanager;
417418 use bitcoin_hashes:: sha256:: Hash as Sha256 ;
418419 use lightning:: ln:: PaymentPreimage ;
419- use lightning:: ln:: features:: { ChannelFeatures , NodeFeatures } ;
420+ use lightning:: ln:: features:: { ChannelFeatures , NodeFeatures , InitFeatures } ;
421+ use lightning:: ln:: functional_test_utils:: * ;
420422 use lightning:: ln:: msgs:: { ErrorAction , LightningError } ;
421423 use lightning:: routing:: router:: { Route , RouteHop } ;
422424 use lightning:: util:: test_utils:: TestLogger ;
423425 use lightning:: util:: errors:: APIError ;
424- use lightning:: util:: events:: Event ;
426+ use lightning:: util:: events:: { Event , MessageSendEventsProvider } ;
425427 use secp256k1:: { SecretKey , PublicKey , Secp256k1 } ;
426428 use std:: time:: { SystemTime , Duration } ;
429+ use std:: collections:: LinkedList ;
430+ use std:: sync:: Mutex ;
427431
428432 fn invoice ( payment_preimage : PaymentPreimage ) -> Invoice {
429433 let payment_hash = Sha256 :: hash ( & payment_preimage. 0 ) ;
@@ -1057,4 +1061,72 @@ mod tests {
10571061 }
10581062 }
10591063 }
1064+
1065+ // *** Full Featured Functional Tests with a Real ChannelManager ***
1066+ struct ManualRouter ( Mutex < LinkedList < Result < Route , LightningError > > > ) ;
1067+
1068+ impl Router for ManualRouter {
1069+ fn find_route ( & self , _payer : & PublicKey , _params : & RouteParameters , _first_hops : Option < & [ & ChannelDetails ] > )
1070+ -> Result < Route , LightningError > {
1071+ self . 0 . lock ( ) . unwrap ( ) . pop_front ( ) . unwrap ( )
1072+ }
1073+ }
1074+
1075+ impl Drop for ManualRouter {
1076+ fn drop ( & mut self ) {
1077+ assert ! ( self . 0 . lock( ) . unwrap( ) . is_empty( ) ) ;
1078+ }
1079+ }
1080+
1081+ #[ test]
1082+ fn retry_multi_path_single_failed_payment ( ) {
1083+ // Tests that we can/will retry after a single path of an MPP payment failed immediately
1084+ let chanmon_cfgs = create_chanmon_cfgs ( 2 ) ;
1085+ let node_cfgs = create_node_cfgs ( 2 , & chanmon_cfgs) ;
1086+ let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None , None ] ) ;
1087+ let nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
1088+
1089+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1090+ create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 0 , InitFeatures :: known ( ) , InitFeatures :: known ( ) ) ;
1091+ let chans = nodes[ 0 ] . node . list_usable_channels ( ) ;
1092+ let mut route = Route {
1093+ paths : vec ! [
1094+ vec![ RouteHop {
1095+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
1096+ node_features: NodeFeatures :: known( ) ,
1097+ short_channel_id: chans[ 0 ] . short_channel_id. unwrap( ) ,
1098+ channel_features: ChannelFeatures :: known( ) ,
1099+ fee_msat: 10_000 ,
1100+ cltv_expiry_delta: 100 ,
1101+ } ] ,
1102+ vec![ RouteHop {
1103+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
1104+ node_features: NodeFeatures :: known( ) ,
1105+ short_channel_id: chans[ 1 ] . short_channel_id. unwrap( ) ,
1106+ channel_features: ChannelFeatures :: known( ) ,
1107+ fee_msat: 100_000_001 , // Our default max-HTLC-value is 10% of the channel value
1108+ cltv_expiry_delta: 100 ,
1109+ } ] ,
1110+ ] ,
1111+ payee : Some ( Payee :: new ( nodes[ 1 ] . node . get_our_node_id ( ) ) ) ,
1112+ } ;
1113+ let mut routes = LinkedList :: new ( ) ;
1114+ routes. push_back ( Ok ( route. clone ( ) ) ) ;
1115+ // On retry, split the payment across both channels.
1116+ route. paths [ 0 ] [ 0 ] . fee_msat = 50_000_001 ;
1117+ route. paths [ 1 ] [ 0 ] . fee_msat = 50_000_000 ;
1118+ routes. push_back ( Ok ( route. clone ( ) ) ) ;
1119+ let route_res = ManualRouter ( Mutex :: new ( routes) ) ;
1120+
1121+ let event_handled = core:: cell:: RefCell :: new ( false ) ;
1122+ let event_handler = |_: & _ | { * event_handled. borrow_mut ( ) = true ; } ;
1123+ let invoice_payer = InvoicePayer :: new ( nodes[ 0 ] . node , route_res, nodes[ 0 ] . logger , event_handler, RetryAttempts ( 1 ) ) ;
1124+
1125+ invoice_payer. pay_invoice ( & create_invoice_from_channelmanager (
1126+ & nodes[ 1 ] . node , nodes[ 1 ] . keys_manager , Currency :: Bitcoin , Some ( 100_010_000 ) , "Invoice" . to_string ( ) ) . unwrap ( ) ) . unwrap ( ) ;
1127+ let htlc_msgs = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
1128+ assert_eq ! ( htlc_msgs. len( ) , 2 ) ;
1129+ check_added_monitors ! ( nodes[ 0 ] , 2 ) ;
1130+ assert ! ( !* event_handled. borrow( ) ) ;
1131+ }
10601132}
0 commit comments