-
Notifications
You must be signed in to change notification settings - Fork 269
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
Separate internal channel config from features #1852
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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).
- Loading branch information
There are no files selected for viewing
Large diffs are not rendered by default.
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 ChannelConfigOptions(activated: Set[ChannelConfigOption]) { | ||||||
|
||||||
def hasOption(option: ChannelConfigOption): Boolean = activated.contains(option) | ||||||
|
||||||
} | ||||||
|
||||||
object ChannelConfigOptions { | ||||||
|
||||||
def standard: ChannelConfigOptions = ChannelConfigOptions(activated = Set(FundingPubKeyBasedChannelKeyPath)) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not a val here?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No reason, this should be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 4e0c814 |
||||||
|
||||||
def apply(options: ChannelConfigOption*): ChannelConfigOptions = ChannelConfigOptions(Set.from(options)) | ||||||
|
||||||
/** | ||||||
* 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" | ||||||
} | ||||||
|
||||||
} |
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)) | ||
} | ||
|
||
} |
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.
Nit:
or
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.
Why? It's really a configuration option...it's not a complete configuration so
ChannelConfig
feels weird IMO, andChannelOption
is on the contrary a bit too vague, isn't it?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.
It's just that everywhere we are using:
channelConfig: ChannelConfigOptions
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.
But it's different, it's because it's a
ChannelConfigOptions
, which is a collection ofChannelConfigOption
.I agree this one could be renamed
ChannelConfigOptions
->ChannelConfig
, but not the trait on individual options.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.
Done in 4e0c814