Skip to content

Commit 49b31e3

Browse files
authored
Require explicit channel type negotiation (#277)
* Rename ChannelTypes -> ChannelData And move commands to a new ChannelCommands file. This commit doesn't contain any logic changes. * Require explicit channel type negotiation 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
1 parent 13c7143 commit 49b31e3

Some content is hidden

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

51 files changed

+2699
-575
lines changed

lightning-kmp-test-fixtures/src/commonMain/kotlin/fr/acinq/lightning/tests/TestConstants.kt

+11-13
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ object TestConstants {
3434

3535
object Alice {
3636
private val entropy = Hex.decode("0101010101010101010101010101010101010101010101010101010101010101")
37-
val mnemonics = MnemonicCode.toMnemonics(entropy)
38-
val seed = MnemonicCode.toSeed(mnemonics, "").toByteVector32()
37+
private val mnemonics = MnemonicCode.toMnemonics(entropy)
38+
private val seed = MnemonicCode.toSeed(mnemonics, "").toByteVector32()
3939

4040
val keyManager = LocalKeyManager(seed, Block.RegtestGenesisBlock.hash)
4141
val walletParams = WalletParams(NodeUri(randomKey().publicKey(), "alice.com", 9735), trampolineFees, InvoiceDefaultRoutingFees(1_000.msat, 100, CltvExpiryDelta(144)))
@@ -53,13 +53,12 @@ object TestConstants {
5353
Feature.Wumbo to FeatureSupport.Optional,
5454
Feature.StaticRemoteKey to FeatureSupport.Mandatory,
5555
Feature.AnchorOutputs to FeatureSupport.Mandatory,
56+
Feature.ChannelType to FeatureSupport.Mandatory,
5657
Feature.TrampolinePayment to FeatureSupport.Optional,
57-
Feature.ZeroReserveChannels to FeatureSupport.Optional,
58-
Feature.ZeroConfChannels to FeatureSupport.Optional,
59-
Feature.WakeUpNotificationClient to FeatureSupport.Optional,
60-
Feature.PayToOpenClient to FeatureSupport.Optional,
61-
Feature.TrustedSwapInClient to FeatureSupport.Optional,
62-
Feature.ChannelBackupClient to FeatureSupport.Optional,
58+
Feature.WakeUpNotificationProvider to FeatureSupport.Optional,
59+
Feature.PayToOpenProvider to FeatureSupport.Optional,
60+
Feature.TrustedSwapInProvider to FeatureSupport.Optional,
61+
Feature.ChannelBackupProvider to FeatureSupport.Optional,
6362
),
6463
dustLimit = 1_100.sat,
6564
maxRemoteDustLimit = 1_500.sat,
@@ -100,7 +99,7 @@ object TestConstants {
10099
enableTrampolinePayment = true
101100
)
102101

103-
val closingPubKeyInfo = keyManager.closingPubkeyScript(PublicKey.Generator)
102+
private val closingPubKeyInfo = keyManager.closingPubkeyScript(PublicKey.Generator)
104103
val channelParams: LocalParams = PeerChannels.makeChannelParams(
105104
nodeParams,
106105
defaultFinalScriptPubkey = ByteVector(closingPubKeyInfo.second),
@@ -112,7 +111,7 @@ object TestConstants {
112111
object Bob {
113112
private val entropy = Hex.decode("0202020202020202020202020202020202020202020202020202020202020202")
114113
val mnemonics = MnemonicCode.toMnemonics(entropy)
115-
val seed = MnemonicCode.toSeed(mnemonics, "").toByteVector32()
114+
private val seed = MnemonicCode.toSeed(mnemonics, "").toByteVector32()
116115
val keyManager = LocalKeyManager(seed, Block.RegtestGenesisBlock.hash)
117116
val walletParams = WalletParams(NodeUri(randomKey().publicKey(), "bob.com", 9735), trampolineFees, InvoiceDefaultRoutingFees(1_000.msat, 100, CltvExpiryDelta(144)))
118117
val nodeParams = NodeParams(
@@ -129,9 +128,8 @@ object TestConstants {
129128
Feature.Wumbo to FeatureSupport.Optional,
130129
Feature.StaticRemoteKey to FeatureSupport.Mandatory,
131130
Feature.AnchorOutputs to FeatureSupport.Mandatory,
131+
Feature.ChannelType to FeatureSupport.Mandatory,
132132
Feature.TrampolinePayment to FeatureSupport.Optional,
133-
Feature.ZeroReserveChannels to FeatureSupport.Optional,
134-
Feature.ZeroConfChannels to FeatureSupport.Optional,
135133
Feature.WakeUpNotificationClient to FeatureSupport.Optional,
136134
Feature.PayToOpenClient to FeatureSupport.Optional,
137135
Feature.TrustedSwapInClient to FeatureSupport.Optional,
@@ -176,7 +174,7 @@ object TestConstants {
176174
enableTrampolinePayment = true
177175
)
178176

179-
val closingPubKeyInfo = keyManager.closingPubkeyScript(PublicKey.Generator)
177+
private val closingPubKeyInfo = keyManager.closingPubkeyScript(PublicKey.Generator)
180178
val channelParams: LocalParams = PeerChannels.makeChannelParams(
181179
nodeParams,
182180
defaultFinalScriptPubkey = ByteVector(closingPubKeyInfo.second),

lightning-kmp-test-fixtures/src/commonMain/kotlin/fr/acinq/lightning/tests/io/peer/builders.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public suspend fun CoroutineScope.newPeer(
136136
}
137137

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

142142
val channelReestablish = ChannelReestablish(

src/commonMain/kotlin/fr/acinq/lightning/Features.kt

+7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ sealed class Feature {
9191
override val mandatory get() = 20
9292
}
9393

94+
@Serializable
95+
object ChannelType : Feature() {
96+
override val rfcName get() = "option_channel_type"
97+
override val mandatory get() = 44
98+
}
99+
94100
// The following features have not been standardised, hence the high feature bits to avoid conflicts.
95101

96102
@Serializable
@@ -222,6 +228,7 @@ data class Features(val activated: Map<Feature, FeatureSupport>, val unknown: Se
222228
Feature.BasicMultiPartPayment,
223229
Feature.Wumbo,
224230
Feature.AnchorOutputs,
231+
Feature.ChannelType,
225232
Feature.TrampolinePayment,
226233
Feature.ZeroReserveChannels,
227234
Feature.ZeroConfChannels,

src/commonMain/kotlin/fr/acinq/lightning/NodeParams.kt

+1
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ data class NodeParams(
120120
init {
121121
require(features.hasFeature(Feature.VariableLengthOnion, FeatureSupport.Mandatory)) { "${Feature.VariableLengthOnion.rfcName} should be mandatory" }
122122
require(features.hasFeature(Feature.PaymentSecret, FeatureSupport.Mandatory)) { "${Feature.PaymentSecret.rfcName} should be mandatory" }
123+
require(features.hasFeature(Feature.ChannelType, FeatureSupport.Mandatory)) { "${Feature.ChannelType.rfcName} should be mandatory" }
123124
Features.validateFeatureGraph(features)
124125
}
125126
}

0 commit comments

Comments
 (0)