@@ -131,11 +131,11 @@ impl<'a, S: Deref> ScorerAccountingForInFlightHtlcs<'a, S> where S::Target: Scor
131
131
impl < ' a , S : Deref > ScoreLookUp for ScorerAccountingForInFlightHtlcs < ' a , S > where S :: Target : ScoreLookUp {
132
132
type ScoreParams = <S :: Target as ScoreLookUp >:: ScoreParams ;
133
133
fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , usage : ChannelUsage , score_params : & Self :: ScoreParams ) -> u64 {
134
- let target = candidate. target ( ) ;
135
134
let short_channel_id = match candidate. short_channel_id ( ) {
136
135
Some ( short_channel_id) => short_channel_id,
137
136
None => return self . scorer . channel_penalty_msat ( candidate, usage, score_params) ,
138
137
} ;
138
+ let target = candidate. target ( ) . unwrap ( ) ;
139
139
let source = candidate. source ( ) ;
140
140
if let Some ( used_liquidity) = self . inflight_htlcs . used_liquidity_msat (
141
141
& source, & target, short_channel_id
@@ -1036,7 +1036,7 @@ pub enum CandidateRouteHop<'a> {
1036
1036
/// The payee's identity is concealed behind blinded paths provided in a BOLT 12 invoice.
1037
1037
Blinded {
1038
1038
/// Hint provides information about a blinded hop, needed while routing through a blinded
1039
- /// channel .
1039
+ /// path .
1040
1040
/// `BlindedPayInfo` provides information needed about the
1041
1041
/// payment while routing through a blinded
1042
1042
/// path.
@@ -1046,10 +1046,6 @@ pub enum CandidateRouteHop<'a> {
1046
1046
/// Provided to uniquely identify a hop as we are
1047
1047
/// route building.
1048
1048
hint_idx : usize ,
1049
- /// The node id of current hop in route.
1050
- ///
1051
- /// This will always equal to `maybe_dummy_payee_node_id` in `find_route` method.
1052
- target_node_id : NodeId ,
1053
1049
} ,
1054
1050
/// Similar to [`Self::Blinded`], but the path here has 1 blinded hop. `BlindedPayInfo` provided
1055
1051
/// for 1-hop blinded paths is ignored because it is meant to apply to the hops *between* the
@@ -1065,10 +1061,6 @@ pub enum CandidateRouteHop<'a> {
1065
1061
/// Provided to uniquely identify a hop as we are
1066
1062
/// route building.
1067
1063
hint_idx : usize ,
1068
- /// The node id of current hop in route.
1069
- ///
1070
- /// This will always equal to `maybe_dummy_payee_node_id` in `find_route` method.
1071
- target_node_id : NodeId ,
1072
1064
} ,
1073
1065
}
1074
1066
@@ -1158,11 +1150,11 @@ impl<'a> CandidateRouteHop<'a> {
1158
1150
/// Returns the id of this hop.
1159
1151
/// For `Blinded` and `OneHopBlinded` we return `CandidateHopId::Blinded` because we don't know the channel id.
1160
1152
/// For any other option we return `CandidateHopId::Clear` because we know the channel id and the direction.
1161
- pub fn id ( & self , channel_direction : bool /* src_node_id < target_node_id */ ) -> CandidateHopId {
1153
+ pub fn id ( & self , channel_direction : Option < bool > /* src_node_id < target_node_id */ ) -> CandidateHopId {
1162
1154
match self {
1163
1155
CandidateRouteHop :: Blinded { hint_idx, .. } => CandidateHopId :: Blinded ( * hint_idx) ,
1164
1156
CandidateRouteHop :: OneHopBlinded { hint_idx, .. } => CandidateHopId :: Blinded ( * hint_idx) ,
1165
- _ => CandidateHopId :: Clear ( ( self . short_channel_id ( ) . unwrap ( ) , channel_direction) ) ,
1157
+ _ => CandidateHopId :: Clear ( ( self . short_channel_id ( ) . unwrap ( ) , channel_direction. unwrap_or_else ( || self . source ( ) < self . target ( ) . unwrap ( ) ) ) ) ,
1166
1158
}
1167
1159
}
1168
1160
fn blinded_path ( & self ) -> Option < & ' a BlindedPath > {
@@ -1195,13 +1187,13 @@ impl<'a> CandidateRouteHop<'a> {
1195
1187
/// Target node id refers to the current examined hop in route finding.
1196
1188
///
1197
1189
/// For `Blinded` and `OneHopBlinded` we return `maybe_dummy_payee_node_id` because we don't know the target.
1198
- pub fn target ( & self ) -> NodeId {
1190
+ pub fn target ( & self ) -> Option < NodeId > {
1199
1191
match self {
1200
- CandidateRouteHop :: FirstHop { details, .. } => details. counterparty . node_id . into ( ) ,
1201
- CandidateRouteHop :: PublicHop { target_node_id, .. } => * target_node_id,
1202
- CandidateRouteHop :: PrivateHop { target_node_id, .. } => * target_node_id,
1203
- CandidateRouteHop :: Blinded { target_node_id , .. } => * target_node_id ,
1204
- CandidateRouteHop :: OneHopBlinded { target_node_id , .. } => * target_node_id ,
1192
+ CandidateRouteHop :: FirstHop { details, .. } => Some ( details. counterparty . node_id . into ( ) ) ,
1193
+ CandidateRouteHop :: PublicHop { target_node_id, .. } => Some ( * target_node_id) ,
1194
+ CandidateRouteHop :: PrivateHop { target_node_id, .. } => Some ( * target_node_id) ,
1195
+ CandidateRouteHop :: Blinded { .. } => None ,
1196
+ CandidateRouteHop :: OneHopBlinded { .. } => None ,
1205
1197
}
1206
1198
}
1207
1199
}
@@ -1289,7 +1281,7 @@ impl<'a> core::fmt::Debug for PathBuildingHop<'a> {
1289
1281
fn fmt ( & self , f : & mut core:: fmt:: Formatter ) -> Result < ( ) , core:: fmt:: Error > {
1290
1282
let mut debug_struct = f. debug_struct ( "PathBuildingHop" ) ;
1291
1283
debug_struct
1292
- . field ( "node_id" , & self . candidate . target ( ) )
1284
+ . field ( "node_id" , & self . candidate . target ( ) . unwrap ( ) )
1293
1285
. field ( "short_channel_id" , & self . candidate . short_channel_id ( ) )
1294
1286
. field ( "total_fee_msat" , & self . total_fee_msat )
1295
1287
. field ( "next_hops_fee_msat" , & self . next_hops_fee_msat )
@@ -1815,7 +1807,7 @@ where L::Target: Logger {
1815
1807
// $next_hops_fee_msat represents the fees paid for using all the channels *after* this one,
1816
1808
// since that value has to be transferred over this channel.
1817
1809
// Returns the contribution amount of $candidate if the channel caused an update to `targets`.
1818
- ( $candidate: expr, $src_node_id : expr , $dest_node_id : expr , $ next_hops_fee_msat: expr,
1810
+ ( $candidate: expr, $next_hops_fee_msat: expr,
1819
1811
$next_hops_value_contribution: expr, $next_hops_path_htlc_minimum_msat: expr,
1820
1812
$next_hops_path_penalty_msat: expr, $next_hops_cltv_delta: expr, $next_hops_path_length: expr ) => { {
1821
1813
// We "return" whether we updated the path at the end, and how much we can route via
@@ -1825,7 +1817,9 @@ where L::Target: Logger {
1825
1817
// practice these cases should be caught earlier:
1826
1818
// - for regular channels at channel announcement (TODO)
1827
1819
// - for first and last hops early in get_route
1828
- if $src_node_id != $dest_node_id {
1820
+ let src_node_id = $candidate. source( ) ;
1821
+ let dest_node_id = $candidate. target( ) . unwrap_or( maybe_dummy_payee_node_id) ;
1822
+ if src_node_id != dest_node_id {
1829
1823
let scid_opt = $candidate. short_channel_id( ) ;
1830
1824
let effective_capacity = $candidate. effective_capacity( ) ;
1831
1825
let htlc_maximum_msat = max_htlc_from_capacity( effective_capacity, channel_saturation_pow_half) ;
@@ -1839,7 +1833,7 @@ where L::Target: Logger {
1839
1833
// We do this for now, but this is a subject for removal.
1840
1834
if let Some ( mut available_value_contribution_msat) = htlc_maximum_msat. checked_sub( $next_hops_fee_msat) {
1841
1835
let used_liquidity_msat = used_liquidities
1842
- . get( & $candidate. id( $src_node_id < $dest_node_id ) )
1836
+ . get( & $candidate. id( None ) )
1843
1837
. map_or( 0 , |used_liquidity_msat| {
1844
1838
available_value_contribution_msat = available_value_contribution_msat
1845
1839
. saturating_sub( * used_liquidity_msat) ;
@@ -1934,7 +1928,7 @@ where L::Target: Logger {
1934
1928
) ;
1935
1929
let path_htlc_minimum_msat = compute_fees_saturating( curr_min, $candidate. fees( ) )
1936
1930
. saturating_add( curr_min) ;
1937
- let hm_entry = dist. entry( $src_node_id ) ;
1931
+ let hm_entry = dist. entry( $candidate . source ( ) ) ;
1938
1932
let old_entry = hm_entry. or_insert_with( || {
1939
1933
// If there was previously no known way to access the source node
1940
1934
// (recall it goes payee-to-payer) of short_channel_id, first add a
@@ -1970,7 +1964,7 @@ where L::Target: Logger {
1970
1964
1971
1965
// Ignore hop_use_fee_msat for channel-from-us as we assume all channels-from-us
1972
1966
// will have the same effective-fee
1973
- if $ src_node_id != our_node_id {
1967
+ if src_node_id != our_node_id {
1974
1968
// Note that `u64::max_value` means we'll always fail the
1975
1969
// `old_entry.total_fee_msat > total_fee_msat` check below
1976
1970
hop_use_fee_msat = compute_fees_saturating( amount_to_transfer_over_msat, $candidate. fees( ) ) ;
@@ -1996,7 +1990,7 @@ where L::Target: Logger {
1996
1990
let path_penalty_msat = $next_hops_path_penalty_msat
1997
1991
. saturating_add( channel_penalty_msat) ;
1998
1992
let new_graph_node = RouteGraphNode {
1999
- node_id: $ src_node_id,
1993
+ node_id: src_node_id,
2000
1994
lowest_fee_to_node: total_fee_msat,
2001
1995
total_cltv_delta: hop_total_cltv_delta,
2002
1996
value_contribution_msat,
@@ -2112,7 +2106,7 @@ where L::Target: Logger {
2112
2106
if let Some ( first_channels) = first_hop_targets. get( & $node_id) {
2113
2107
for details in first_channels {
2114
2108
let candidate = CandidateRouteHop :: FirstHop { details, node_id: our_node_id } ;
2115
- add_entry!( & candidate, our_node_id , $node_id , $fee_to_target_msat,
2109
+ add_entry!( & candidate, $fee_to_target_msat,
2116
2110
$next_hops_value_contribution,
2117
2111
$next_hops_path_htlc_minimum_msat, $next_hops_path_penalty_msat,
2118
2112
$next_hops_cltv_delta, $next_hops_path_length) ;
@@ -2138,7 +2132,7 @@ where L::Target: Logger {
2138
2132
source_node_id: * source,
2139
2133
target_node_id: $node_id,
2140
2134
} ;
2141
- add_entry!( & candidate, * source , $node_id ,
2135
+ add_entry!( & candidate,
2142
2136
$fee_to_target_msat,
2143
2137
$next_hops_value_contribution,
2144
2138
$next_hops_path_htlc_minimum_msat,
@@ -2169,7 +2163,7 @@ where L::Target: Logger {
2169
2163
payee_node_id_opt. map ( |payee| first_hop_targets. get ( & payee) . map ( |first_channels| {
2170
2164
for details in first_channels {
2171
2165
let candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id } ;
2172
- let added = add_entry ! ( & candidate, our_node_id , payee , 0 , path_value_msat,
2166
+ let added = add_entry ! ( & candidate, 0 , path_value_msat,
2173
2167
0 , 0u64 , 0 , 0 ) . is_some ( ) ;
2174
2168
log_trace ! ( logger, "{} direct route to payee via {}" ,
2175
2169
if added { "Added" } else { "Skipped" } , LoggedCandidateHop ( & candidate) ) ;
@@ -2203,10 +2197,10 @@ where L::Target: Logger {
2203
2197
network_nodes. get ( & intro_node_id) . is_some ( ) ;
2204
2198
if !have_intro_node_in_graph || our_node_id == intro_node_id { continue }
2205
2199
let candidate = if hint. 1 . blinded_hops . len ( ) == 1 {
2206
- CandidateRouteHop :: OneHopBlinded { hint, hint_idx, target_node_id : maybe_dummy_payee_node_id }
2207
- } else { CandidateRouteHop :: Blinded { hint, hint_idx, target_node_id : maybe_dummy_payee_node_id } } ;
2200
+ CandidateRouteHop :: OneHopBlinded { hint, hint_idx }
2201
+ } else { CandidateRouteHop :: Blinded { hint, hint_idx } } ;
2208
2202
let mut path_contribution_msat = path_value_msat;
2209
- if let Some ( hop_used_msat) = add_entry ! ( & candidate, intro_node_id , maybe_dummy_payee_node_id ,
2203
+ if let Some ( hop_used_msat) = add_entry ! ( & candidate,
2210
2204
0 , path_contribution_msat, 0 , 0_u64 , 0 , 0 )
2211
2205
{
2212
2206
path_contribution_msat = hop_used_msat;
@@ -2222,7 +2216,7 @@ where L::Target: Logger {
2222
2216
} ;
2223
2217
let path_min = candidate. htlc_minimum_msat ( ) . saturating_add (
2224
2218
compute_fees_saturating ( candidate. htlc_minimum_msat ( ) , candidate. fees ( ) ) ) ;
2225
- add_entry ! ( & first_hop_candidate, our_node_id , intro_node_id , blinded_path_fee,
2219
+ add_entry ! ( & first_hop_candidate, blinded_path_fee,
2226
2220
path_contribution_msat, path_min, 0_u64 , candidate. cltv_expiry_delta( ) ,
2227
2221
candidate. blinded_path( ) . map_or( 1 , |bp| bp. blinded_hops. len( ) as u8 ) ) ;
2228
2222
}
@@ -2276,7 +2270,7 @@ where L::Target: Logger {
2276
2270
} )
2277
2271
. unwrap_or_else ( || CandidateRouteHop :: PrivateHop { hint : hop, target_node_id : target } ) ;
2278
2272
2279
- if let Some ( hop_used_msat) = add_entry ! ( & candidate, source , target ,
2273
+ if let Some ( hop_used_msat) = add_entry ! ( & candidate,
2280
2274
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2281
2275
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
2282
2276
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length)
@@ -2290,7 +2284,7 @@ where L::Target: Logger {
2290
2284
}
2291
2285
2292
2286
let used_liquidity_msat = used_liquidities
2293
- . get ( & candidate. id ( source < target ) ) . copied ( )
2287
+ . get ( & candidate. id ( None ) ) . copied ( )
2294
2288
. unwrap_or ( 0 ) ;
2295
2289
let channel_usage = ChannelUsage {
2296
2290
amount_msat : final_value_msat + aggregate_next_hops_fee_msat,
@@ -2315,7 +2309,7 @@ where L::Target: Logger {
2315
2309
recommended_value_msat, our_node_pubkey) ;
2316
2310
for details in first_channels {
2317
2311
let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id} ;
2318
- add_entry ! ( & first_hop_candidate, our_node_id , NodeId :: from_pubkey ( & prev_hop_id ) ,
2312
+ add_entry ! ( & first_hop_candidate,
2319
2313
aggregate_next_hops_fee_msat, aggregate_path_contribution_msat,
2320
2314
aggregate_next_hops_path_htlc_minimum_msat, aggregate_next_hops_path_penalty_msat,
2321
2315
aggregate_next_hops_cltv_delta, aggregate_next_hops_path_length) ;
@@ -2360,8 +2354,7 @@ where L::Target: Logger {
2360
2354
recommended_value_msat, our_node_pubkey) ;
2361
2355
for details in first_channels {
2362
2356
let first_hop_candidate = CandidateRouteHop :: FirstHop { details, node_id : our_node_id} ;
2363
- add_entry ! ( & first_hop_candidate, our_node_id,
2364
- NodeId :: from_pubkey( & hop. src_node_id) ,
2357
+ add_entry ! ( & first_hop_candidate,
2365
2358
aggregate_next_hops_fee_msat,
2366
2359
aggregate_path_contribution_msat,
2367
2360
aggregate_next_hops_path_htlc_minimum_msat,
@@ -2400,7 +2393,7 @@ where L::Target: Logger {
2400
2393
2401
2394
' path_walk: loop {
2402
2395
let mut features_set = false ;
2403
- if let Some ( first_channels) = first_hop_targets. get ( & ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) ) {
2396
+ if let Some ( first_channels) = first_hop_targets. get ( & ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) . unwrap_or ( maybe_dummy_payee_node_id ) ) {
2404
2397
for details in first_channels {
2405
2398
if let Some ( scid) = ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . short_channel_id ( ) {
2406
2399
if details. get_outbound_payment_scid ( ) . unwrap ( ) == scid {
@@ -2412,7 +2405,7 @@ where L::Target: Logger {
2412
2405
}
2413
2406
}
2414
2407
if !features_set {
2415
- if let Some ( node) = network_nodes. get ( & ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) ) {
2408
+ if let Some ( node) = network_nodes. get ( & ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) . unwrap_or ( maybe_dummy_payee_node_id ) ) {
2416
2409
if let Some ( node_info) = node. announcement_info . as_ref ( ) {
2417
2410
ordered_hops. last_mut ( ) . unwrap ( ) . 1 = node_info. features . clone ( ) ;
2418
2411
} else {
@@ -2429,11 +2422,11 @@ where L::Target: Logger {
2429
2422
// save this path for the payment route. Also, update the liquidity
2430
2423
// remaining on the used hops, so that we take them into account
2431
2424
// while looking for more paths.
2432
- if ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) == maybe_dummy_payee_node_id {
2425
+ if ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) . unwrap_or ( maybe_dummy_payee_node_id ) == maybe_dummy_payee_node_id {
2433
2426
break ' path_walk;
2434
2427
}
2435
2428
2436
- new_entry = match dist. remove ( & ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) ) {
2429
+ new_entry = match dist. remove ( & ordered_hops. last ( ) . unwrap ( ) . 0 . candidate . target ( ) . unwrap_or ( maybe_dummy_payee_node_id ) ) {
2437
2430
Some ( payment_hop) => payment_hop,
2438
2431
// We can't arrive at None because, if we ever add an entry to targets,
2439
2432
// we also fill in the entry in dist (see add_entry!).
@@ -2473,12 +2466,11 @@ where L::Target: Logger {
2473
2466
// on the same liquidity in future paths.
2474
2467
let mut prevented_redundant_path_selection = false ;
2475
2468
let prev_hop_iter = core:: iter:: once ( our_node_id)
2476
- . chain ( payment_path. hops . iter ( ) . map ( |( hop, _) | hop. candidate . target ( ) ) ) ;
2477
- for ( prev_hop, ( hop, _) ) in prev_hop_iter. zip ( payment_path. hops . iter ( ) ) {
2478
- let target = hop. candidate . target ( ) ;
2469
+ . chain ( payment_path. hops . iter ( ) . map ( |( hop, _) | hop. candidate . target ( ) . unwrap_or ( maybe_dummy_payee_node_id) ) ) ;
2470
+ for ( _, ( hop, _) ) in prev_hop_iter. zip ( payment_path. hops . iter ( ) ) {
2479
2471
let spent_on_hop_msat = value_contribution_msat + hop. next_hops_fee_msat ;
2480
2472
let used_liquidity_msat = used_liquidities
2481
- . entry ( hop. candidate . id ( prev_hop < target ) )
2473
+ . entry ( hop. candidate . id ( None ) )
2482
2474
. and_modify ( |used_liquidity_msat| * used_liquidity_msat += spent_on_hop_msat)
2483
2475
. or_insert ( spent_on_hop_msat) ;
2484
2476
let hop_capacity = hop. candidate . effective_capacity ( ) ;
@@ -2499,8 +2491,8 @@ where L::Target: Logger {
2499
2491
log_trace ! ( logger,
2500
2492
"Disabling route candidate {} for future path building iterations to avoid duplicates." ,
2501
2493
LoggedCandidateHop ( victim_candidate) ) ;
2502
- * used_liquidities. entry ( victim_candidate. id ( false ) ) . or_default ( ) = exhausted;
2503
- * used_liquidities. entry ( victim_candidate. id ( true ) ) . or_default ( ) = exhausted;
2494
+ * used_liquidities. entry ( victim_candidate. id ( Some ( false ) ) ) . or_default ( ) = exhausted;
2495
+ * used_liquidities. entry ( victim_candidate. id ( Some ( true ) ) ) . or_default ( ) = exhausted;
2504
2496
}
2505
2497
2506
2498
// Track the total amount all our collected paths allow to send so that we know
@@ -2646,15 +2638,15 @@ where L::Target: Logger {
2646
2638
selected_route. sort_unstable_by_key ( |path| {
2647
2639
let mut key = [ CandidateHopId :: Clear ( ( 42 , true ) ) ; MAX_PATH_LENGTH_ESTIMATE as usize ] ;
2648
2640
debug_assert ! ( path. hops. len( ) <= key. len( ) ) ;
2649
- for ( scid, key) in path. hops . iter ( ) . map ( |h| h. 0 . candidate . id ( true ) ) . zip ( key. iter_mut ( ) ) {
2641
+ for ( scid, key) in path. hops . iter ( ) . map ( |h| h. 0 . candidate . id ( Some ( true ) ) ) . zip ( key. iter_mut ( ) ) {
2650
2642
* key = scid;
2651
2643
}
2652
2644
key
2653
2645
} ) ;
2654
2646
for idx in 0 ..( selected_route. len ( ) - 1 ) {
2655
2647
if idx + 1 >= selected_route. len ( ) { break ; }
2656
- if iter_equal ( selected_route[ idx ] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( true ) , h. 0 . candidate . target ( ) ) ) ,
2657
- selected_route[ idx + 1 ] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( true ) , h. 0 . candidate . target ( ) ) ) ) {
2648
+ if iter_equal ( selected_route[ idx ] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( Some ( true ) ) , h. 0 . candidate . target ( ) . unwrap_or ( maybe_dummy_payee_node_id ) ) ) ,
2649
+ selected_route[ idx + 1 ] . hops . iter ( ) . map ( |h| ( h. 0 . candidate . id ( Some ( true ) ) , h. 0 . candidate . target ( ) . unwrap_or ( maybe_dummy_payee_node_id ) ) ) ) {
2658
2650
let new_value = selected_route[ idx] . get_value_msat ( ) + selected_route[ idx + 1 ] . get_value_msat ( ) ;
2659
2651
selected_route[ idx] . update_value_and_recompute_fees ( new_value) ;
2660
2652
selected_route. remove ( idx + 1 ) ;
@@ -2679,14 +2671,14 @@ where L::Target: Logger {
2679
2671
// there are announced channels between the endpoints. If so, the hop might be
2680
2672
// referring to any of the announced channels, as its `short_channel_id` might be
2681
2673
// an alias, in which case we don't take any chances here.
2682
- network_graph. node ( & hop. candidate . target ( ) ) . map_or ( false , |hop_node|
2674
+ network_graph. node ( & hop. candidate . target ( ) . unwrap_or ( maybe_dummy_payee_node_id ) ) . map_or ( false , |hop_node|
2683
2675
hop_node. channels . iter ( ) . any ( |scid| network_graph. channel ( * scid)
2684
2676
. map_or ( false , |c| c. as_directed_from ( & prev_hop_node_id) . is_some ( ) ) )
2685
2677
)
2686
2678
} ;
2687
2679
2688
2680
hops. push ( RouteHop {
2689
- pubkey : PublicKey :: from_slice ( hop. candidate . target ( ) . as_slice ( ) ) . map_err ( |_| LightningError { err : format ! ( "Public key {:?} is invalid" , & hop. candidate. target( ) ) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ?,
2681
+ pubkey : PublicKey :: from_slice ( hop. candidate . target ( ) . unwrap ( ) . as_slice ( ) ) . map_err ( |_| LightningError { err : format ! ( "Public key {:?} is invalid" , & hop. candidate. target( ) . unwrap_or ( maybe_dummy_payee_node_id ) . as_slice ( ) ) , action : ErrorAction :: IgnoreAndLog ( Level :: Trace ) } ) ?,
2690
2682
node_features : node_features. clone ( ) ,
2691
2683
short_channel_id : hop. candidate . short_channel_id ( ) . unwrap ( ) ,
2692
2684
channel_features : hop. candidate . features ( ) ,
@@ -2695,7 +2687,7 @@ where L::Target: Logger {
2695
2687
maybe_announced_channel,
2696
2688
} ) ;
2697
2689
2698
- prev_hop_node_id = hop. candidate . target ( ) ;
2690
+ prev_hop_node_id = hop. candidate . target ( ) . unwrap_or ( maybe_dummy_payee_node_id ) ;
2699
2691
}
2700
2692
let mut final_cltv_delta = final_cltv_expiry_delta;
2701
2693
let blinded_tail = payment_path. hops . last ( ) . and_then ( |( h, _) | {
@@ -2861,7 +2853,7 @@ fn build_route_from_hops_internal<L: Deref>(
2861
2853
fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop ,
2862
2854
_usage : ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64
2863
2855
{
2864
- let target = candidate. target ( ) ;
2856
+ let target = candidate. target ( ) . unwrap ( ) ;
2865
2857
let source = candidate. source ( ) ;
2866
2858
let mut cur_id = self . our_node_id ;
2867
2859
for i in 0 ..self . hop_ids . len ( ) {
@@ -6237,7 +6229,7 @@ mod tests {
6237
6229
impl ScoreLookUp for BadNodeScorer {
6238
6230
type ScoreParams = ( ) ;
6239
6231
fn channel_penalty_msat ( & self , candidate : & CandidateRouteHop , _: ChannelUsage , _score_params : & Self :: ScoreParams ) -> u64 {
6240
- let target = candidate. target ( ) ;
6232
+ let target = candidate. target ( ) . unwrap ( ) ;
6241
6233
if target == self . node_id { u64:: max_value ( ) } else { 0 }
6242
6234
}
6243
6235
}
0 commit comments