Skip to content

Commit

Permalink
Implement simple taproot channels
Browse files Browse the repository at this point in the history
  • Loading branch information
sstone committed Jul 15, 2024
1 parent efe0ac1 commit b940cee
Show file tree
Hide file tree
Showing 47 changed files with 2,713 additions and 408 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ val currentOs = org.gradle.internal.os.OperatingSystem.current()

kotlin {

val bitcoinKmpVersion = "0.19.0" // when upgrading bitcoin-kmp, keep secpJniJvmVersion in sync!
val bitcoinKmpVersion = "0.20.0-SNAPSHOT" // when upgrading bitcoin-kmp, keep secpJniJvmVersion in sync!
val secpJniJvmVersion = "0.15.0"

val serializationVersion = "1.6.2"
Expand Down
12 changes: 10 additions & 2 deletions src/commonMain/kotlin/fr/acinq/lightning/Features.kt
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,12 @@ sealed class Feature {
override val scopes: Set<FeatureScope> get() = setOf(FeatureScope.Init, FeatureScope.Node)
}

@Serializable
object SimpleTaprootStaging : Feature() {
override val rfcName get() = "option_simple_taproot_staging"
override val mandatory get() = 180
override val scopes: Set<FeatureScope> get() = setOf(FeatureScope.Init, FeatureScope.Node)
}
}

@Serializable
Expand Down Expand Up @@ -337,7 +343,8 @@ data class Features(val activated: Map<Feature, FeatureSupport>, val unknown: Se
Feature.ChannelBackupClient,
Feature.ChannelBackupProvider,
Feature.ExperimentalSplice,
Feature.Quiescence
Feature.Quiescence,
Feature.SimpleTaprootStaging
)

operator fun invoke(bytes: ByteVector): Features = invoke(bytes.toByteArray())
Expand Down Expand Up @@ -369,7 +376,8 @@ data class Features(val activated: Map<Feature, FeatureSupport>, val unknown: Se
Feature.BasicMultiPartPayment to listOf(Feature.PaymentSecret),
Feature.AnchorOutputs to listOf(Feature.StaticRemoteKey),
Feature.TrampolinePayment to listOf(Feature.PaymentSecret),
Feature.ExperimentalTrampolinePayment to listOf(Feature.PaymentSecret)
Feature.ExperimentalTrampolinePayment to listOf(Feature.PaymentSecret),
Feature.SimpleTaprootStaging to listOf(Feature.AnchorOutputs, Feature.StaticRemoteKey)
)

class FeatureException(message: String) : IllegalArgumentException(message)
Expand Down
3 changes: 2 additions & 1 deletion src/commonMain/kotlin/fr/acinq/lightning/NodeParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ data class NodeParams(
Feature.PayToOpenClient to FeatureSupport.Optional,
Feature.ChannelBackupClient to FeatureSupport.Optional,
Feature.ExperimentalSplice to FeatureSupport.Optional,
Feature.Quiescence to FeatureSupport.Mandatory
Feature.Quiescence to FeatureSupport.Mandatory,
Feature.SimpleTaprootStaging to FeatureSupport.Optional
),
dustLimit = 546.sat,
maxRemoteDustLimit = 600.sat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ data class InvalidPushAmount (override val channelId: Byte
data class InvalidMaxAcceptedHtlcs (override val channelId: ByteVector32, val maxAcceptedHtlcs: Int, val max: Int) : ChannelException(channelId, "invalid max_accepted_htlcs=$maxAcceptedHtlcs (max=$max)")
data class InvalidChannelType (override val channelId: ByteVector32, val ourChannelType: ChannelType, val theirChannelType: ChannelType) : ChannelException(channelId, "invalid channel_type=${theirChannelType.name}, expected channel_type=${ourChannelType.name}")
data class MissingChannelType (override val channelId: ByteVector32) : ChannelException(channelId, "option_channel_type was negotiated but channel_type is missing")
data class MissingNextLocalNonces (override val channelId: ByteVector32) : ChannelException(channelId, "missing next local nonces")
data class DustLimitTooSmall (override val channelId: ByteVector32, val dustLimit: Satoshi, val min: Satoshi) : ChannelException(channelId, "dustLimit=$dustLimit is too small (min=$min)")
data class DustLimitTooLarge (override val channelId: ByteVector32, val dustLimit: Satoshi, val max: Satoshi) : ChannelException(channelId, "dustLimit=$dustLimit is too large (max=$max)")
data class ToSelfDelayTooHigh (override val channelId: ByteVector32, val toSelfDelay: CltvExpiryDelta, val max: CltvExpiryDelta) : ChannelException(channelId, "unreasonable to_self_delay=$toSelfDelay (max=$max)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ sealed class ChannelType {
override val features: Set<Feature> get() = setOf(Feature.StaticRemoteKey, Feature.AnchorOutputs, Feature.ZeroReserveChannels)
}

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

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

data class UnsupportedChannelType(val featureBits: Features) : ChannelType() {
Expand All @@ -71,6 +80,8 @@ sealed class ChannelType {
// NB: Bolt 2: features must exactly match in order to identify a channel type.
fun fromFeatures(features: Features): ChannelType = when (features) {
// @formatter:off
Features(Feature.StaticRemoteKey to FeatureSupport.Mandatory, Feature.AnchorOutputs to FeatureSupport.Mandatory, Feature.ZeroReserveChannels to FeatureSupport.Mandatory, Feature.SimpleTaprootStaging to FeatureSupport.Mandatory) -> SupportedChannelType.SimpleTaprootStagingZeroReserve
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) -> SupportedChannelType.AnchorOutputsZeroReserve
Features(Feature.StaticRemoteKey to FeatureSupport.Mandatory, Feature.AnchorOutputs to FeatureSupport.Mandatory) -> SupportedChannelType.AnchorOutputs
else -> UnsupportedChannelType(features)
Expand Down
Loading

0 comments on commit b940cee

Please sign in to comment.