@@ -2123,6 +2123,16 @@ where L::Target: Logger, GL::Target: Logger {
21232123 Ok ( route)
21242124}
21252125
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+
21262136pub ( crate ) fn get_route < L : Deref , S : ScoreLookUp > (
21272137 our_node_pubkey : & PublicKey , route_params : & RouteParameters , network_graph : & ReadOnlyNetworkGraph ,
21282138 first_hops : Option < & [ & ChannelDetails ] > , logger : L , scorer : & S , score_params : & S :: ScoreParams ,
@@ -2375,6 +2385,11 @@ where L::Target: Logger {
23752385 // Remember how many candidates we ignored to allow for some logging afterwards.
23762386 let mut ignored_stats = IgnoredCandidatesStats :: default ( ) ;
23772387
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+
23782393 macro_rules! add_entry {
23792394 // Adds entry which goes from $candidate.source() to $candidate.target() over the $candidate hop.
23802395 // $next_hops_fee_msat represents the fees paid for using all the channels *after* this one,
@@ -2384,22 +2399,17 @@ where L::Target: Logger {
23842399 $next_hops_value_contribution: expr, $next_hops_path_htlc_minimum_msat: expr,
23852400 $next_hops_path_penalty_msat: expr, $next_hops_cltv_delta: expr, $next_hops_path_length: expr ) => { {
23862401 add_entry_internal(
2402+ & params,
23872403 channel_saturation_pow_half,
23882404 & used_liquidities,
2389- minimal_value_contribution_msat,
2390- & payment_params,
2391- final_cltv_expiry_delta,
2392- recommended_value_msat,
23932405 & logger,
23942406 & mut ignored_stats,
23952407 & mut hit_minimum_limit,
23962408 & mut dist,
23972409 our_node_id,
2398- max_total_routing_fee_msat,
23992410 & mut targets,
24002411 scorer,
24012412 score_params,
2402- max_path_length,
24032413 $candidate,
24042414 $next_hops_fee_msat,
24052415 $next_hops_value_contribution,
@@ -3113,22 +3123,17 @@ where L::Target: Logger {
31133123// Returns the contribution amount of candidate if the channel caused an update to `targets`.
31143124fn add_entry_internal < ' a , L : Deref , S : ScoreLookUp > (
31153125 // parameters that were captured from the original macro add_entry:
3126+ params : & GetRouteParameters ,
31163127 channel_saturation_pow_half : u8 ,
31173128 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 ,
31223129 logger : & L ,
31233130 ignored_stats : & mut IgnoredCandidatesStats ,
31243131 hit_minimum_limit : & mut bool ,
31253132 dist : & mut Vec < Option < PathBuildingHop < ' a > > > ,
31263133 our_node_id : NodeId ,
3127- max_total_routing_fee_msat : u64 ,
31283134 targets : & mut BinaryHeap < RouteGraphNode > ,
31293135 scorer : & S ,
31303136 score_params : & S :: ScoreParams ,
3131- max_path_length : u8 ,
31323137 // original add_entry params:
31333138 candidate : & CandidateRouteHop < ' a > ,
31343139 next_hops_fee_msat : u64 ,
@@ -3171,19 +3176,19 @@ where
31713176 } ) ;
31723177
31733178 // 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 ;
31753180 // Do not consider candidate hops that would exceed the maximum path length.
31763181 let path_length_to_node = next_hops_path_length
31773182 + 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 ;
31793184
31803185 // Do not consider candidates that exceed the maximum total cltv expiry limit.
31813186 // In order to already account for some of the privacy enhancing random CLTV
31823187 // expiry delta offset we add on top later, we subtract a rough estimate
31833188 // (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 )
31853190 . 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 ) ;
31873192 let hop_total_cltv_delta = ( next_hops_cltv_delta as u32 )
31883193 . saturating_add ( candidate. cltv_expiry_delta ( ) ) ;
31893194 let exceeds_cltv_delta_limit = hop_total_cltv_delta > max_total_cltv_expiry_delta;
@@ -3202,15 +3207,15 @@ where
32023207 #[ allow( unused_comparisons) ] // next_hops_path_htlc_minimum_msat is 0 in some calls so rustc complains
32033208 let may_overpay_to_meet_path_minimum_msat =
32043209 ( 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 ( ) ) ||
32063211 ( 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) ;
32083213
32093214 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) ,
32113216 None => match candidate. blinded_hint_idx ( ) {
32123217 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 ) )
32143219 } ,
32153220 None => false ,
32163221 } ,
@@ -3324,15 +3329,15 @@ where
33243329 }
33253330
33263331 // 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 {
33283333 if should_log_candidate {
33293334 log_trace ! ( logger, "Ignoring {} due to exceeding max total routing fee limit." , LoggedCandidateHop ( & candidate) ) ;
33303335
33313336 if let Some ( _) = first_hop_details {
33323337 log_trace ! ( logger,
33333338 "First hop candidate routing fee: {}. Limit: {}" ,
33343339 total_fee_msat,
3335- max_total_routing_fee_msat,
3340+ params . max_total_routing_fee_msat,
33363341 ) ;
33373342 }
33383343 }
0 commit comments