-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate internal channel config from features (#1852)
* Separate internal channel config from features Our current ChannelVersion field mixes two unrelated concepts: channel features (as defined in Bolt 9) and channel internals (such as custom key derivation). It is more future-proof to separate these two unrelated concepts and will make it easier to implement channel types (see lightning/bolts#880). * Add shutdown script to channel remote params This will be necessary when we implement `upfront_shutdown_script`. This field can be set to `None` for all current channels as we don't support the feature yet.
- Loading branch information
Showing
44 changed files
with
848 additions
and
495 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 37 additions & 35 deletions
72
eclair-core/src/main/scala/fr/acinq/eclair/channel/Channel.scala
Large diffs are not rendered by default.
Oops, something went wrong.
58 changes: 58 additions & 0 deletions
58
eclair-core/src/main/scala/fr/acinq/eclair/channel/ChannelConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright 2021 ACINQ SAS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package fr.acinq.eclair.channel | ||
|
||
/** | ||
* Created by t-bast on 24/06/2021. | ||
*/ | ||
|
||
/** | ||
* Internal configuration option impacting the channel's structure or behavior. | ||
* This must be set when creating the channel and cannot be changed afterwards. | ||
*/ | ||
trait ChannelConfigOption { | ||
// @formatter:off | ||
def supportBit: Int | ||
def name: String | ||
// @formatter:on | ||
} | ||
|
||
case class ChannelConfig(options: Set[ChannelConfigOption]) { | ||
|
||
def hasOption(option: ChannelConfigOption): Boolean = options.contains(option) | ||
|
||
} | ||
|
||
object ChannelConfig { | ||
|
||
val standard: ChannelConfig = ChannelConfig(options = Set(FundingPubKeyBasedChannelKeyPath)) | ||
|
||
def apply(opts: ChannelConfigOption*): ChannelConfig = ChannelConfig(Set.from(opts)) | ||
|
||
/** | ||
* If set, the channel's BIP32 key path will be deterministically derived from the funding public key. | ||
* It makes it very easy to retrieve funds when channel data has been lost: | ||
* - connect to your peer and use option_data_loss_protect to get them to publish their remote commit tx | ||
* - retrieve the commit tx from the bitcoin network, extract your funding pubkey from its witness data | ||
* - recompute your channel keys and spend your output | ||
*/ | ||
case object FundingPubKeyBasedChannelKeyPath extends ChannelConfigOption { | ||
override val supportBit: Int = 0 | ||
override val name: String = "funding_pubkey_based_channel_keypath" | ||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
eclair-core/src/main/scala/fr/acinq/eclair/channel/ChannelFeatures.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2021 ACINQ SAS | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package fr.acinq.eclair.channel | ||
|
||
import fr.acinq.eclair.Features.{AnchorOutputs, StaticRemoteKey, Wumbo} | ||
import fr.acinq.eclair.transactions.Transactions.{AnchorOutputsCommitmentFormat, CommitmentFormat, DefaultCommitmentFormat} | ||
import fr.acinq.eclair.{Feature, FeatureSupport, Features} | ||
|
||
/** | ||
* Created by t-bast on 24/06/2021. | ||
*/ | ||
|
||
/** | ||
* Subset of Bolt 9 features used to configure a channel and applicable over the lifetime of that channel. | ||
* Even if one of these features is later disabled at the connection level, it will still apply to the channel until the | ||
* channel is upgraded or closed. | ||
*/ | ||
case class ChannelFeatures(features: Features) { | ||
|
||
/** True if our main output in the remote commitment is directly sent (without any delay) to one of our wallet addresses. */ | ||
val paysDirectlyToWallet: Boolean = { | ||
features.hasFeature(Features.StaticRemoteKey) && !features.hasFeature(Features.AnchorOutputs) | ||
} | ||
|
||
/** Format of the channel transactions. */ | ||
val commitmentFormat: CommitmentFormat = { | ||
if (features.hasFeature(AnchorOutputs)) { | ||
AnchorOutputsCommitmentFormat | ||
} else { | ||
DefaultCommitmentFormat | ||
} | ||
} | ||
|
||
def hasFeature(feature: Feature): Boolean = features.hasFeature(feature) | ||
|
||
} | ||
|
||
object ChannelFeatures { | ||
|
||
/** Pick the channel features that should be used based on local and remote feature bits. */ | ||
def pickChannelFeatures(localFeatures: Features, remoteFeatures: Features): ChannelFeatures = { | ||
// NB: we don't include features that can be safely activated/deactivated without impacting the channel's operation, | ||
// such as option_dataloss_protect or option_shutdown_anysegwit. | ||
val availableFeatures: Seq[Feature] = Seq( | ||
StaticRemoteKey, | ||
Wumbo, | ||
AnchorOutputs, | ||
).filter(f => Features.canUseFeature(localFeatures, remoteFeatures, f)) | ||
ChannelFeatures(Features(availableFeatures.map(f => f -> FeatureSupport.Mandatory).toMap)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.