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