From 9faa2dd5077386a023be3cf12aa0f22ed84831a7 Mon Sep 17 00:00:00 2001 From: t-bast Date: Tue, 24 Sep 2024 04:11:03 +0200 Subject: [PATCH] Clarify fee credit check --- .../lightning/payment/IncomingPaymentHandler.kt | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/commonMain/kotlin/fr/acinq/lightning/payment/IncomingPaymentHandler.kt b/src/commonMain/kotlin/fr/acinq/lightning/payment/IncomingPaymentHandler.kt index 2d9dc2cfe..1ad78651c 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/payment/IncomingPaymentHandler.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/payment/IncomingPaymentHandler.kt @@ -247,12 +247,16 @@ class IncomingPaymentHandler(val nodeParams: NodeParams, val db: PaymentsDb) { // in terms of fees we need to pay, otherwise we may not have enough to actually pay the liquidity fees. val maxFeerate = currentFeerate * AddLiquidityForIncomingPayment.SpliceWithNoBalanceFeerateRatio val maxLiquidityFees = fundingRate.fees(maxFeerate, requestedAmount, requestedAmount, isChannelCreation = true).total.toMilliSatoshi() - val feeCreditThreshold = when (val policy = nodeParams.liquidityPolicy.value) { - LiquidityPolicy.Disable -> maxLiquidityFees - is LiquidityPolicy.Auto -> maxLiquidityFees.min(policy.maxAllowedFeeCredit) + val maxFeeCredit = when (val policy = nodeParams.liquidityPolicy.value) { + LiquidityPolicy.Disable -> 0.msat + is LiquidityPolicy.Auto -> policy.maxAllowedFeeCredit } - val amountBelowThreshold = (willAddHtlcParts.map { it.amount }.sum() + currentFeeCredit) <= feeCreditThreshold - featureOk && amountBelowThreshold + val nextFeeCredit = willAddHtlcParts.map { it.amount }.sum() + currentFeeCredit + val cannotCoverLiquidityFees = nextFeeCredit <= maxLiquidityFees + val isBelowMaxFeeCredit = nextFeeCredit <= maxFeeCredit + val assessment = featureOk && cannotCoverLiquidityFees && isBelowMaxFeeCredit + logger.info { "fee credit assessment: result=$assessment featureOk=$featureOk cannotCoverLiquidityFees=$cannotCoverLiquidityFees isBelowMaxFeeCredit=$isBelowMaxFeeCredit (nextFeeCredit=$nextFeeCredit, maxLiquidityFees=$maxLiquidityFees, maxFeeCredit=$maxFeeCredit)" } + assessment } when { addToFeeCredit -> {