-
Notifications
You must be signed in to change notification settings - Fork 2.3k
lnwire+funding: introduce new protocol extension for explicit commitment type negotiation #5373
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
Closed
wpaulino
wants to merge
11
commits into
lightningnetwork:master
from
wpaulino:explicit-chan-negotiation
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4253ff7
lnwire: introduce new explicit ChannelType TLV record
Roasbeef 822a3af
lnwire: add new ChannelType field as TLV record to Open/AcceptChannel
Roasbeef 55aef0b
lnwire: add new feature bits for explicit channel type negotiation
Roasbeef 268990a
rpc: add new commitment_type field to OpenChannelRequest
Roasbeef 459d7dc
lnwire: extend RawFeatureVector with helper methods
wpaulino de79673
funding: add explicit commitment type negotiation support
wpaulino ce2918e
funding: use explicit commitment type negotiation when possible
Roasbeef 082c019
lntest: replace `commitType` type with rpc alternative
wpaulino 478f640
lntest: use explicit channel commitment negotiation for multi-hop itests
wpaulino 450f2be
lncli: add channel type flag to openchannel command
wpaulino 0c56b07
docs: add explicit channel negotiation text to release notes
wpaulino 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
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
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
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
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,120 @@ | ||
| package funding | ||
|
|
||
| import ( | ||
| "errors" | ||
|
|
||
| "github.com/lightningnetwork/lnd/lnwallet" | ||
| "github.com/lightningnetwork/lnd/lnwire" | ||
| ) | ||
|
|
||
| var ( | ||
| // errUnsupportedExplicitNegotiation is an error returned when explicit | ||
| // channel commitment negotiation is attempted but either peer of the | ||
| // channel does not support it. | ||
| errUnsupportedExplicitNegotiation = errors.New("explicit channel " + | ||
| "type negotiation not supported") | ||
|
|
||
| // errUnsupportedCommitmentType is an error returned when a specific | ||
| // channel commitment type is being explicitly negotiated but either | ||
| // peer of the channel does not support it. | ||
| errUnsupportedChannelType = errors.New("requested channel type " + | ||
| "not supported") | ||
| ) | ||
|
|
||
| // negotiateCommitmentType negotiates the commitment type of a newly opened | ||
| // channel. If a channelType is provided, explicit negotiation for said type | ||
| // will be attempted if the set of both local and remote features support it. | ||
| // Otherwise, implicit negotiation will be attempted. | ||
| func negotiateCommitmentType(channelType *lnwire.ChannelType, | ||
| local, remote *lnwire.FeatureVector) (lnwallet.CommitmentType, error) { | ||
|
|
||
| if channelType != nil { | ||
| if !hasFeatures(local, remote, lnwire.ExplicitChannelTypeOptional) { | ||
| return 0, errUnsupportedExplicitNegotiation | ||
| } | ||
| return explicitNegotiateCommitmentType( | ||
| *channelType, local, remote, | ||
| ) | ||
| } | ||
|
|
||
| return implicitNegotiateCommitmentType(local, remote), nil | ||
| } | ||
|
|
||
| // explicitNegotiateCommitmentType attempts to explicitly negotiate for a | ||
| // specific channel type. Since the channel type is comprised of a set of even | ||
| // feature bits, we also make sure each feature is supported by both peers. An | ||
| // error is returned if either peer does not support said channel type. | ||
| func explicitNegotiateCommitmentType(channelType lnwire.ChannelType, | ||
| local, remote *lnwire.FeatureVector) (lnwallet.CommitmentType, error) { | ||
|
|
||
| channelFeatures := lnwire.RawFeatureVector(channelType) | ||
|
|
||
| switch { | ||
| // Anchors zero fee + static remote key features only. | ||
| case channelFeatures.OnlyContains( | ||
| lnwire.AnchorsZeroFeeHtlcTxRequired, | ||
| lnwire.StaticRemoteKeyRequired, | ||
| ): | ||
| if !hasFeatures( | ||
| local, remote, | ||
| lnwire.AnchorsZeroFeeHtlcTxOptional, | ||
| lnwire.StaticRemoteKeyOptional, | ||
| ) { | ||
| return 0, errUnsupportedChannelType | ||
| } | ||
| return lnwallet.CommitmentTypeAnchorsZeroFeeHtlcTx, nil | ||
|
|
||
| // Static remote key feature only. | ||
| case channelFeatures.OnlyContains(lnwire.StaticRemoteKeyRequired): | ||
| if !hasFeatures(local, remote, lnwire.StaticRemoteKeyOptional) { | ||
| return 0, errUnsupportedChannelType | ||
| } | ||
| return lnwallet.CommitmentTypeTweakless, nil | ||
|
|
||
| // No features, use legacy commitment type. | ||
| case channelFeatures.IsEmpty(): | ||
| return lnwallet.CommitmentTypeLegacy, nil | ||
|
|
||
| default: | ||
| return 0, errUnsupportedChannelType | ||
| } | ||
| } | ||
|
|
||
| // implicitNegotiateCommitmentType negotiates the commitment type of a channel | ||
| // implicitly by choosing the latest type supported by the local and remote | ||
| // fetures. | ||
| func implicitNegotiateCommitmentType(local, | ||
| remote *lnwire.FeatureVector) lnwallet.CommitmentType { | ||
|
|
||
| // If both peers are signalling support for anchor commitments with | ||
| // zero-fee HTLC transactions, we'll use this type. | ||
| if hasFeatures(local, remote, lnwire.AnchorsZeroFeeHtlcTxOptional) { | ||
| return lnwallet.CommitmentTypeAnchorsZeroFeeHtlcTx | ||
| } | ||
|
|
||
| // Since we don't want to support the "legacy" anchor type, we will fall | ||
| // back to static remote key if the nodes don't support the zero fee | ||
| // HTLC tx anchor type. | ||
| // | ||
| // If both nodes are signaling the proper feature bit for tweakless | ||
| // commitments, we'll use that. | ||
| if hasFeatures(local, remote, lnwire.StaticRemoteKeyOptional) { | ||
| return lnwallet.CommitmentTypeTweakless | ||
| } | ||
|
|
||
| // Otherwise we'll fall back to the legacy type. | ||
| return lnwallet.CommitmentTypeLegacy | ||
| } | ||
|
|
||
| // hasFeatures determines whether a set of features is supported by both the set | ||
| // of local and remote features. | ||
| func hasFeatures(local, remote *lnwire.FeatureVector, | ||
| features ...lnwire.FeatureBit) bool { | ||
|
|
||
| for _, feature := range features { | ||
| if !local.HasFeature(feature) || !remote.HasFeature(feature) { | ||
| return false | ||
| } | ||
| } | ||
| return true | ||
| } | ||
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.
Re the existing comment, if a user doesn't set this new value when opening a channel, then we'll default to the old implicit negotiation. IMO instead, we want to map the unknown value (so them not setting a value at all), to our current "default" channel type, and still use the explicit chan negotiation.