Skip to content

Commit

Permalink
Require explicit channel type negotiation
Browse files Browse the repository at this point in the history
This feature was introduced by lightning/bolts#880
and the feature bit was added in lightning/bolts#906

We also clean up the channel state machine to leverage the feature bits
added in #237
  • Loading branch information
t-bast committed Feb 4, 2022
1 parent fce2986 commit 713f8c3
Show file tree
Hide file tree
Showing 50 changed files with 2,688 additions and 556 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ object TestConstants {

object Alice {
private val entropy = Hex.decode("0101010101010101010101010101010101010101010101010101010101010101")
val mnemonics = MnemonicCode.toMnemonics(entropy)
val seed = MnemonicCode.toSeed(mnemonics, "").toByteVector32()
private val mnemonics = MnemonicCode.toMnemonics(entropy)
private val seed = MnemonicCode.toSeed(mnemonics, "").toByteVector32()

val keyManager = LocalKeyManager(seed, Block.RegtestGenesisBlock.hash)
val walletParams = WalletParams(NodeUri(randomKey().publicKey(), "alice.com", 9735), trampolineFees, InvoiceDefaultRoutingFees(1_000.msat, 100, CltvExpiryDelta(144)))
Expand All @@ -53,13 +53,12 @@ object TestConstants {
Feature.Wumbo to FeatureSupport.Optional,
Feature.StaticRemoteKey to FeatureSupport.Mandatory,
Feature.AnchorOutputs to FeatureSupport.Mandatory,
Feature.ChannelType to FeatureSupport.Mandatory,
Feature.TrampolinePayment to FeatureSupport.Optional,
Feature.ZeroReserveChannels to FeatureSupport.Optional,
Feature.ZeroConfChannels to FeatureSupport.Optional,
Feature.WakeUpNotificationClient to FeatureSupport.Optional,
Feature.PayToOpenClient to FeatureSupport.Optional,
Feature.TrustedSwapInClient to FeatureSupport.Optional,
Feature.ChannelBackupClient to FeatureSupport.Optional,
Feature.WakeUpNotificationProvider to FeatureSupport.Optional,
Feature.PayToOpenProvider to FeatureSupport.Optional,
Feature.TrustedSwapInProvider to FeatureSupport.Optional,
Feature.ChannelBackupProvider to FeatureSupport.Optional,
),
dustLimit = 1_100.sat,
maxRemoteDustLimit = 1_500.sat,
Expand Down Expand Up @@ -100,7 +99,7 @@ object TestConstants {
enableTrampolinePayment = true
)

val closingPubKeyInfo = keyManager.closingPubkeyScript(PublicKey.Generator)
private val closingPubKeyInfo = keyManager.closingPubkeyScript(PublicKey.Generator)
val channelParams: LocalParams = PeerChannels.makeChannelParams(
nodeParams,
defaultFinalScriptPubkey = ByteVector(closingPubKeyInfo.second),
Expand All @@ -112,7 +111,7 @@ object TestConstants {
object Bob {
private val entropy = Hex.decode("0202020202020202020202020202020202020202020202020202020202020202")
val mnemonics = MnemonicCode.toMnemonics(entropy)
val seed = MnemonicCode.toSeed(mnemonics, "").toByteVector32()
private val seed = MnemonicCode.toSeed(mnemonics, "").toByteVector32()
val keyManager = LocalKeyManager(seed, Block.RegtestGenesisBlock.hash)
val walletParams = WalletParams(NodeUri(randomKey().publicKey(), "bob.com", 9735), trampolineFees, InvoiceDefaultRoutingFees(1_000.msat, 100, CltvExpiryDelta(144)))
val nodeParams = NodeParams(
Expand All @@ -129,9 +128,8 @@ object TestConstants {
Feature.Wumbo to FeatureSupport.Optional,
Feature.StaticRemoteKey to FeatureSupport.Mandatory,
Feature.AnchorOutputs to FeatureSupport.Mandatory,
Feature.ChannelType to FeatureSupport.Mandatory,
Feature.TrampolinePayment to FeatureSupport.Optional,
Feature.ZeroReserveChannels to FeatureSupport.Optional,
Feature.ZeroConfChannels to FeatureSupport.Optional,
Feature.WakeUpNotificationClient to FeatureSupport.Optional,
Feature.PayToOpenClient to FeatureSupport.Optional,
Feature.TrustedSwapInClient to FeatureSupport.Optional,
Expand Down Expand Up @@ -176,7 +174,7 @@ object TestConstants {
enableTrampolinePayment = true
)

val closingPubKeyInfo = keyManager.closingPubkeyScript(PublicKey.Generator)
private val closingPubKeyInfo = keyManager.closingPubkeyScript(PublicKey.Generator)
val channelParams: LocalParams = PeerChannels.makeChannelParams(
nodeParams,
defaultFinalScriptPubkey = ByteVector(closingPubKeyInfo.second),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public suspend fun CoroutineScope.newPeer(
}

val yourLastPerCommitmentSecret = state.commitments.remotePerCommitmentSecrets.lastIndex?.let { state.commitments.remotePerCommitmentSecrets.getHash(it) } ?: ByteVector32.Zeroes
val channelKeyPath = peer.nodeParams.keyManager.channelKeyPath(state.commitments.localParams, state.commitments.channelVersion)
val channelKeyPath = peer.nodeParams.keyManager.channelKeyPath(state.commitments.localParams, state.commitments.channelConfig)
val myCurrentPerCommitmentPoint = peer.nodeParams.keyManager.commitmentPoint(channelKeyPath, state.commitments.localCommit.index)

val channelReestablish = ChannelReestablish(
Expand Down
7 changes: 7 additions & 0 deletions src/commonMain/kotlin/fr/acinq/lightning/Features.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ sealed class Feature {
override val mandatory get() = 20
}

@Serializable
object ChannelType : Feature() {
override val rfcName get() = "option_channel_type"
override val mandatory get() = 44
}

// The following features have not been standardised, hence the high feature bits to avoid conflicts.

@Serializable
Expand Down Expand Up @@ -222,6 +228,7 @@ data class Features(val activated: Map<Feature, FeatureSupport>, val unknown: Se
Feature.BasicMultiPartPayment,
Feature.Wumbo,
Feature.AnchorOutputs,
Feature.ChannelType,
Feature.TrampolinePayment,
Feature.ZeroReserveChannels,
Feature.ZeroConfChannels,
Expand Down
1 change: 1 addition & 0 deletions src/commonMain/kotlin/fr/acinq/lightning/NodeParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ data class NodeParams(
init {
require(features.hasFeature(Feature.VariableLengthOnion, FeatureSupport.Mandatory)) { "${Feature.VariableLengthOnion.rfcName} should be mandatory" }
require(features.hasFeature(Feature.PaymentSecret, FeatureSupport.Mandatory)) { "${Feature.PaymentSecret.rfcName} should be mandatory" }
require(features.hasFeature(Feature.ChannelType, FeatureSupport.Mandatory)) { "${Feature.ChannelType.rfcName} should be mandatory" }
Features.validateFeatureGraph(features)
}
}
Loading

0 comments on commit 713f8c3

Please sign in to comment.