Skip to content

Commit

Permalink
Clarify fee credit check
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bast committed Sep 24, 2024
1 parent 2b3062f commit 5d21e08
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down

0 comments on commit 5d21e08

Please sign in to comment.