Skip to content

Commit c5b5b03

Browse files
authored
Refactor transactions for taproot compatibility (#800)
We refactor our transactions handling and our closing data to match the changes made in `eclair` to support taproot channels and commitment upgrades during splices. The architecture matches the change made in eclair, up to changes from ACINQ/eclair#3118
1 parent 9c32cc2 commit c5b5b03

File tree

74 files changed

+6015
-5922
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+6015
-5922
lines changed

modules/core/src/commonMain/kotlin/fr/acinq/lightning/NodeEvents.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import fr.acinq.bitcoin.Satoshi
77
import fr.acinq.lightning.blockchain.electrum.WalletState
88
import fr.acinq.lightning.channel.ChannelManagementFees
99
import fr.acinq.lightning.channel.InteractiveTxParams
10-
import fr.acinq.lightning.channel.SharedFundingInput
1110
import fr.acinq.lightning.channel.states.ChannelStateWithCommitments
1211
import fr.acinq.lightning.channel.states.Normal
1312
import fr.acinq.lightning.channel.states.WaitForFundingCreated
@@ -58,7 +57,7 @@ sealed interface LiquidityEvents : NodeEvents {
5857
sealed interface SensitiveTaskEvents : NodeEvents {
5958
sealed class TaskIdentifier {
6059
data class InteractiveTx(val channelId: ByteVector32, val fundingTxIndex: Long) : TaskIdentifier() {
61-
constructor(fundingParams: InteractiveTxParams) : this(fundingParams.channelId, (fundingParams.sharedInput as? SharedFundingInput.Multisig2of2)?.fundingTxIndex?.let { it + 1 } ?: 0)
60+
constructor(fundingParams: InteractiveTxParams) : this(fundingParams.channelId, fundingParams.sharedInput?.fundingTxIndex?.let { it + 1 } ?: 0)
6261
}
6362
data class IncomingMultiPartPayment(val paymentHash: ByteVector32) : TaskIdentifier()
6463
}

modules/core/src/commonMain/kotlin/fr/acinq/lightning/blockchain/IClient.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ suspend fun IClient.computeSpliceCpfpFeerate(commitments: Commitments, targetFee
3131
val (parentsWeight, parentsFees) = commitments.all
3232
.takeWhile { getConfirmations(it.fundingTxId).let { confirmations -> confirmations == null || confirmations == 0 } } // we check for null in case the tx has been evicted
3333
.fold(Pair(0, 0.sat)) { (parentsWeight, parentsFees), commitment ->
34-
val weight = when (commitment.localFundingStatus) {
35-
// weight will be underestimated if the transaction is not fully signed
36-
is LocalFundingStatus.UnconfirmedFundingTx -> commitment.localFundingStatus.signedTx?.weight() ?: commitment.localFundingStatus.sharedTx.tx.buildUnsignedTx().weight()
37-
is LocalFundingStatus.ConfirmedFundingTx -> commitment.localFundingStatus.signedTx.weight()
34+
when (commitment.localFundingStatus) {
35+
is LocalFundingStatus.UnconfirmedFundingTx -> {
36+
// Note that the weight will be underestimated if the transaction is not fully signed.
37+
val weight = commitment.localFundingStatus.signedTx?.weight() ?: commitment.localFundingStatus.sharedTx.tx.buildUnsignedTx().weight()
38+
Pair(parentsWeight + weight, parentsFees + commitment.localFundingStatus.fee)
39+
}
40+
// We filtered confirmed transactions before, so this case shouldn't happen.
41+
is LocalFundingStatus.ConfirmedFundingTx -> Pair(parentsWeight, parentsFees)
3842
}
39-
Pair(parentsWeight + weight, parentsFees + commitment.localFundingStatus.fee)
4043
}
4144
val totalWeight = parentsWeight + spliceWeight
4245
val totalFees = Transactions.weight2fee(targetFeerate, totalWeight)

modules/core/src/commonMain/kotlin/fr/acinq/lightning/blockchain/electrum/SwapInManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class SwapInManager(private var reservedUtxos: Set<OutPoint>, private val logger
7373
.forEach { fundingStatus ->
7474
when (fundingStatus) {
7575
is LocalFundingStatus.UnconfirmedFundingTx -> addAll(fundingStatus.sharedTx.tx.localInputs.map { it.outPoint })
76-
is LocalFundingStatus.ConfirmedFundingTx -> addAll(fundingStatus.signedTx.txIn.map { it.outPoint })
76+
is LocalFundingStatus.ConfirmedFundingTx -> addAll(fundingStatus.spentInputs)
7777
}
7878
}
7979
else -> {}

modules/core/src/commonMain/kotlin/fr/acinq/lightning/channel/ChannelAction.kt

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,9 @@ sealed class ChannelAction {
3232
CommitTx,
3333
HtlcSuccessTx,
3434
HtlcTimeoutTx,
35+
HtlcDelayedTx,
3536
ClaimHtlcSuccessTx,
3637
ClaimHtlcTimeoutTx,
37-
ClaimLocalAnchorOutputTx,
38-
ClaimRemoteAnchorOutputTx,
3938
ClaimLocalDelayedOutputTx,
4039
ClaimRemoteDelayedOutputTx,
4140
MainPenaltyTx,
@@ -47,20 +46,19 @@ sealed class ChannelAction {
4746
constructor(txinfo: Transactions.TransactionWithInputInfo) : this(
4847
tx = txinfo.tx,
4948
txType = when (txinfo) {
50-
is Transactions.TransactionWithInputInfo.CommitTx -> Type.CommitTx
51-
is Transactions.TransactionWithInputInfo.HtlcTx.HtlcSuccessTx -> Type.HtlcSuccessTx
52-
is Transactions.TransactionWithInputInfo.HtlcTx.HtlcTimeoutTx -> Type.HtlcTimeoutTx
53-
is Transactions.TransactionWithInputInfo.ClaimHtlcTx.ClaimHtlcSuccessTx -> Type.ClaimHtlcSuccessTx
54-
is Transactions.TransactionWithInputInfo.ClaimHtlcTx.ClaimHtlcTimeoutTx -> Type.ClaimHtlcTimeoutTx
55-
is Transactions.TransactionWithInputInfo.ClaimAnchorOutputTx.ClaimLocalAnchorOutputTx -> Type.ClaimLocalAnchorOutputTx
56-
is Transactions.TransactionWithInputInfo.ClaimAnchorOutputTx.ClaimRemoteAnchorOutputTx -> Type.ClaimRemoteAnchorOutputTx
57-
is Transactions.TransactionWithInputInfo.ClaimLocalDelayedOutputTx -> Type.ClaimLocalDelayedOutputTx
58-
is Transactions.TransactionWithInputInfo.ClaimRemoteCommitMainOutputTx.ClaimRemoteDelayedOutputTx -> Type.ClaimRemoteDelayedOutputTx
59-
is Transactions.TransactionWithInputInfo.MainPenaltyTx -> Type.MainPenaltyTx
60-
is Transactions.TransactionWithInputInfo.HtlcPenaltyTx -> Type.HtlcPenaltyTx
61-
is Transactions.TransactionWithInputInfo.ClaimHtlcDelayedOutputPenaltyTx -> Type.ClaimHtlcDelayedOutputPenaltyTx
62-
is Transactions.TransactionWithInputInfo.ClosingTx -> Type.ClosingTx
63-
is Transactions.TransactionWithInputInfo.SpliceTx -> Type.FundingTx
49+
is Transactions.CommitTx -> Type.CommitTx
50+
is Transactions.HtlcSuccessTx -> Type.HtlcSuccessTx
51+
is Transactions.HtlcTimeoutTx -> Type.HtlcTimeoutTx
52+
is Transactions.HtlcDelayedTx -> Type.HtlcDelayedTx
53+
is Transactions.ClaimHtlcSuccessTx -> Type.ClaimHtlcSuccessTx
54+
is Transactions.ClaimHtlcTimeoutTx -> Type.ClaimHtlcTimeoutTx
55+
is Transactions.ClaimLocalDelayedOutputTx -> Type.ClaimLocalDelayedOutputTx
56+
is Transactions.ClaimRemoteDelayedOutputTx -> Type.ClaimRemoteDelayedOutputTx
57+
is Transactions.MainPenaltyTx -> Type.MainPenaltyTx
58+
is Transactions.HtlcPenaltyTx -> Type.HtlcPenaltyTx
59+
is Transactions.ClaimHtlcDelayedOutputPenaltyTx -> Type.ClaimHtlcDelayedOutputPenaltyTx
60+
is Transactions.ClosingTx -> Type.ClosingTx
61+
is Transactions.SpliceTx -> Type.FundingTx
6462
}
6563
)
6664
// endregion

modules/core/src/commonMain/kotlin/fr/acinq/lightning/channel/ChannelCommand.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fr.acinq.lightning.channel
22

33
import fr.acinq.bitcoin.*
44
import fr.acinq.lightning.CltvExpiry
5+
import fr.acinq.lightning.CltvExpiryDelta
56
import fr.acinq.lightning.MilliSatoshi
67
import fr.acinq.lightning.blockchain.WatchTriggered
78
import fr.acinq.lightning.blockchain.electrum.WalletState
@@ -28,7 +29,12 @@ sealed class ChannelCommand {
2829
val walletInputs: List<WalletState.Utxo>,
2930
val commitTxFeerate: FeeratePerKw,
3031
val fundingTxFeerate: FeeratePerKw,
31-
val localParams: LocalParams,
32+
val localChannelParams: LocalChannelParams,
33+
val dustLimit: Satoshi,
34+
val htlcMinimum: MilliSatoshi,
35+
val maxHtlcValueInFlightMsat: Long,
36+
val maxAcceptedHtlcs: Int,
37+
val toRemoteDelay: CltvExpiryDelta,
3238
val remoteInit: InitMessage,
3339
val channelFlags: ChannelFlags,
3440
val channelConfig: ChannelConfig,
@@ -44,7 +50,12 @@ sealed class ChannelCommand {
4450
val temporaryChannelId: ByteVector32,
4551
val fundingAmount: Satoshi,
4652
val walletInputs: List<WalletState.Utxo>,
47-
val localParams: LocalParams,
53+
val localParams: LocalChannelParams,
54+
val dustLimit: Satoshi,
55+
val htlcMinimum: MilliSatoshi,
56+
val maxHtlcValueInFlightMsat: Long,
57+
val maxAcceptedHtlcs: Int,
58+
val toRemoteDelay: CltvExpiryDelta,
4859
val channelConfig: ChannelConfig,
4960
val remoteInit: InitMessage,
5061
val fundingRates: LiquidityAds.WillFundRates?

0 commit comments

Comments
 (0)