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