@@ -2123,6 +2123,17 @@ where L::Target: Logger, GL::Target: Logger {
2123
2123
Ok ( route)
2124
2124
}
2125
2125
2126
+ // Const after initialization params which are used across the [`get_route`].
2127
+ struct GetRouteParameters < ' a > {
2128
+ our_node_id : NodeId ,
2129
+ payment : & ' a PaymentParameters ,
2130
+ max_total_routing_fee_msat : u64 ,
2131
+ minimal_value_contribution_msat : u64 ,
2132
+ final_cltv_expiry_delta : u32 ,
2133
+ recommended_value_msat : u64 ,
2134
+ max_path_length : u8 ,
2135
+ }
2136
+
2126
2137
pub ( crate ) fn get_route < L : Deref , S : ScoreLookUp > (
2127
2138
our_node_pubkey : & PublicKey , route_params : & RouteParameters , network_graph : & ReadOnlyNetworkGraph ,
2128
2139
first_hops : Option < & [ & ChannelDetails ] > , logger : L , scorer : & S , score_params : & S :: ScoreParams ,
@@ -2375,6 +2386,11 @@ where L::Target: Logger {
2375
2386
// Remember how many candidates we ignored to allow for some logging afterwards.
2376
2387
let mut ignored_stats = IgnoredCandidatesStats :: default ( ) ;
2377
2388
2389
+ // Common parameters used across this function.
2390
+ let params = GetRouteParameters { max_total_routing_fee_msat,
2391
+ minimal_value_contribution_msat, final_cltv_expiry_delta, our_node_id,
2392
+ recommended_value_msat, max_path_length, payment : payment_params } ;
2393
+
2378
2394
macro_rules! add_entry {
2379
2395
// Adds entry which goes from $candidate.source() to $candidate.target() over the $candidate hop.
2380
2396
// $next_hops_fee_msat represents the fees paid for using all the channels *after* this one,
@@ -2384,22 +2400,16 @@ where L::Target: Logger {
2384
2400
$next_hops_value_contribution: expr, $next_hops_path_htlc_minimum_msat: expr,
2385
2401
$next_hops_path_penalty_msat: expr, $next_hops_cltv_delta: expr, $next_hops_path_length: expr ) => { {
2386
2402
add_entry_internal(
2403
+ & params,
2387
2404
channel_saturation_pow_half,
2388
2405
& used_liquidities,
2389
- minimal_value_contribution_msat,
2390
- & payment_params,
2391
- final_cltv_expiry_delta,
2392
- recommended_value_msat,
2393
2406
& logger,
2394
2407
& mut ignored_stats,
2395
2408
& mut hit_minimum_limit,
2396
2409
& mut dist,
2397
- our_node_id,
2398
- max_total_routing_fee_msat,
2399
2410
& mut targets,
2400
2411
scorer,
2401
2412
score_params,
2402
- max_path_length,
2403
2413
$candidate,
2404
2414
$next_hops_fee_msat,
2405
2415
$next_hops_value_contribution,
@@ -3113,22 +3123,16 @@ where L::Target: Logger {
3113
3123
// Returns the contribution amount of candidate if the channel caused an update to `targets`.
3114
3124
fn add_entry_internal < ' a , L : Deref , S : ScoreLookUp > (
3115
3125
// parameters that were captured from the original macro add_entry:
3126
+ params : & GetRouteParameters ,
3116
3127
channel_saturation_pow_half : u8 ,
3117
3128
used_liquidities : & HashMap < CandidateHopId , u64 > ,
3118
- minimal_value_contribution_msat : u64 ,
3119
- payment_params : & PaymentParameters ,
3120
- final_cltv_expiry_delta : u32 ,
3121
- recommended_value_msat : u64 ,
3122
3129
logger : & L ,
3123
3130
ignored_stats : & mut IgnoredCandidatesStats ,
3124
3131
hit_minimum_limit : & mut bool ,
3125
3132
dist : & mut Vec < Option < PathBuildingHop < ' a > > > ,
3126
- our_node_id : NodeId ,
3127
- max_total_routing_fee_msat : u64 ,
3128
3133
targets : & mut BinaryHeap < RouteGraphNode > ,
3129
3134
scorer : & S ,
3130
3135
score_params : & S :: ScoreParams ,
3131
- max_path_length : u8 ,
3132
3136
// original add_entry params:
3133
3137
candidate : & CandidateRouteHop < ' a > ,
3134
3138
next_hops_fee_msat : u64 ,
@@ -3171,19 +3175,19 @@ where
3171
3175
} ) ;
3172
3176
3173
3177
// Verify the liquidity offered by this channel complies to the minimal contribution.
3174
- let contributes_sufficient_value = available_value_contribution_msat >= minimal_value_contribution_msat;
3178
+ let contributes_sufficient_value = available_value_contribution_msat >= params . minimal_value_contribution_msat ;
3175
3179
// Do not consider candidate hops that would exceed the maximum path length.
3176
3180
let path_length_to_node = next_hops_path_length
3177
3181
+ if candidate. blinded_hint_idx ( ) . is_some ( ) { 0 } else { 1 } ;
3178
- let exceeds_max_path_length = path_length_to_node > max_path_length;
3182
+ let exceeds_max_path_length = path_length_to_node > params . max_path_length ;
3179
3183
3180
3184
// Do not consider candidates that exceed the maximum total cltv expiry limit.
3181
3185
// In order to already account for some of the privacy enhancing random CLTV
3182
3186
// expiry delta offset we add on top later, we subtract a rough estimate
3183
3187
// (2*MEDIAN_HOP_CLTV_EXPIRY_DELTA) here.
3184
- let max_total_cltv_expiry_delta = ( payment_params . max_total_cltv_expiry_delta - final_cltv_expiry_delta)
3188
+ let max_total_cltv_expiry_delta = ( params . payment . max_total_cltv_expiry_delta - params . final_cltv_expiry_delta )
3185
3189
. checked_sub ( 2 * MEDIAN_HOP_CLTV_EXPIRY_DELTA )
3186
- . unwrap_or ( payment_params . max_total_cltv_expiry_delta - final_cltv_expiry_delta) ;
3190
+ . unwrap_or ( params . payment . max_total_cltv_expiry_delta - params . final_cltv_expiry_delta ) ;
3187
3191
let hop_total_cltv_delta = ( next_hops_cltv_delta as u32 )
3188
3192
. saturating_add ( candidate. cltv_expiry_delta ( ) ) ;
3189
3193
let exceeds_cltv_delta_limit = hop_total_cltv_delta > max_total_cltv_expiry_delta;
@@ -3202,15 +3206,15 @@ where
3202
3206
#[ allow( unused_comparisons) ] // next_hops_path_htlc_minimum_msat is 0 in some calls so rustc complains
3203
3207
let may_overpay_to_meet_path_minimum_msat =
3204
3208
( amount_to_transfer_over_msat < candidate. htlc_minimum_msat ( ) &&
3205
- recommended_value_msat >= candidate. htlc_minimum_msat ( ) ) ||
3209
+ params . recommended_value_msat >= candidate. htlc_minimum_msat ( ) ) ||
3206
3210
( amount_to_transfer_over_msat < next_hops_path_htlc_minimum_msat &&
3207
- recommended_value_msat >= next_hops_path_htlc_minimum_msat) ;
3211
+ params . recommended_value_msat >= next_hops_path_htlc_minimum_msat) ;
3208
3212
3209
3213
let payment_failed_on_this_channel = match scid_opt {
3210
- Some ( scid) => payment_params . previously_failed_channels . contains ( & scid) ,
3214
+ Some ( scid) => params . payment . previously_failed_channels . contains ( & scid) ,
3211
3215
None => match candidate. blinded_hint_idx ( ) {
3212
3216
Some ( idx) => {
3213
- payment_params . previously_failed_blinded_path_idxs . contains ( & ( idx as u64 ) )
3217
+ params . payment . previously_failed_blinded_path_idxs . contains ( & ( idx as u64 ) )
3214
3218
} ,
3215
3219
None => false ,
3216
3220
} ,
@@ -3316,23 +3320,23 @@ where
3316
3320
3317
3321
// Ignore hop_use_fee_msat for channel-from-us as we assume all channels-from-us
3318
3322
// will have the same effective-fee
3319
- if src_node_id != our_node_id {
3323
+ if src_node_id != params . our_node_id {
3320
3324
// Note that `u64::max_value` means we'll always fail the
3321
3325
// `old_entry.total_fee_msat > total_fee_msat` check below
3322
3326
hop_use_fee_msat = compute_fees_saturating ( amount_to_transfer_over_msat, candidate. fees ( ) ) ;
3323
3327
total_fee_msat = total_fee_msat. saturating_add ( hop_use_fee_msat) ;
3324
3328
}
3325
3329
3326
3330
// Ignore hops if augmenting the current path to them would put us over `max_total_routing_fee_msat`
3327
- if total_fee_msat > max_total_routing_fee_msat {
3331
+ if total_fee_msat > params . max_total_routing_fee_msat {
3328
3332
if should_log_candidate {
3329
3333
log_trace ! ( logger, "Ignoring {} due to exceeding max total routing fee limit." , LoggedCandidateHop ( & candidate) ) ;
3330
3334
3331
3335
if let Some ( _) = first_hop_details {
3332
3336
log_trace ! ( logger,
3333
3337
"First hop candidate routing fee: {}. Limit: {}" ,
3334
3338
total_fee_msat,
3335
- max_total_routing_fee_msat,
3339
+ params . max_total_routing_fee_msat,
3336
3340
) ;
3337
3341
}
3338
3342
}
0 commit comments