Skip to content

Commit

Permalink
Add optional feerate for swap-in (#486)
Browse files Browse the repository at this point in the history
Library integrator is responsible for providing a value. If set, Phoenix will use it to iniate a splice (which only happens in the swap-in case). Otherwise we don't start the swap-in coroutine.
  • Loading branch information
pm47 authored Jun 22, 2023
1 parent 4b65d7a commit e7a38da
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class Peer(

val currentTipFlow = MutableStateFlow<Pair<Int, BlockHeader>?>(null)
val onChainFeeratesFlow = MutableStateFlow<OnChainFeerates?>(null)
val swapInFeeratesFlow = MutableStateFlow<FeeratePerKw?>(null)

private val _channelLogger = nodeParams.loggerFactory.newLogger(ChannelState::class)
private suspend fun ChannelState.process(cmd: ChannelCommand): Pair<ChannelState, List<ChannelAction>> {
Expand Down Expand Up @@ -226,6 +227,8 @@ class Peer(
}
logger.info { "restored ${channelIds.size} channels" }
launch {
// wait to have a swap-in feerate available
swapInFeeratesFlow.filterNotNull().first()
watchSwapInWallet(bootChannels)
}
launch {
Expand Down Expand Up @@ -941,7 +944,7 @@ class Peer(
is RequestChannelOpen -> {
when (val channel = channels.values.firstOrNull { it is Normal }) {
is ChannelStateWithCommitments -> {
val targetFeerate = onChainFeeratesFlow.filterNotNull().first().fundingFeerate
val targetFeerate = swapInFeeratesFlow.filterNotNull().first()
val weight = FundingContributions.computeWeightPaid(isInitiator = true, commitment = channel.commitments.active.first(), walletInputs = cmd.walletInputs, localOutputs = emptyList())
val (feerate, fee) = watcher.client.computeSpliceCpfpFeerate(channel.commitments, targetFeerate, spliceWeight = weight, logger)

Expand Down

0 comments on commit e7a38da

Please sign in to comment.