@@ -1074,26 +1074,30 @@ fn three_f64_pow_3(a: f64, b: f64, c: f64) -> (f64, f64, f64) {
10741074/// 
10751075/// Must not return a numerator or denominator greater than 2^31 for arguments less than 2^31. 
10761076/// 
1077+ /// `total_inflight_amount_msat` includes the amount of the HTLC and any HTLCs in flight over the 
1078+ /// channel. 
1079+ /// 
10771080/// min_zero_implies_no_successes signals that a `min_liquidity_msat` of 0 means we've not 
10781081/// (recently) seen an HTLC successfully complete over this channel. 
10791082#[ inline( always) ]  
10801083fn  success_probability ( 
1081- 	amount_msat :  u64 ,  min_liquidity_msat :  u64 ,  max_liquidity_msat :  u64 ,  capacity_msat :  u64 , 
1082- 	params :  & ProbabilisticScoringFeeParameters ,  min_zero_implies_no_successes :  bool , 
1084+ 	total_inflight_amount_msat :  u64 ,  min_liquidity_msat :  u64 ,  max_liquidity_msat :  u64 , 
1085+ 	capacity_msat :  u64 ,  params :  & ProbabilisticScoringFeeParameters , 
1086+ 	min_zero_implies_no_successes :  bool , 
10831087)  -> ( u64 ,  u64 )  { 
1084- 	debug_assert ! ( min_liquidity_msat <= amount_msat ) ; 
1085- 	debug_assert ! ( amount_msat  < max_liquidity_msat) ; 
1088+ 	debug_assert ! ( min_liquidity_msat <= total_inflight_amount_msat ) ; 
1089+ 	debug_assert ! ( total_inflight_amount_msat  < max_liquidity_msat) ; 
10861090	debug_assert ! ( max_liquidity_msat <= capacity_msat) ; 
10871091
10881092	let  ( numerator,  mut  denominator)  =
10891093		if  params. linear_success_probability  { 
1090- 			( max_liquidity_msat - amount_msat , 
1094+ 			( max_liquidity_msat - total_inflight_amount_msat , 
10911095				( max_liquidity_msat - min_liquidity_msat) . saturating_add ( 1 ) ) 
10921096		}  else  { 
10931097			let  capacity = capacity_msat as  f64 ; 
10941098			let  min = ( min_liquidity_msat as  f64 )  / capacity; 
10951099			let  max = ( max_liquidity_msat as  f64 )  / capacity; 
1096- 			let  amount = ( amount_msat  as  f64 )  / capacity; 
1100+ 			let  amount = ( total_inflight_amount_msat  as  f64 )  / capacity; 
10971101
10981102			// Assume the channel has a probability density function of (x - 0.5)^2 for values from 
10991103			// 0 to 1 (where 1 is the channel's full capacity). The success probability given some 
@@ -1779,7 +1783,7 @@ mod bucketed_history {
17791783
17801784		#[ inline]  
17811785		pub ( super )  fn  calculate_success_probability_times_billion ( 
1782- 			& self ,  params :  & ProbabilisticScoringFeeParameters ,  amount_msat :  u64 , 
1786+ 			& self ,  params :  & ProbabilisticScoringFeeParameters ,  total_inflight_amount_msat :  u64 , 
17831787			capacity_msat :  u64 
17841788		)  -> Option < u64 >  { 
17851789			// If historical penalties are enabled, we try to calculate a probability of success 
@@ -1789,7 +1793,7 @@ mod bucketed_history {
17891793			// state). For each pair, we calculate the probability as if the bucket's corresponding 
17901794			// min- and max- liquidity bounds were our current liquidity bounds and then multiply 
17911795			// that probability by the weight of the selected buckets. 
1792- 			let  payment_pos = amount_to_pos ( amount_msat ,  capacity_msat) ; 
1796+ 			let  payment_pos = amount_to_pos ( total_inflight_amount_msat ,  capacity_msat) ; 
17931797			if  payment_pos >= POSITION_TICKS  {  return  None ;  } 
17941798
17951799			let  min_liquidity_offset_history_buckets =
0 commit comments