@@ -1247,9 +1247,6 @@ fn iter_equal<I1: Iterator, I2: Iterator>(mut iter_a: I1, mut iter_b: I2)
1247
1247
/// These fee values are useful to choose hops as we traverse the graph "payee-to-payer".
1248
1248
#[ derive( Clone ) ]
1249
1249
struct PathBuildingHop < ' a > {
1250
- // Note that this should be dropped in favor of loading it from CandidateRouteHop, but doing so
1251
- // is a larger refactor and will require careful performance analysis.
1252
- node_id : NodeId ,
1253
1250
candidate : CandidateRouteHop < ' a > ,
1254
1251
fee_msat : u64 ,
1255
1252
@@ -1287,7 +1284,7 @@ impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
1287
1284
fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
1288
1285
let mut debug_struct = f. debug_struct ( "PathBuildingHop" ) ;
1289
1286
debug_struct
1290
- . field ( "node_id" , & self . node_id )
1287
+ . field ( "node_id" , & self . candidate . target ( ) )
1291
1288
. field ( "short_channel_id" , & self . candidate . short_channel_id ( ) )
1292
1289
. field ( "total_fee_msat" , & self . total_fee_msat )
1293
1290
. field ( "next_hops_fee_msat" , & self . next_hops_fee_msat )
@@ -1824,8 +1821,7 @@ where L::Target: Logger {
1824
1821
// - for regular channels at channel announcement (TODO)
1825
1822
// - for first and last hops early in get_route
1826
1823
let src_node_id = $candidate. source( ) ;
1827
- let dest_node_id = $candidate. target( ) . unwrap_or( maybe_dummy_payee_node_id) ;
1828
- if src_node_id != dest_node_id {
1824
+ if Some ( src_node_id) != $candidate. target( ) {
1829
1825
let scid_opt = $candidate. short_channel_id( ) ;
1830
1826
let effective_capacity = $candidate. effective_capacity( ) ;
1831
1827
let htlc_maximum_msat = max_htlc_from_capacity( effective_capacity, channel_saturation_pow_half) ;
@@ -1964,7 +1960,6 @@ where L::Target: Logger {
1964
1960
// This will affect our decision on selecting short_channel_id
1965
1961
// as a way to reach the $candidate.target() node.
1966
1962
PathBuildingHop {
1967
- node_id: dest_node_id. clone( ) ,
1968
1963
candidate: $candidate. clone( ) ,
1969
1964
fee_msat: 0 ,
1970
1965
next_hops_fee_msat: u64 :: max_value( ) ,
@@ -2063,7 +2058,6 @@ where L::Target: Logger {
2063
2058
old_entry. next_hops_fee_msat = $next_hops_fee_msat;
2064
2059
old_entry. hop_use_fee_msat = hop_use_fee_msat;
2065
2060
old_entry. total_fee_msat = total_fee_msat;
2066
- old_entry. node_id = dest_node_id;
2067
2061
old_entry. candidate = $candidate. clone( ) ;
2068
2062
old_entry. fee_msat = 0 ; // This value will be later filled with hop_use_fee_msat of the following channel
2069
2063
old_entry. path_htlc_minimum_msat = path_htlc_minimum_msat;
@@ -2435,7 +2429,8 @@ where L::Target: Logger {
2435
2429
2436
2430
' path_walk: loop {
2437
2431
let mut features_set = false ;
2438
- if let Some ( first_channels) = first_hop_targets. get ( & ordered_hops. last ( ) . unwrap ( ) . 0 . node_id ) {
2432
+ let target = ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) . unwrap_or ( maybe_dummy_payee_node_id) ;
2433
+ if let Some ( first_channels) = first_hop_targets. get ( & target) {
2439
2434
for details in first_channels {
2440
2435
if let Some ( scid) = ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . short_channel_id ( ) {
2441
2436
if details. get_outbound_payment_scid ( ) . unwrap ( ) == scid {
@@ -2447,7 +2442,7 @@ where L::Target: Logger {
2447
2442
}
2448
2443
}
2449
2444
if !features_set {
2450
- if let Some ( node) = network_nodes. get ( & ordered_hops . last ( ) . unwrap ( ) . 0 . node_id ) {
2445
+ if let Some ( node) = network_nodes. get ( & target ) {
2451
2446
if let Some ( node_info) = node. announcement_info . as_ref ( ) {
2452
2447
ordered_hops. last_mut ( ) . unwrap ( ) . 1 = node_info. features . clone ( ) ;
2453
2448
} else {
@@ -2464,11 +2459,11 @@ where L::Target: Logger {
2464
2459
// save this path for the payment route. Also, update the liquidity
2465
2460
// remaining on the used hops, so that we take them into account
2466
2461
// while looking for more paths.
2467
- if ordered_hops . last ( ) . unwrap ( ) . 0 . node_id == maybe_dummy_payee_node_id {
2462
+ if target == maybe_dummy_payee_node_id {
2468
2463
break ' path_walk;
2469
2464
}
2470
2465
2471
- new_entry = match dist. remove ( & ordered_hops . last ( ) . unwrap ( ) . 0 . node_id ) {
2466
+ new_entry = match dist. remove ( & target ) {
2472
2467
Some ( payment_hop) => payment_hop,
2473
2468
// We can't arrive at None because, if we ever add an entry to targets,
2474
2469
// we also fill in the entry in dist (see add_entry!).
@@ -2687,8 +2682,8 @@ where L::Target: Logger {
2687
2682
} ) ;
2688
2683
for idx in 0 ..( selected_route. len ( ) - 1 ) {
2689
2684
if idx + 1 >= selected_route. len ( ) { break ; }
2690
- if iter_equal ( selected_route[ idx] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( ) , h. 0 . node_id ) ) ,
2691
- selected_route[ idx + 1 ] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( ) , h. 0 . node_id ) ) ) {
2685
+ if iter_equal ( selected_route[ idx] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( ) , h. 0 . candidate . target ( ) ) ) ,
2686
+ selected_route[ idx + 1 ] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( ) , h. 0 . candidate . target ( ) ) ) ) {
2692
2687
let new_value = selected_route[ idx] . get_value_msat ( ) + selected_route[ idx + 1 ] . get_value_msat ( ) ;
2693
2688
selected_route[ idx] . update_value_and_recompute_fees ( new_value) ;
2694
2689
selected_route. remove ( idx + 1 ) ;
@@ -2701,6 +2696,7 @@ where L::Target: Logger {
2701
2696
for ( hop, node_features) in payment_path. hops . iter ( )
2702
2697
. filter ( |( h, _) | h. candidate . short_channel_id ( ) . is_some ( ) )
2703
2698
{
2699
+ let target = hop. candidate . target ( ) . expect ( "target is defined when short_channel_id is defined" ) ;
2704
2700
let maybe_announced_channel = if let CandidateRouteHop :: PublicHop { .. } = hop. candidate {
2705
2701
// If we sourced the hop from the graph we're sure the target node is announced.
2706
2702
true
@@ -2712,14 +2708,14 @@ where L::Target: Logger {
2712
2708
// there are announced channels between the endpoints. If so, the hop might be
2713
2709
// referring to any of the announced channels, as its `short_channel_id` might be
2714
2710
// an alias, in which case we don't take any chances here.
2715
- network_graph. node ( & hop . node_id ) . map_or ( false , |hop_node|
2711
+ network_graph. node ( & target ) . map_or ( false , |hop_node|
2716
2712
hop_node. channels . iter ( ) . any ( |scid| network_graph. channel ( * scid)
2717
2713
. map_or ( false , |c| c. as_directed_from ( & hop. candidate . source ( ) ) . is_some ( ) ) )
2718
2714
)
2719
2715
} ;
2720
2716
2721
2717
hops. push ( RouteHop {
2722
- 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 ) } ) ?,
2718
+ pubkey : PublicKey :: from_slice ( target . as_slice ( ) ) . map_err ( |_| LightningError { err : format ! ( "Public key {:?} is invalid" , & target ) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ?,
2723
2719
node_features : node_features. clone ( ) ,
2724
2720
short_channel_id : hop. candidate . short_channel_id ( ) . unwrap ( ) ,
2725
2721
channel_features : hop. candidate . features ( ) ,
0 commit comments