@@ -2122,13 +2122,14 @@ impl<'a> PaymentPath<'a> {
2122
2122
value_msat + extra_contribution_msat
2123
2123
}
2124
2124
2125
- // Returns the maximum contribution that this path can make to the final value of the payment. May
2126
- // be slightly lower than the actual max due to rounding errors when aggregating fees along the
2127
- // path.
2128
- fn compute_max_final_value_contribution (
2125
+ /// Returns the hop which most limited our maximum contribution as well as the maximum
2126
+ /// contribution this path can make to the final value of the payment.
2127
+ /// May be slightly lower than the actual max due to rounding errors when aggregating fees
2128
+ /// along the path.
2129
+ fn max_final_value_msat (
2129
2130
& self , used_liquidities : & HashMap < CandidateHopId , u64 > , channel_saturation_pow_half : u8
2130
- ) -> u64 {
2131
- let mut max_path_contribution = u64:: MAX ;
2131
+ ) -> ( usize , u64 ) {
2132
+ let mut max_path_contribution = ( 0 , u64:: MAX ) ;
2132
2133
for ( idx, ( hop, _) ) in self . hops . iter ( ) . enumerate ( ) {
2133
2134
let hop_effective_capacity_msat = hop. candidate . effective_capacity ( ) ;
2134
2135
let hop_max_msat = max_htlc_from_capacity (
@@ -2154,7 +2155,9 @@ impl<'a> PaymentPath<'a> {
2154
2155
2155
2156
if let Some ( hop_contribution) = hop_max_final_value_contribution {
2156
2157
let hop_contribution: u64 = hop_contribution. try_into ( ) . unwrap_or ( u64:: MAX ) ;
2157
- max_path_contribution = core:: cmp:: min ( hop_contribution, max_path_contribution) ;
2158
+ if hop_contribution <= max_path_contribution. 1 {
2159
+ max_path_contribution = ( idx, hop_contribution) ;
2160
+ }
2158
2161
} else { debug_assert ! ( false ) ; }
2159
2162
}
2160
2163
@@ -3310,9 +3313,8 @@ where L::Target: Logger {
3310
3313
// recompute the fees again, so that if that's the case, we match the currently
3311
3314
// underpaid htlc_minimum_msat with fees.
3312
3315
debug_assert_eq ! ( payment_path. get_value_msat( ) , value_contribution_msat) ;
3313
- let max_path_contribution_msat = payment_path. compute_max_final_value_contribution (
3314
- & used_liquidities, channel_saturation_pow_half
3315
- ) ;
3316
+ let ( lowest_value_contrib_hop, max_path_contribution_msat) =
3317
+ payment_path. max_final_value_msat ( & used_liquidities, channel_saturation_pow_half) ;
3316
3318
let desired_value_contribution = cmp:: min ( max_path_contribution_msat, final_value_msat) ;
3317
3319
value_contribution_msat = payment_path. update_value_and_recompute_fees ( desired_value_contribution) ;
3318
3320
@@ -3348,6 +3350,8 @@ where L::Target: Logger {
3348
3350
* used_liquidities. entry ( CandidateHopId :: Clear ( ( scid, false ) ) ) . or_default ( ) = exhausted;
3349
3351
* used_liquidities. entry ( CandidateHopId :: Clear ( ( scid, true ) ) ) . or_default ( ) = exhausted;
3350
3352
}
3353
+ } else {
3354
+ log_trace ! ( logger, "Path was limited to {}msat by hop {}" , max_path_contribution_msat, lowest_value_contrib_hop) ;
3351
3355
}
3352
3356
3353
3357
// Track the total amount all our collected paths allow to send so that we know
0 commit comments