@@ -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
+ payment : & ' a PaymentParameters ,
2129
+ channel_saturation_pow_half : u8 ,
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 { channel_saturation_pow_half,
2391
+ max_total_routing_fee_msat, minimal_value_contribution_msat, final_cltv_expiry_delta,
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(
2387
- channel_saturation_pow_half ,
2403
+ & params ,
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,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:
3116
- channel_saturation_pow_half : u8 ,
3126
+ params : & GetRouteParameters ,
3117
3127
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
3128
logger : & L ,
3123
3129
ignored_stats : & mut IgnoredCandidatesStats ,
3124
3130
hit_minimum_limit : & mut bool ,
3125
3131
dist : & mut Vec < Option < PathBuildingHop < ' a > > > ,
3126
3132
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 ,
@@ -3152,7 +3156,7 @@ where
3152
3156
if Some ( src_node_id) != candidate. target ( ) {
3153
3157
let scid_opt = candidate. short_channel_id ( ) ;
3154
3158
let effective_capacity = candidate. effective_capacity ( ) ;
3155
- let htlc_maximum_msat = max_htlc_from_capacity ( effective_capacity, channel_saturation_pow_half) ;
3159
+ let htlc_maximum_msat = max_htlc_from_capacity ( effective_capacity, params . channel_saturation_pow_half ) ;
3156
3160
3157
3161
// It is tricky to subtract $next_hops_fee_msat from available liquidity here.
3158
3162
// It may be misleading because we might later choose to reduce the value transferred
@@ -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
} ,
@@ -3324,15 +3328,15 @@ where
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