@@ -2123,6 +2123,16 @@ 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
+ payment : & ' a PaymentParameters ,
2129
+ max_total_routing_fee_msat : u64 ,
2130
+ minimal_value_contribution_msat : u64 ,
2131
+ final_cltv_expiry_delta : u32 ,
2132
+ recommended_value_msat : u64 ,
2133
+ max_path_length : u8 ,
2134
+ }
2135
+
2126
2136
pub ( crate ) fn get_route < L : Deref , S : ScoreLookUp > (
2127
2137
our_node_pubkey : & PublicKey , route_params : & RouteParameters , network_graph : & ReadOnlyNetworkGraph ,
2128
2138
first_hops : Option < & [ & ChannelDetails ] > , logger : L , scorer : & S , score_params : & S :: ScoreParams ,
@@ -2375,6 +2385,11 @@ where L::Target: Logger {
2375
2385
// Remember how many candidates we ignored to allow for some logging afterwards.
2376
2386
let mut ignored_stats = IgnoredCandidatesStats :: default ( ) ;
2377
2387
2388
+ // Common parameters used across this function.
2389
+ let params = GetRouteParameters { max_total_routing_fee_msat,
2390
+ minimal_value_contribution_msat, final_cltv_expiry_delta,
2391
+ recommended_value_msat, max_path_length, payment : payment_params } ;
2392
+
2378
2393
macro_rules! add_entry {
2379
2394
// Adds entry which goes from $candidate.source() to $candidate.target() over the $candidate hop.
2380
2395
// $next_hops_fee_msat represents the fees paid for using all the channels *after* this one,
@@ -2384,22 +2399,17 @@ where L::Target: Logger {
2384
2399
$next_hops_value_contribution: expr, $next_hops_path_htlc_minimum_msat: expr,
2385
2400
$next_hops_path_penalty_msat: expr, $next_hops_cltv_delta: expr, $next_hops_path_length: expr ) => { {
2386
2401
add_entry_internal(
2402
+ & params,
2387
2403
channel_saturation_pow_half,
2388
2404
& used_liquidities,
2389
- minimal_value_contribution_msat,
2390
- & payment_params,
2391
- final_cltv_expiry_delta,
2392
- recommended_value_msat,
2393
2405
& logger,
2394
2406
& mut ignored_stats,
2395
2407
& mut hit_minimum_limit,
2396
2408
& mut dist,
2397
2409
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,17 @@ 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
3133
our_node_id : NodeId ,
3127
- max_total_routing_fee_msat : u64 ,
3128
3134
targets : & mut BinaryHeap < RouteGraphNode > ,
3129
3135
scorer : & S ,
3130
3136
score_params : & S :: ScoreParams ,
3131
- max_path_length : u8 ,
3132
3137
// original add_entry params:
3133
3138
candidate : & CandidateRouteHop < ' a > ,
3134
3139
next_hops_fee_msat : u64 ,
@@ -3171,19 +3176,19 @@ where
3171
3176
} ) ;
3172
3177
3173
3178
// 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;
3179
+ let contributes_sufficient_value = available_value_contribution_msat >= params . minimal_value_contribution_msat ;
3175
3180
// Do not consider candidate hops that would exceed the maximum path length.
3176
3181
let path_length_to_node = next_hops_path_length
3177
3182
+ if candidate. blinded_hint_idx ( ) . is_some ( ) { 0 } else { 1 } ;
3178
- let exceeds_max_path_length = path_length_to_node > max_path_length;
3183
+ let exceeds_max_path_length = path_length_to_node > params . max_path_length ;
3179
3184
3180
3185
// Do not consider candidates that exceed the maximum total cltv expiry limit.
3181
3186
// In order to already account for some of the privacy enhancing random CLTV
3182
3187
// expiry delta offset we add on top later, we subtract a rough estimate
3183
3188
// (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)
3189
+ let max_total_cltv_expiry_delta = ( params . payment . max_total_cltv_expiry_delta - params . final_cltv_expiry_delta )
3185
3190
. checked_sub ( 2 * MEDIAN_HOP_CLTV_EXPIRY_DELTA )
3186
- . unwrap_or ( payment_params . max_total_cltv_expiry_delta - final_cltv_expiry_delta) ;
3191
+ . unwrap_or ( params . payment . max_total_cltv_expiry_delta - params . final_cltv_expiry_delta ) ;
3187
3192
let hop_total_cltv_delta = ( next_hops_cltv_delta as u32 )
3188
3193
. saturating_add ( candidate. cltv_expiry_delta ( ) ) ;
3189
3194
let exceeds_cltv_delta_limit = hop_total_cltv_delta > max_total_cltv_expiry_delta;
@@ -3202,15 +3207,15 @@ where
3202
3207
#[ allow( unused_comparisons) ] // next_hops_path_htlc_minimum_msat is 0 in some calls so rustc complains
3203
3208
let may_overpay_to_meet_path_minimum_msat =
3204
3209
( amount_to_transfer_over_msat < candidate. htlc_minimum_msat ( ) &&
3205
- recommended_value_msat >= candidate. htlc_minimum_msat ( ) ) ||
3210
+ params . recommended_value_msat >= candidate. htlc_minimum_msat ( ) ) ||
3206
3211
( amount_to_transfer_over_msat < next_hops_path_htlc_minimum_msat &&
3207
- recommended_value_msat >= next_hops_path_htlc_minimum_msat) ;
3212
+ params . recommended_value_msat >= next_hops_path_htlc_minimum_msat) ;
3208
3213
3209
3214
let payment_failed_on_this_channel = match scid_opt {
3210
- Some ( scid) => payment_params . previously_failed_channels . contains ( & scid) ,
3215
+ Some ( scid) => params . payment . previously_failed_channels . contains ( & scid) ,
3211
3216
None => match candidate. blinded_hint_idx ( ) {
3212
3217
Some ( idx) => {
3213
- payment_params . previously_failed_blinded_path_idxs . contains ( & ( idx as u64 ) )
3218
+ params . payment . previously_failed_blinded_path_idxs . contains ( & ( idx as u64 ) )
3214
3219
} ,
3215
3220
None => false ,
3216
3221
} ,
@@ -3324,15 +3329,15 @@ where
3324
3329
}
3325
3330
3326
3331
// 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 {
3332
+ if total_fee_msat > params . max_total_routing_fee_msat {
3328
3333
if should_log_candidate {
3329
3334
log_trace ! ( logger, "Ignoring {} due to exceeding max total routing fee limit." , LoggedCandidateHop ( & candidate) ) ;
3330
3335
3331
3336
if let Some ( _) = first_hop_details {
3332
3337
log_trace ! ( logger,
3333
3338
"First hop candidate routing fee: {}. Limit: {}" ,
3334
3339
total_fee_msat,
3335
- max_total_routing_fee_msat,
3340
+ params . max_total_routing_fee_msat,
3336
3341
) ;
3337
3342
}
3338
3343
}
0 commit comments