@@ -2258,12 +2258,14 @@ fn auto_retry_partial_failure() {
2258
2258
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
2259
2259
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2260
2260
2261
+ // Open three channels, the first has plenty of liquidity, the second and third have ~no
2262
+ // available liquidity, causing any outbound payments routed over it to fail immediately.
2261
2263
let chan_1_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
2262
- let chan_2_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
2263
- let chan_3_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
2264
+ let chan_2_id = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 989_000_000 ) . 0 . contents . short_channel_id ;
2265
+ let chan_3_id = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 989_000_000 ) . 0 . contents . short_channel_id ;
2264
2266
2265
2267
// Marshall data to send the payment
2266
- let amt_msat = 20_000 ;
2268
+ let amt_msat = 10_000_000 ;
2267
2269
let ( _, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( & nodes[ 0 ] , nodes[ 1 ] , amt_msat) ;
2268
2270
#[ cfg( feature = "std" ) ]
2269
2271
let payment_expiry_secs = SystemTime :: UNIX_EPOCH . elapsed ( ) . unwrap ( ) . as_secs ( ) + 60 * 60 ;
@@ -2278,16 +2280,6 @@ fn auto_retry_partial_failure() {
2278
2280
. with_bolt11_features ( invoice_features) . unwrap ( ) ;
2279
2281
let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, amt_msat) ;
2280
2282
2281
- // Ensure the first monitor update (for the initial send path1 over chan_1) succeeds, but the
2282
- // second (for the initial send path2 over chan_2) fails.
2283
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
2284
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: PermanentFailure ) ;
2285
- // Ensure third monitor update (for the retry1's path1 over chan_1) succeeds, but the fourth (for
2286
- // the retry1's path2 over chan_3) fails, and monitor updates succeed after that.
2287
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
2288
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: PermanentFailure ) ;
2289
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
2290
-
2291
2283
// Configure the initial send, retry1 and retry2's paths.
2292
2284
let send_route = Route {
2293
2285
paths : vec ! [
@@ -2364,32 +2356,23 @@ fn auto_retry_partial_failure() {
2364
2356
// Send a payment that will partially fail on send, then partially fail on retry, then succeed.
2365
2357
nodes[ 0 ] . node . send_payment ( payment_hash, RecipientOnionFields :: secret_only ( payment_secret) ,
2366
2358
PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 3 ) ) . unwrap ( ) ;
2367
- let closed_chan_events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
2368
- assert_eq ! ( closed_chan_events. len( ) , 4 ) ;
2369
- match closed_chan_events[ 0 ] {
2370
- Event :: ChannelClosed { .. } => { } ,
2371
- _ => panic ! ( "Unexpected event" ) ,
2372
- }
2373
- match closed_chan_events[ 1 ] {
2359
+ let payment_failed_events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
2360
+ assert_eq ! ( payment_failed_events. len( ) , 2 ) ;
2361
+ match payment_failed_events[ 0 ] {
2374
2362
Event :: PaymentPathFailed { .. } => { } ,
2375
2363
_ => panic ! ( "Unexpected event" ) ,
2376
2364
}
2377
- match closed_chan_events[ 2 ] {
2378
- Event :: ChannelClosed { .. } => { } ,
2379
- _ => panic ! ( "Unexpected event" ) ,
2380
- }
2381
- match closed_chan_events[ 3 ] {
2365
+ match payment_failed_events[ 1 ] {
2382
2366
Event :: PaymentPathFailed { .. } => { } ,
2383
2367
_ => panic ! ( "Unexpected event" ) ,
2384
2368
}
2385
2369
2386
2370
// Pass the first part of the payment along the path.
2387
- check_added_monitors ! ( nodes[ 0 ] , 5 ) ; // three outbound channel updates succeeded, two permanently failed
2371
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ; // only one HTLC actually made it out
2388
2372
let mut msg_events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
2389
2373
2390
- // First message is the first update_add, remaining messages are broadcasting channel updates and
2391
- // errors for the permfailed channels
2392
- assert_eq ! ( msg_events. len( ) , 5 ) ;
2374
+ // Only one HTLC/channel update actually made it out
2375
+ assert_eq ! ( msg_events. len( ) , 1 ) ;
2393
2376
let mut payment_event = SendEvent :: from_event ( msg_events. remove ( 0 ) ) ;
2394
2377
2395
2378
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
@@ -2478,12 +2461,13 @@ fn auto_retry_zero_attempts_send_error() {
2478
2461
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
2479
2462
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2480
2463
2481
- create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
2482
- create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
2464
+ // Open a single channel that does not have sufficient liquidity for the payment we want to
2465
+ // send.
2466
+ let chan_id = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 989_000_000 ) . 0 . contents . short_channel_id ;
2483
2467
2484
2468
// Marshall data to send the payment
2485
- let amt_msat = 20_000 ;
2486
- let ( _, payment_hash, _ , payment_secret) = get_route_and_payment_hash ! ( & nodes[ 0 ] , nodes [ 1 ] , amt_msat) ;
2469
+ let amt_msat = 10_000_000 ;
2470
+ let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 1 ] , Some ( amt_msat) , None ) ;
2487
2471
#[ cfg( feature = "std" ) ]
2488
2472
let payment_expiry_secs = SystemTime :: UNIX_EPOCH . elapsed ( ) . unwrap ( ) . as_secs ( ) + 60 * 60 ;
2489
2473
#[ cfg( not( feature = "std" ) ) ]
@@ -2497,16 +2481,31 @@ fn auto_retry_zero_attempts_send_error() {
2497
2481
. with_bolt11_features ( invoice_features) . unwrap ( ) ;
2498
2482
let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, amt_msat) ;
2499
2483
2500
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: PermanentFailure ) ;
2484
+ // Override the route search to return a route, rather than failing at the route-finding step.
2485
+ let send_route = Route {
2486
+ paths : vec ! [
2487
+ Path { hops: vec![ RouteHop {
2488
+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
2489
+ node_features: nodes[ 1 ] . node. node_features( ) ,
2490
+ short_channel_id: chan_id,
2491
+ channel_features: nodes[ 1 ] . node. channel_features( ) ,
2492
+ fee_msat: amt_msat,
2493
+ cltv_expiry_delta: 100 ,
2494
+ maybe_announced_channel: true ,
2495
+ } ] , blinded_tail: None } ,
2496
+ ] ,
2497
+ route_params : Some ( route_params. clone ( ) ) ,
2498
+ } ;
2499
+ nodes[ 0 ] . router . expect_find_route ( route_params. clone ( ) , Ok ( send_route) ) ;
2500
+
2501
2501
nodes[ 0 ] . node . send_payment ( payment_hash, RecipientOnionFields :: secret_only ( payment_secret) ,
2502
2502
PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 0 ) ) . unwrap ( ) ;
2503
- assert_eq ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . len ( ) , 2 ) ; // channel close messages
2503
+ assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty ( ) ) ;
2504
2504
let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
2505
- assert_eq ! ( events. len( ) , 3 ) ;
2506
- if let Event :: ChannelClosed { .. } = events[ 0 ] { } else { panic ! ( ) ; }
2507
- if let Event :: PaymentPathFailed { .. } = events[ 1 ] { } else { panic ! ( ) ; }
2508
- if let Event :: PaymentFailed { .. } = events[ 2 ] { } else { panic ! ( ) ; }
2509
- check_added_monitors ! ( nodes[ 0 ] , 2 ) ;
2505
+ assert_eq ! ( events. len( ) , 2 ) ;
2506
+ if let Event :: PaymentPathFailed { .. } = events[ 0 ] { } else { panic ! ( ) ; }
2507
+ if let Event :: PaymentFailed { .. } = events[ 1 ] { } else { panic ! ( ) ; }
2508
+ check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
2510
2509
}
2511
2510
2512
2511
#[ test]
0 commit comments