Skip to content

Commit

Permalink
Add a specific channel type for taproot channels
Browse files Browse the repository at this point in the history
  • Loading branch information
sstone committed Dec 10, 2024
1 parent 430e00f commit b183e9c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ data class Features(val activated: Map<Feature, FeatureSupport>, val unknown: Se
Feature.ExperimentalTrampolinePayment to listOf(Feature.PaymentSecret),
Feature.OnTheFlyFunding to listOf(Feature.ExperimentalSplice),
Feature.FundingFeeCredit to listOf(Feature.OnTheFlyFunding),
Feature.SimpleTaprootStaging to listOf(Feature.AnchorOutputs, Feature.StaticRemoteKey)
Feature.SimpleTaprootStaging to listOf(Feature.StaticRemoteKey)
)

class FeatureException(message: String) : IllegalArgumentException(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ sealed class ChannelType {

object SimpleTaprootStaging : SupportedChannelType() {
override val name: String get() = "simple_taproot_staging"
override val features: Set<Feature> get() = setOf(Feature.StaticRemoteKey, Feature.AnchorOutputs, Feature.SimpleTaprootStaging)
override val features: Set<Feature> get() = setOf(Feature.StaticRemoteKey, Feature.AnchorOutputs, Feature.ZeroReserveChannels, Feature.SimpleTaprootStaging)
}
}

Expand All @@ -77,7 +77,7 @@ sealed class ChannelType {
// @formatter:off
Features(Feature.StaticRemoteKey to FeatureSupport.Mandatory, Feature.AnchorOutputs to FeatureSupport.Mandatory, Feature.ZeroReserveChannels to FeatureSupport.Mandatory) -> SupportedChannelType.AnchorOutputsZeroReserve
Features(Feature.StaticRemoteKey to FeatureSupport.Mandatory, Feature.AnchorOutputs to FeatureSupport.Mandatory) -> SupportedChannelType.AnchorOutputs
Features(Feature.StaticRemoteKey to FeatureSupport.Mandatory, Feature.AnchorOutputs to FeatureSupport.Mandatory, Feature.SimpleTaprootStaging to FeatureSupport.Mandatory) -> SupportedChannelType.SimpleTaprootStaging
Features(Feature.StaticRemoteKey to FeatureSupport.Mandatory, Feature.AnchorOutputs to FeatureSupport.Mandatory, Feature.ZeroReserveChannels to FeatureSupport.Mandatory, Feature.SimpleTaprootStaging to FeatureSupport.Mandatory) -> SupportedChannelType.SimpleTaprootStaging
else -> UnsupportedChannelType(features)
// @formatter:on
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package fr.acinq.lightning.channel.states

import fr.acinq.lightning.Feature
import fr.acinq.lightning.Features
import fr.acinq.lightning.blockchain.BITCOIN_FUNDING_DEPTHOK
import fr.acinq.lightning.blockchain.BITCOIN_FUNDING_SPENT
import fr.acinq.lightning.blockchain.WatchConfirmed
Expand Down Expand Up @@ -52,7 +54,7 @@ data object WaitForInit : ChannelState() {
buildSet {
add(ChannelTlv.ChannelTypeTlv(cmd.channelType))
cmd.requestRemoteFunding?.let { add(ChannelTlv.RequestFundingTlv(it)) }
if (cmd.channelType == ChannelType.SupportedChannelType.SimpleTaprootStaging) add(
if (Features.canUseFeature(cmd.localParams.features, cmd.remoteInit.features, Feature.SimpleTaprootStaging)) add(
ChannelTlv.NextLocalNoncesTlv(
listOf(
channelKeys.verificationNonce(0, 0).second,
Expand Down
14 changes: 12 additions & 2 deletions modules/core/src/commonMain/kotlin/fr/acinq/lightning/io/Peer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,11 @@ class Peer(
// We ask our peer to pay the commit tx fees.
val localParams = LocalParams(nodeParams, isChannelOpener = true, payCommitTxFees = false)
val channelFlags = ChannelFlags(announceChannel = false, nonInitiatorPaysCommitFees = true)
val channelType = if (Features.canUseFeature(localParams.features, theirInit!!.features, Feature.SimpleTaprootStaging)) {
ChannelType.SupportedChannelType.SimpleTaprootStaging
} else {
ChannelType.SupportedChannelType.AnchorOutputsZeroReserve
}
val initCommand = ChannelCommand.Init.Initiator(
replyTo = CompletableDeferred(),
fundingAmount = localFundingAmount,
Expand All @@ -1367,7 +1372,7 @@ class Peer(
remoteInit = theirInit!!,
channelFlags = channelFlags,
channelConfig = ChannelConfig.standard,
channelType = ChannelType.SupportedChannelType.AnchorOutputsZeroReserve,
channelType = channelType,
requestRemoteFunding = requestRemoteFunding,
channelOrigin = Origin.OnChainWallet(cmd.walletInputs.map { it.outPoint }.toSet(), cmd.totalAmount.toMilliSatoshi(), fees),
)
Expand Down Expand Up @@ -1472,6 +1477,11 @@ class Peer(
}
else -> {
logger.info { "requesting on-the-fly channel for paymentHash=${cmd.paymentHash} feerate=$fundingFeerate fee=${totalFees.total} paymentType=${paymentDetails.paymentType}" }
val channelType = if (Features.canUseFeature(localParams.features, theirInit!!.features, Feature.SimpleTaprootStaging)) {
ChannelType.SupportedChannelType.SimpleTaprootStaging
} else {
ChannelType.SupportedChannelType.AnchorOutputsZeroReserve
}
val (state, actions) = WaitForInit.process(
ChannelCommand.Init.Initiator(
replyTo = CompletableDeferred(),
Expand All @@ -1483,7 +1493,7 @@ class Peer(
remoteInit = theirInit!!,
channelFlags = channelFlags,
channelConfig = ChannelConfig.standard,
channelType = ChannelType.SupportedChannelType.AnchorOutputsZeroReserve,
channelType = channelType,
requestRemoteFunding = LiquidityAds.RequestFunding(cmd.requestedAmount, cmd.fundingRate, paymentDetails),
channelOrigin = Origin.OffChainPayment(cmd.preimage, cmd.paymentAmount, totalFees),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package fr.acinq.lightning.channel.states

import fr.acinq.bitcoin.*
import fr.acinq.lightning.Feature
import fr.acinq.lightning.Lightning.randomBytes32
import fr.acinq.lightning.Lightning.randomKey
import fr.acinq.lightning.blockchain.*
Expand Down Expand Up @@ -154,6 +155,9 @@ open class SpliceTestsCommon : LightningTestSuite() {

@Test
fun `splice funds out -- would go below reserve`() {
if (defaultChannelType.toFeatures().hasFeature(Feature.ZeroReserveChannels)) {
return
}
val (alice, bob) = reachNormalWithConfirmedFundingTx(defaultChannelType)
val (alice1, bob1, _) = setupHtlcs(alice, bob)
val cmd = createSpliceOutRequest(810_000.sat)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ class WaitForFundingCreatedTestsCommon : LightningTestSuite() {
actionsBob3.has<ChannelAction.Storage.StoreState>()
assertIs<WaitForFundingSigned>(alice2.state)
assertIs<WaitForFundingSigned>(bob3.state)
assertEquals(alice2.state.channelParams.channelFeatures, ChannelFeatures(setOf(Feature.StaticRemoteKey, Feature.AnchorOutputs, Feature.DualFunding, Feature.SimpleTaprootStaging)))
assertEquals(bob3.state.channelParams.channelFeatures, ChannelFeatures(setOf(Feature.StaticRemoteKey, Feature.AnchorOutputs, Feature.DualFunding, Feature.SimpleTaprootStaging)))
assertEquals(alice2.state.channelParams.channelFeatures, ChannelFeatures(setOf(Feature.StaticRemoteKey, Feature.AnchorOutputs, Feature.ZeroReserveChannels, Feature.DualFunding, Feature.SimpleTaprootStaging)))
assertEquals(bob3.state.channelParams.channelFeatures, ChannelFeatures(setOf(Feature.StaticRemoteKey, Feature.AnchorOutputs, Feature.ZeroReserveChannels, Feature.DualFunding, Feature.SimpleTaprootStaging)))
verifyCommits(alice2.state.signingSession, bob3.state.signingSession, TestConstants.aliceFundingAmount.toMilliSatoshi(), 0.msat)
}

Expand Down

0 comments on commit b183e9c

Please sign in to comment.