From 62bd5c85aa8093aba981aa36d61f12630355df26 Mon Sep 17 00:00:00 2001 From: pm47 Date: Fri, 15 Dec 2023 11:39:35 +0100 Subject: [PATCH] make caller provide liquidity lease rate In the future it will be provided by the peer in an `Init` TLV. --- src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt b/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt index 659ff7b17..dac54df8c 100644 --- a/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt +++ b/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt @@ -168,7 +168,6 @@ class Peer( val currentTipFlow = MutableStateFlow?>(null) val onChainFeeratesFlow = MutableStateFlow(null) val swapInFeeratesFlow = MutableStateFlow(null) - val liquidityRatesFlow = MutableStateFlow(null) private val _channelLogger = nodeParams.loggerFactory.newLogger(ChannelState::class) private suspend fun ChannelState.process(cmd: ChannelCommand): Pair> { @@ -542,12 +541,11 @@ class Peer( * Estimate the actual feerate to use (and corresponding fee to pay) to purchase inbound liquidity with a splice * that reaches the target feerate. */ - suspend fun estimateFeeForInboundLiquidity(amount: Satoshi, targetFeerate: FeeratePerKw): Pair? { + suspend fun estimateFeeForInboundLiquidity(amount: Satoshi, targetFeerate: FeeratePerKw, leaseRate: LiquidityAds.LeaseRate): Pair? { return channels.values .filterIsInstance() .firstOrNull() ?.let { channel -> - val leaseRate = liquidityRatesFlow.filterNotNull().first { it.leaseDuration == 0 } val weight = FundingContributions.computeWeightPaid(isInitiator = true, commitment = channel.commitments.active.first(), walletInputs = emptyList(), localOutputs = emptyList()) + leaseRate.fundingWeight // The mining fee below pays for the entirety of the splice transaction, including inputs and outputs from the liquidity provider. val (actualFeerate, miningFee) = watcher.client.computeSpliceCpfpFeerate(channel.commitments, targetFeerate, spliceWeight = weight, logger) @@ -597,13 +595,12 @@ class Peer( } } - suspend fun requestInboundLiquidity(amount: Satoshi, feerate: FeeratePerKw): ChannelCommand.Commitment.Splice.Response? { + suspend fun requestInboundLiquidity(amount: Satoshi, feerate: FeeratePerKw, leaseRate: LiquidityAds.LeaseRate): ChannelCommand.Commitment.Splice.Response? { return channels.values .filterIsInstance() .firstOrNull() ?.let { channel -> val leaseStart = currentTipFlow.filterNotNull().first().first - val leaseRate = liquidityRatesFlow.filterNotNull().first { it.leaseDuration == 0 } val spliceCommand = ChannelCommand.Commitment.Splice.Request( replyTo = CompletableDeferred(), spliceIn = null, @@ -882,7 +879,6 @@ class Peer( else -> { theirInit = msg _connectionState.value = Connection.ESTABLISHED - msg.liquidityRates.forEach { liquidityRatesFlow.emit(it) } _channels = _channels.mapValues { entry -> val (state1, actions) = entry.value.process(ChannelCommand.Connected(ourInit, theirInit!!)) processActions(entry.key, peerConnection, actions)