@@ -250,13 +250,16 @@ fn mpp_retry_overpay() {
250250 let ( mut route, hash, payment_preimage, pay_secret) =
251251 get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 3 ] , payment_params, amt_msat, max_fee) ;
252252
253- // Check we overpay on the second path which we're about to fail.
253+ // Check we overpay on the second path which we're about to fail. Path ordering is not fixed,
254+ // so we identify paths by first-hop pubkey.
254255 assert_eq ! ( chan_1_update. contents. fee_proportional_millionths, 0 ) ;
255- let overpaid_amount_1 = route. paths [ 0 ] . fee_msat ( ) as u32 - chan_1_update. contents . fee_base_msat ;
256+ let path_via_b = route. paths . iter ( ) . find ( |p| p. hops [ 0 ] . pubkey == node_b_id) . unwrap ( ) ;
257+ let overpaid_amount_1 = path_via_b. fee_msat ( ) as u32 - chan_1_update. contents . fee_base_msat ;
256258 assert_eq ! ( overpaid_amount_1, 0 ) ;
257259
258260 assert_eq ! ( chan_2_update. contents. fee_proportional_millionths, 0 ) ;
259- let overpaid_amount_2 = route. paths [ 1 ] . fee_msat ( ) as u32 - chan_2_update. contents . fee_base_msat ;
261+ let path_via_c = route. paths . iter ( ) . find ( |p| p. hops [ 0 ] . pubkey == node_c_id) . unwrap ( ) ;
262+ let overpaid_amount_2 = path_via_c. fee_msat ( ) as u32 - chan_2_update. contents . fee_base_msat ;
260263
261264 let total_overpaid_amount = overpaid_amount_1 + overpaid_amount_2;
262265
@@ -304,11 +307,13 @@ fn mpp_retry_overpay() {
304307 // Rebalance the channel so the second half of the payment can succeed.
305308 send_payment ( & nodes[ 3 ] , & [ & nodes[ 2 ] ] , 38_000_000 ) ;
306309
307- // Retry the second half of the payment and make sure it succeeds.
308- let first_path_value = route. paths [ 0 ] . final_value_msat ( ) ;
310+ // Retry the second half of the payment and make sure it succeeds. Identify the successful
311+ // path (through nodes[1]) by first-hop pubkey, since path ordering is not stable.
312+ let path_via_b_idx = route. paths . iter ( ) . position ( |p| p. hops [ 0 ] . pubkey == node_b_id) . unwrap ( ) ;
313+ let first_path_value = route. paths [ path_via_b_idx] . final_value_msat ( ) ;
309314 assert_eq ! ( first_path_value, 36_000_000 ) ;
310315
311- route. paths . remove ( 0 ) ;
316+ route. paths . remove ( path_via_b_idx ) ;
312317 route_params. final_value_msat -= first_path_value;
313318 let chan_4_scid = chan_4_update. contents . short_channel_id ;
314319 route_params. payment_params . previously_failed_channels . push ( chan_4_scid) ;
@@ -2023,8 +2028,18 @@ fn preflight_probes_yield_event() {
20232028 let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, recv_value) ;
20242029 let res = nodes[ 0 ] . node . send_preflight_probes ( route_params, None ) . unwrap ( ) ;
20252030
2031+ // Path ordering depends on outbound SCID selection. Determine which res entry corresponds
2032+ // to which path by comparing the alias SCIDs of the two channels.
2033+ let node_b_id = nodes[ 1 ] . node . get_our_node_id ( ) ;
2034+ let node_c_id = nodes[ 2 ] . node . get_our_node_id ( ) ;
2035+ let chans = nodes[ 0 ] . node . list_usable_channels ( ) ;
2036+ let chan_to_b = chans. iter ( ) . find ( |c| c. counterparty . node_id == node_b_id) . unwrap ( ) ;
2037+ let chan_to_c = chans. iter ( ) . find ( |c| c. counterparty . node_id == node_c_id) . unwrap ( ) ;
2038+ let b_first = chan_to_b. get_outbound_payment_scid ( ) < chan_to_c. get_outbound_payment_scid ( ) ;
2039+ let ( hash_b, hash_c) = if b_first { ( res[ 0 ] . 0 , res[ 1 ] . 0 ) } else { ( res[ 1 ] . 0 , res[ 0 ] . 0 ) } ;
2040+
20262041 let expected_route: & [ ( & [ & Node ] , PaymentHash ) ] =
2027- & [ ( & [ & nodes[ 1 ] , & nodes[ 3 ] ] , res [ 0 ] . 0 ) , ( & [ & nodes[ 2 ] , & nodes[ 3 ] ] , res [ 1 ] . 0 ) ] ;
2042+ & [ ( & [ & nodes[ 1 ] , & nodes[ 3 ] ] , hash_b ) , ( & [ & nodes[ 2 ] , & nodes[ 3 ] ] , hash_c ) ] ;
20282043
20292044 assert_eq ! ( res. len( ) , expected_route. len( ) ) ;
20302045
@@ -2319,7 +2334,7 @@ fn test_trivial_inflight_htlc_tracking() {
23192334 let chan_1_used_liquidity = inflight_htlcs. used_liquidity_msat (
23202335 & NodeId :: from_pubkey ( & node_a_id) ,
23212336 & NodeId :: from_pubkey ( & node_b_id) ,
2322- channel_1. funding ( ) . get_short_channel_id ( ) . unwrap ( ) ,
2337+ channel_1. context ( ) . outbound_scid_alias ( ) ,
23232338 ) ;
23242339 // First hop accounts for expected 1000 msat fee
23252340 assert_eq ! ( chan_1_used_liquidity, Some ( 501000 ) ) ;
@@ -2429,7 +2444,7 @@ fn test_holding_cell_inflight_htlcs() {
24292444 let used_liquidity = inflight_htlcs. used_liquidity_msat (
24302445 & NodeId :: from_pubkey ( & node_a_id) ,
24312446 & NodeId :: from_pubkey ( & node_b_id) ,
2432- channel. funding ( ) . get_short_channel_id ( ) . unwrap ( ) ,
2447+ channel. context ( ) . outbound_scid_alias ( ) ,
24332448 ) ;
24342449
24352450 assert_eq ! ( used_liquidity, Some ( 2000000 ) ) ;
0 commit comments