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