Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Require explicit channel type negotiation #277

Merged
merged 3 commits into from
Feb 4, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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