-
Notifications
You must be signed in to change notification settings - Fork 282
Separate internal channel config from features #1852
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming is inconsistent
LocalParams.defaultFinalScriptPubKeyandRemoteParams.shutdownScriptEither:
LocalParams.defaultFinalScriptPubKeyandRemoteParams.upfrontFinalScriptPubKeyor
LocalParams.defaultShutdownScriptandRemoteParams.upfrontShutdownScriptI would keep the
upfrontin any case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's revisit the naming afterwards.