@@ -247,13 +247,16 @@ fn mpp_retry_overpay() {
247247 let ( mut route, hash, payment_preimage, pay_secret) =
248248 get_route_and_payment_hash ! ( nodes[ 0 ] , nodes[ 3 ] , payment_params, amt_msat, max_fee) ;
249249
250- // Check we overpay on the second path which we're about to fail.
250+ // Check we overpay on the second path which we're about to fail. Path ordering is determined
251+ // by alias SCID sort and is not stable, so we identify paths by first-hop pubkey.
251252 assert_eq ! ( chan_1_update. contents. fee_proportional_millionths, 0 ) ;
252- let overpaid_amount_1 = route. paths [ 0 ] . fee_msat ( ) as u32 - chan_1_update. contents . fee_base_msat ;
253+ let path_via_b = route. paths . iter ( ) . find ( |p| p. hops [ 0 ] . pubkey == node_b_id) . unwrap ( ) ;
254+ let overpaid_amount_1 = path_via_b. fee_msat ( ) as u32 - chan_1_update. contents . fee_base_msat ;
253255 assert_eq ! ( overpaid_amount_1, 0 ) ;
254256
255257 assert_eq ! ( chan_2_update. contents. fee_proportional_millionths, 0 ) ;
256- let overpaid_amount_2 = route. paths [ 1 ] . fee_msat ( ) as u32 - chan_2_update. contents . fee_base_msat ;
258+ let path_via_c = route. paths . iter ( ) . find ( |p| p. hops [ 0 ] . pubkey == node_c_id) . unwrap ( ) ;
259+ let overpaid_amount_2 = path_via_c. fee_msat ( ) as u32 - chan_2_update. contents . fee_base_msat ;
257260
258261 let total_overpaid_amount = overpaid_amount_1 + overpaid_amount_2;
259262
@@ -301,11 +304,13 @@ fn mpp_retry_overpay() {
301304 // Rebalance the channel so the second half of the payment can succeed.
302305 send_payment ( & nodes[ 3 ] , & [ & nodes[ 2 ] ] , 38_000_000 ) ;
303306
304- // Retry the second half of the payment and make sure it succeeds.
305- let first_path_value = route. paths [ 0 ] . final_value_msat ( ) ;
307+ // Retry the second half of the payment and make sure it succeeds. Identify the successful
308+ // path (through nodes[1]) by first-hop pubkey, since path ordering is not stable.
309+ let path_via_b_idx = route. paths . iter ( ) . position ( |p| p. hops [ 0 ] . pubkey == node_b_id) . unwrap ( ) ;
310+ let first_path_value = route. paths [ path_via_b_idx] . final_value_msat ( ) ;
306311 assert_eq ! ( first_path_value, 36_000_000 ) ;
307312
308- route. paths . remove ( 0 ) ;
313+ route. paths . remove ( path_via_b_idx ) ;
309314 route_params. final_value_msat -= first_path_value;
310315 let chan_4_scid = chan_4_update. contents . short_channel_id ;
311316 route_params. payment_params . previously_failed_channels . push ( chan_4_scid) ;
@@ -1790,8 +1795,18 @@ fn preflight_probes_yield_event() {
17901795 let route_params = RouteParameters :: from_payment_params_and_value ( payment_params, recv_value) ;
17911796 let res = nodes[ 0 ] . node . send_preflight_probes ( route_params, None ) . unwrap ( ) ;
17921797
1798+ // Path order in route.paths is by alias SCID (ascending). Determine which res entry
1799+ // corresponds to which path by comparing alias SCIDs.
1800+ let node_b_id = nodes[ 1 ] . node . get_our_node_id ( ) ;
1801+ let node_c_id = nodes[ 2 ] . node . get_our_node_id ( ) ;
1802+ let chans = nodes[ 0 ] . node . list_usable_channels ( ) ;
1803+ let chan_to_b = chans. iter ( ) . find ( |c| c. counterparty . node_id == node_b_id) . unwrap ( ) ;
1804+ let chan_to_c = chans. iter ( ) . find ( |c| c. counterparty . node_id == node_c_id) . unwrap ( ) ;
1805+ let b_first = chan_to_b. get_outbound_payment_scid ( ) < chan_to_c. get_outbound_payment_scid ( ) ;
1806+ let ( hash_b, hash_c) = if b_first { ( res[ 0 ] . 0 , res[ 1 ] . 0 ) } else { ( res[ 1 ] . 0 , res[ 0 ] . 0 ) } ;
1807+
17931808 let expected_route: & [ ( & [ & Node ] , PaymentHash ) ] =
1794- & [ ( & [ & nodes[ 1 ] , & nodes[ 3 ] ] , res [ 0 ] . 0 ) , ( & [ & nodes[ 2 ] , & nodes[ 3 ] ] , res [ 1 ] . 0 ) ] ;
1809+ & [ ( & [ & nodes[ 1 ] , & nodes[ 3 ] ] , hash_b ) , ( & [ & nodes[ 2 ] , & nodes[ 3 ] ] , hash_c ) ] ;
17951810
17961811 assert_eq ! ( res. len( ) , expected_route. len( ) ) ;
17971812
@@ -2086,7 +2101,7 @@ fn test_trivial_inflight_htlc_tracking() {
20862101 let chan_1_used_liquidity = inflight_htlcs. used_liquidity_msat (
20872102 & NodeId :: from_pubkey ( & node_a_id) ,
20882103 & NodeId :: from_pubkey ( & node_b_id) ,
2089- channel_1. funding ( ) . get_short_channel_id ( ) . unwrap ( ) ,
2104+ channel_1. context ( ) . outbound_scid_alias ( ) ,
20902105 ) ;
20912106 // First hop accounts for expected 1000 msat fee
20922107 assert_eq ! ( chan_1_used_liquidity, Some ( 501000 ) ) ;
@@ -2191,7 +2206,7 @@ fn test_holding_cell_inflight_htlcs() {
21912206 let used_liquidity = inflight_htlcs. used_liquidity_msat (
21922207 & NodeId :: from_pubkey ( & node_a_id) ,
21932208 & NodeId :: from_pubkey ( & node_b_id) ,
2194- channel. funding ( ) . get_short_channel_id ( ) . unwrap ( ) ,
2209+ channel. context ( ) . outbound_scid_alias ( ) ,
21952210 ) ;
21962211
21972212 assert_eq ! ( used_liquidity, Some ( 2000000 ) ) ;
0 commit comments