@@ -1236,35 +1236,42 @@ DirectedChannelLiquidity< L, HT, T> {
12361236 let max_liquidity_msat = self . max_liquidity_msat ( ) ;
12371237 let min_liquidity_msat = core:: cmp:: min ( self . min_liquidity_msat ( ) , max_liquidity_msat) ;
12381238
1239- let mut res = if total_inflight_amount_msat <= min_liquidity_msat {
1240- 0
1241- } else if total_inflight_amount_msat >= max_liquidity_msat {
1242- // Equivalent to hitting the else clause below with the amount equal to the effective
1243- // capacity and without any certainty on the liquidity upper bound, plus the
1244- // impossibility penalty.
1245- let negative_log10_times_2048 = NEGATIVE_LOG10_UPPER_BOUND * 2048 ;
1246- Self :: combined_penalty_msat ( amount_msat, negative_log10_times_2048,
1247- score_params. liquidity_penalty_multiplier_msat ,
1248- score_params. liquidity_penalty_amount_multiplier_msat )
1249- . saturating_add ( score_params. considered_impossible_penalty_msat )
1250- } else {
1251- let ( numerator, denominator) = success_probability (
1252- total_inflight_amount_msat, min_liquidity_msat, max_liquidity_msat,
1253- available_capacity, score_params, false ,
1254- ) ;
1255- if denominator - numerator < denominator / PRECISION_LOWER_BOUND_DENOMINATOR {
1256- // If the failure probability is < 1.5625% (as 1 - numerator/denominator < 1/64),
1257- // don't bother trying to use the log approximation as it gets too noisy to be
1258- // particularly helpful, instead just round down to 0.
1259- 0
1239+ let mut res = 0 ;
1240+ if score_params. liquidity_penalty_multiplier_msat != 0 ||
1241+ score_params. liquidity_penalty_amount_multiplier_msat != 0 {
1242+ if total_inflight_amount_msat <= min_liquidity_msat {
1243+ // If the in-flight is less than the minimum liquidity estimate, we don't assign a
1244+ // liquidity penalty at all (as the success probability is 100%).
1245+ } else if total_inflight_amount_msat >= max_liquidity_msat {
1246+ // Equivalent to hitting the else clause below with the amount equal to the effective
1247+ // capacity and without any certainty on the liquidity upper bound, plus the
1248+ // impossibility penalty.
1249+ let negative_log10_times_2048 = NEGATIVE_LOG10_UPPER_BOUND * 2048 ;
1250+ res = Self :: combined_penalty_msat ( amount_msat, negative_log10_times_2048,
1251+ score_params. liquidity_penalty_multiplier_msat ,
1252+ score_params. liquidity_penalty_amount_multiplier_msat ) ;
12601253 } else {
1261- let negative_log10_times_2048 =
1262- log_approx:: negative_log10_times_2048 ( numerator, denominator) ;
1263- Self :: combined_penalty_msat ( amount_msat, negative_log10_times_2048,
1264- score_params. liquidity_penalty_multiplier_msat ,
1265- score_params. liquidity_penalty_amount_multiplier_msat )
1254+ let ( numerator, denominator) = success_probability (
1255+ total_inflight_amount_msat, min_liquidity_msat, max_liquidity_msat,
1256+ available_capacity, score_params, false ,
1257+ ) ;
1258+ if denominator - numerator < denominator / PRECISION_LOWER_BOUND_DENOMINATOR {
1259+ // If the failure probability is < 1.5625% (as 1 - numerator/denominator < 1/64),
1260+ // don't bother trying to use the log approximation as it gets too noisy to be
1261+ // particularly helpful, instead just round down to 0.
1262+ } else {
1263+ let negative_log10_times_2048 =
1264+ log_approx:: negative_log10_times_2048 ( numerator, denominator) ;
1265+ res = Self :: combined_penalty_msat ( amount_msat, negative_log10_times_2048,
1266+ score_params. liquidity_penalty_multiplier_msat ,
1267+ score_params. liquidity_penalty_amount_multiplier_msat ) ;
1268+ }
12661269 }
1267- } ;
1270+ }
1271+
1272+ if total_inflight_amount_msat >= max_liquidity_msat {
1273+ res = res. saturating_add ( score_params. considered_impossible_penalty_msat ) ;
1274+ }
12681275
12691276 if total_inflight_amount_msat >= available_capacity {
12701277 // We're trying to send more than the capacity, use a max penalty.
0 commit comments