@@ -1052,8 +1052,6 @@ pub enum CandidateRouteHop<'a> {
1052
1052
/// Provided to uniquely identify a hop as we are
1053
1053
/// route building.
1054
1054
hint_idx : usize ,
1055
- /// The node id of the payer.
1056
- source_node_id : NodeId ,
1057
1055
} ,
1058
1056
/// Similar to [`Self::Blinded`], but the path here has 1 blinded hop. `BlindedPayInfo` provided
1059
1057
/// for 1-hop blinded paths is ignored because it is meant to apply to the hops *between* the
@@ -1069,8 +1067,6 @@ pub enum CandidateRouteHop<'a> {
1069
1067
/// Provided to uniquely identify a hop as we are
1070
1068
/// route building.
1071
1069
hint_idx : usize ,
1072
- /// The node id of the payer.
1073
- source_node_id : NodeId ,
1074
1070
} ,
1075
1071
}
1076
1072
@@ -1183,8 +1179,8 @@ impl<'a> CandidateRouteHop<'a> {
1183
1179
* source_node_id
1184
1180
} ,
1185
1181
CandidateRouteHop :: PrivateHop { hint, .. } => hint. src_node_id . into ( ) ,
1186
- CandidateRouteHop :: Blinded { source_node_id , .. } => * source_node_id ,
1187
- CandidateRouteHop :: OneHopBlinded { source_node_id , .. } => * source_node_id ,
1182
+ CandidateRouteHop :: Blinded { hint , .. } => hint . 1 . introduction_node_id . into ( ) ,
1183
+ CandidateRouteHop :: OneHopBlinded { hint , .. } => hint . 1 . introduction_node_id . into ( ) ,
1188
1184
}
1189
1185
}
1190
1186
/// Returns the target node id of this hop, if known.
@@ -1249,7 +1245,7 @@ fn iter_equal<I1: Iterator, I2: Iterator>(mut iter_a: I1, mut iter_b: I2)
1249
1245
pub struct PathBuildingHop < ' a > {
1250
1246
// Note that this should be dropped in favor of loading it from CandidateRouteHop, but doing so
1251
1247
// is a larger refactor and will require careful performance analysis.
1252
- node_id : NodeId ,
1248
+ // node_id: NodeId,
1253
1249
candidate : CandidateRouteHop < ' a > ,
1254
1250
fee_msat : u64 ,
1255
1251
@@ -1287,7 +1283,7 @@ impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
1287
1283
fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
1288
1284
let mut debug_struct = f. debug_struct ( "PathBuildingHop" ) ;
1289
1285
debug_struct
1290
- . field ( "node_id" , & self . node_id )
1286
+ . field ( "node_id" , & self . candidate . source ( ) )
1291
1287
. field ( "short_channel_id" , & self . candidate . short_channel_id ( ) )
1292
1288
. field ( "total_fee_msat" , & self . total_fee_msat )
1293
1289
. field ( "next_hops_fee_msat" , & self . next_hops_fee_msat )
@@ -1940,7 +1936,7 @@ where L::Target: Logger {
1940
1936
// This will affect our decision on selecting short_channel_id
1941
1937
// as a way to reach the $dest_node_id.
1942
1938
PathBuildingHop {
1943
- node_id: $dest_node_id. clone( ) ,
1939
+ // node_id: $dest_node_id.clone(),
1944
1940
candidate: $candidate. clone( ) ,
1945
1941
fee_msat: 0 ,
1946
1942
next_hops_fee_msat: u64 :: max_value( ) ,
@@ -2030,7 +2026,6 @@ where L::Target: Logger {
2030
2026
old_entry. next_hops_fee_msat = $next_hops_fee_msat;
2031
2027
old_entry. hop_use_fee_msat = hop_use_fee_msat;
2032
2028
old_entry. total_fee_msat = total_fee_msat;
2033
- old_entry. node_id = $dest_node_id. clone( ) ;
2034
2029
old_entry. candidate = $candidate. clone( ) ;
2035
2030
old_entry. fee_msat = 0 ; // This value will be later filled with hop_use_fee_msat of the following channel
2036
2031
old_entry. path_htlc_minimum_msat = path_htlc_minimum_msat;
@@ -2203,8 +2198,8 @@ where L::Target: Logger {
2203
2198
network_nodes. get ( & intro_node_id) . is_some ( ) ;
2204
2199
if !have_intro_node_in_graph || our_node_id == intro_node_id { continue }
2205
2200
let candidate = if hint. 1 . blinded_hops . len ( ) == 1 {
2206
- CandidateRouteHop :: OneHopBlinded { hint, hint_idx, source_node_id : our_node_id }
2207
- } else { CandidateRouteHop :: Blinded { hint, hint_idx, source_node_id : intro_node_id } } ;
2201
+ CandidateRouteHop :: OneHopBlinded { hint, hint_idx }
2202
+ } else { CandidateRouteHop :: Blinded { hint, hint_idx } } ;
2208
2203
let mut path_contribution_msat = path_value_msat;
2209
2204
if let Some ( hop_used_msat) = add_entry ! ( & candidate, intro_node_id, maybe_dummy_payee_node_id,
2210
2205
0 , path_contribution_msat, 0 , 0_u64 , 0 , 0 )
@@ -2400,7 +2395,11 @@ where L::Target: Logger {
2400
2395
2401
2396
' path_walk: loop {
2402
2397
let mut features_set = false ;
2403
- if let Some ( first_channels) = first_hop_targets. get ( & ordered_hops. last ( ) . unwrap ( ) . 0 . node_id ) {
2398
+ let target = match ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) {
2399
+ Some ( target) => target,
2400
+ None => break ,
2401
+ } ;
2402
+ if let Some ( first_channels) = first_hop_targets. get ( & target) {
2404
2403
for details in first_channels {
2405
2404
if let Some ( scid) = ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . short_channel_id ( ) {
2406
2405
if details. get_outbound_payment_scid ( ) . unwrap ( ) == scid {
@@ -2412,7 +2411,7 @@ where L::Target: Logger {
2412
2411
}
2413
2412
}
2414
2413
if !features_set {
2415
- if let Some ( node) = network_nodes. get ( & ordered_hops. last ( ) . unwrap ( ) . 0 . node_id ) {
2414
+ if let Some ( node) = network_nodes. get ( & ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) . unwrap ( ) ) {
2416
2415
if let Some ( node_info) = node. announcement_info . as_ref ( ) {
2417
2416
ordered_hops. last_mut ( ) . unwrap ( ) . 1 = node_info. features . clone ( ) ;
2418
2417
} else {
@@ -2429,11 +2428,11 @@ where L::Target: Logger {
2429
2428
// save this path for the payment route. Also, update the liquidity
2430
2429
// remaining on the used hops, so that we take them into account
2431
2430
// while looking for more paths.
2432
- if ordered_hops. last ( ) . unwrap ( ) . 0 . node_id == maybe_dummy_payee_node_id {
2431
+ if ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) . unwrap ( ) == maybe_dummy_payee_node_id {
2433
2432
break ' path_walk;
2434
2433
}
2435
2434
2436
- new_entry = match dist. remove ( & ordered_hops. last ( ) . unwrap ( ) . 0 . node_id ) {
2435
+ new_entry = match dist. remove ( & ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) . unwrap ( ) ) {
2437
2436
Some ( payment_hop) => payment_hop,
2438
2437
// We can't arrive at None because, if we ever add an entry to targets,
2439
2438
// we also fill in the entry in dist (see add_entry!).
@@ -2472,12 +2471,16 @@ where L::Target: Logger {
2472
2471
// Remember that we used these channels so that we don't rely
2473
2472
// on the same liquidity in future paths.
2474
2473
let mut prevented_redundant_path_selection = false ;
2475
- let prev_hop_iter = core:: iter:: once ( & our_node_id)
2476
- . chain ( payment_path. hops . iter ( ) . map ( |( hop, _) | & hop. node_id ) ) ;
2474
+ let prev_hop_iter = core:: iter:: once ( our_node_id)
2475
+ . chain ( payment_path. hops . iter ( ) . map ( |( hop, _) | hop. candidate . target ( ) . unwrap ( ) ) ) ;
2477
2476
for ( prev_hop, ( hop, _) ) in prev_hop_iter. zip ( payment_path. hops . iter ( ) ) {
2477
+ let target = match hop. candidate . target ( ) {
2478
+ Some ( target) => target,
2479
+ None => break ,
2480
+ } ;
2478
2481
let spent_on_hop_msat = value_contribution_msat + hop. next_hops_fee_msat ;
2479
2482
let used_liquidity_msat = used_liquidities
2480
- . entry ( hop. candidate . id ( * prev_hop < hop . node_id ) )
2483
+ . entry ( hop. candidate . id ( prev_hop < target ) )
2481
2484
. and_modify ( |used_liquidity_msat| * used_liquidity_msat += spent_on_hop_msat)
2482
2485
. or_insert ( spent_on_hop_msat) ;
2483
2486
let hop_capacity = hop. candidate . effective_capacity ( ) ;
@@ -2652,8 +2655,8 @@ where L::Target: Logger {
2652
2655
} ) ;
2653
2656
for idx in 0 ..( selected_route. len ( ) - 1 ) {
2654
2657
if idx + 1 >= selected_route. len ( ) { break ; }
2655
- if iter_equal ( selected_route[ idx ] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( true ) , h. 0 . node_id ) ) ,
2656
- selected_route[ idx + 1 ] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( true ) , h. 0 . node_id ) ) ) {
2658
+ if iter_equal ( selected_route[ idx] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( true ) , h. 0 . candidate . target ( ) ) ) ,
2659
+ selected_route[ idx + 1 ] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( true ) , h. 0 . candidate . target ( ) ) ) ) {
2657
2660
let new_value = selected_route[ idx] . get_value_msat ( ) + selected_route[ idx + 1 ] . get_value_msat ( ) ;
2658
2661
selected_route[ idx] . update_value_and_recompute_fees ( new_value) ;
2659
2662
selected_route. remove ( idx + 1 ) ;
@@ -2678,14 +2681,15 @@ where L::Target: Logger {
2678
2681
// there are announced channels between the endpoints. If so, the hop might be
2679
2682
// referring to any of the announced channels, as its `short_channel_id` might be
2680
2683
// an alias, in which case we don't take any chances here.
2681
- network_graph. node ( & hop. node_id ) . map_or ( false , |hop_node|
2684
+ let hop_node_id = hop. candidate . source ( ) ;
2685
+ network_graph. node ( & hop_node_id) . map_or ( false , |hop_node|
2682
2686
hop_node. channels . iter ( ) . any ( |scid| network_graph. channel ( * scid)
2683
- . map_or ( false , |c| c. as_directed_from ( & prev_hop_node_id) . is_some ( ) ) )
2687
+ . map_or ( false , |c| c. as_directed_from ( & prev_hop_node_id) . is_some ( ) ) )
2684
2688
)
2685
2689
} ;
2686
2690
2687
2691
hops. push ( RouteHop {
2688
- pubkey : PublicKey :: from_slice ( hop. node_id . as_slice ( ) ) . map_err ( |_| LightningError { err : format ! ( "Public key {:?} is invalid" , & hop. node_id ) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ?,
2692
+ pubkey : PublicKey :: from_slice ( hop. candidate . target ( ) . unwrap ( ) . as_slice ( ) ) . map_err ( |_| LightningError { err : format ! ( "Public key {:?} is invalid" , & hop. candidate . target ( ) . unwrap ( ) ) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ?,
2689
2693
node_features : node_features. clone ( ) ,
2690
2694
short_channel_id : hop. candidate . short_channel_id ( ) . unwrap ( ) ,
2691
2695
channel_features : hop. candidate . features ( ) ,
@@ -2694,7 +2698,7 @@ where L::Target: Logger {
2694
2698
maybe_announced_channel,
2695
2699
} ) ;
2696
2700
2697
- prev_hop_node_id = hop. node_id ;
2701
+ prev_hop_node_id = hop. candidate . source ( ) ;
2698
2702
}
2699
2703
let mut final_cltv_delta = final_cltv_expiry_delta;
2700
2704
let blinded_tail = payment_path. hops . last ( ) . and_then ( |( h, _) | {
0 commit comments