@@ -2161,12 +2161,14 @@ fn auto_retry_partial_failure() {
2161
2161
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
2162
2162
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2163
2163
2164
+ // Open three channels, the first has plenty of liquidity, the second and third have ~no
2165
+ // available liquidity, causing any outbound payments routed over it to fail immediately.
2164
2166
let chan_1_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
2165
- let chan_2_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
2166
- let chan_3_id = create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
2167
+ 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 ;
2168
+ 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 ;
2167
2169
2168
2170
// Marshall data to send the payment
2169
- let amt_msat = 20_000 ;
2171
+ let amt_msat = 10_000_000 ;
2170
2172
let ( _, payment_hash, payment_preimage, payment_secret) = get_route_and_payment_hash ! ( & nodes[ 0 ] , nodes[ 1 ] , amt_msat) ;
2171
2173
#[ cfg( feature = "std" ) ]
2172
2174
let payment_expiry_secs = SystemTime :: UNIX_EPOCH . elapsed ( ) . unwrap ( ) . as_secs ( ) + 60 * 60 ;
@@ -2181,16 +2183,6 @@ fn auto_retry_partial_failure() {
2181
2183
. with_bolt11_features ( invoice_features) . unwrap ( ) ;
2182
2184
let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, amt_msat) ;
2183
2185
2184
- // Ensure the first monitor update (for the initial send path1 over chan_1) succeeds, but the
2185
- // second (for the initial send path2 over chan_2) fails.
2186
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
2187
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: PermanentFailure ) ;
2188
- // Ensure third monitor update (for the retry1's path1 over chan_1) succeeds, but the fourth (for
2189
- // the retry1's path2 over chan_3) fails, and monitor updates succeed after that.
2190
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
2191
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: PermanentFailure ) ;
2192
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: Completed ) ;
2193
-
2194
2186
// Configure the initial send, retry1 and retry2's paths.
2195
2187
let send_route = Route {
2196
2188
paths : vec ! [
@@ -2263,31 +2255,23 @@ fn auto_retry_partial_failure() {
2263
2255
nodes[ 0 ] . node . send_payment ( payment_hash, RecipientOnionFields :: secret_only ( payment_secret) ,
2264
2256
PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 3 ) ) . unwrap ( ) ;
2265
2257
let closed_chan_events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
2266
- assert_eq ! ( closed_chan_events. len( ) , 4 ) ;
2258
+ assert_eq ! ( closed_chan_events. len( ) , 2 ) ;
2267
2259
match closed_chan_events[ 0 ] {
2268
- Event :: ChannelClosed { .. } => { } ,
2269
- _ => panic ! ( "Unexpected event" ) ,
2270
- }
2271
- match closed_chan_events[ 1 ] {
2272
2260
Event :: PaymentPathFailed { .. } => { } ,
2273
2261
_ => panic ! ( "Unexpected event" ) ,
2274
2262
}
2275
- match closed_chan_events[ 2 ] {
2276
- Event :: ChannelClosed { .. } => { } ,
2277
- _ => panic ! ( "Unexpected event" ) ,
2278
- }
2279
- match closed_chan_events[ 3 ] {
2263
+ match closed_chan_events[ 1 ] {
2280
2264
Event :: PaymentPathFailed { .. } => { } ,
2281
2265
_ => panic ! ( "Unexpected event" ) ,
2282
2266
}
2283
2267
2284
2268
// Pass the first part of the payment along the path.
2285
- check_added_monitors ! ( nodes[ 0 ] , 5 ) ; // three outbound channel updates succeeded, two permanently failed
2269
+ check_added_monitors ! ( nodes[ 0 ] , 1 ) ; // three outbound channel updates succeeded, two permanently failed
2286
2270
let mut msg_events = nodes[ 0 ] . node . get_and_clear_pending_msg_events ( ) ;
2287
2271
2288
2272
// First message is the first update_add, remaining messages are broadcasting channel updates and
2289
2273
// errors for the permfailed channels
2290
- assert_eq ! ( msg_events. len( ) , 5 ) ;
2274
+ assert_eq ! ( msg_events. len( ) , 1 ) ;
2291
2275
let mut payment_event = SendEvent :: from_event ( msg_events. remove ( 0 ) ) ;
2292
2276
2293
2277
nodes[ 1 ] . node . handle_update_add_htlc ( & nodes[ 0 ] . node . get_our_node_id ( ) , & payment_event. msgs [ 0 ] ) ;
@@ -2376,12 +2360,13 @@ fn auto_retry_zero_attempts_send_error() {
2376
2360
let node_chanmgrs = create_node_chanmgrs ( 2 , & node_cfgs, & [ None , None ] ) ;
2377
2361
let mut nodes = create_network ( 2 , & node_cfgs, & node_chanmgrs) ;
2378
2362
2379
- create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
2380
- create_announced_chan_between_nodes ( & nodes, 0 , 1 ) . 0 . contents . short_channel_id ;
2363
+ // Open a single channel that does not have sufficient liquidity for the payment we want to
2364
+ // send.
2365
+ let chan_id = create_announced_chan_between_nodes_with_value ( & nodes, 0 , 1 , 1_000_000 , 989_000_000 ) . 0 . contents . short_channel_id ;
2381
2366
2382
2367
// Marshall data to send the payment
2383
- let amt_msat = 20_000 ;
2384
- let ( _, payment_hash, _ , payment_secret) = get_route_and_payment_hash ! ( & nodes[ 0 ] , nodes [ 1 ] , amt_msat) ;
2368
+ let amt_msat = 10_000_000 ;
2369
+ let ( _, payment_hash, payment_secret) = get_payment_preimage_hash ( & nodes[ 1 ] , Some ( amt_msat) , None ) ;
2385
2370
#[ cfg( feature = "std" ) ]
2386
2371
let payment_expiry_secs = SystemTime :: UNIX_EPOCH . elapsed ( ) . unwrap ( ) . as_secs ( ) + 60 * 60 ;
2387
2372
#[ cfg( not( feature = "std" ) ) ]
@@ -2395,16 +2380,30 @@ fn auto_retry_zero_attempts_send_error() {
2395
2380
. with_bolt11_features ( invoice_features) . unwrap ( ) ;
2396
2381
let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, amt_msat) ;
2397
2382
2398
- chanmon_cfgs[ 0 ] . persister . set_update_ret ( ChannelMonitorUpdateStatus :: PermanentFailure ) ;
2383
+ // Override the route search to return a route, rather than failing at the route-finding step.
2384
+ let send_route = Route {
2385
+ paths : vec ! [
2386
+ Path { hops: vec![ RouteHop {
2387
+ pubkey: nodes[ 1 ] . node. get_our_node_id( ) ,
2388
+ node_features: nodes[ 1 ] . node. node_features( ) ,
2389
+ short_channel_id: chan_id,
2390
+ channel_features: nodes[ 1 ] . node. channel_features( ) ,
2391
+ fee_msat: amt_msat,
2392
+ cltv_expiry_delta: 100 ,
2393
+ } ] , blinded_tail: None } ,
2394
+ ] ,
2395
+ route_params : Some ( route_params. clone ( ) ) ,
2396
+ } ;
2397
+ nodes[ 0 ] . router . expect_find_route ( route_params. clone ( ) , Ok ( send_route) ) ;
2398
+
2399
2399
nodes[ 0 ] . node . send_payment ( payment_hash, RecipientOnionFields :: secret_only ( payment_secret) ,
2400
2400
PaymentId ( payment_hash. 0 ) , route_params, Retry :: Attempts ( 0 ) ) . unwrap ( ) ;
2401
- assert_eq ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . len ( ) , 2 ) ; // channel close messages
2401
+ assert ! ( nodes[ 0 ] . node. get_and_clear_pending_msg_events( ) . is_empty ( ) ) ;
2402
2402
let events = nodes[ 0 ] . node . get_and_clear_pending_events ( ) ;
2403
- assert_eq ! ( events. len( ) , 3 ) ;
2404
- if let Event :: ChannelClosed { .. } = events[ 0 ] { } else { panic ! ( ) ; }
2405
- if let Event :: PaymentPathFailed { .. } = events[ 1 ] { } else { panic ! ( ) ; }
2406
- if let Event :: PaymentFailed { .. } = events[ 2 ] { } else { panic ! ( ) ; }
2407
- check_added_monitors ! ( nodes[ 0 ] , 2 ) ;
2403
+ assert_eq ! ( events. len( ) , 2 ) ;
2404
+ if let Event :: PaymentPathFailed { .. } = events[ 0 ] { } else { panic ! ( ) ; }
2405
+ if let Event :: PaymentFailed { .. } = events[ 1 ] { } else { panic ! ( ) ; }
2406
+ check_added_monitors ! ( nodes[ 0 ] , 0 ) ;
2408
2407
}
2409
2408
2410
2409
#[ test]
0 commit comments