-
Notifications
You must be signed in to change notification settings - Fork 2k
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
funding: fix channel type negotiation bug #7177
Changes from 5 commits
ec85b5b
e59cd7f
34186de
0ae9c63
a8a50f3
c50d704
e6a2167
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,12 +8,6 @@ import ( | |
) | ||
|
||
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. | ||
|
@@ -22,40 +16,49 @@ var ( | |
) | ||
|
||
// negotiateCommitmentType negotiates the commitment type of a newly opened | ||
// channel. If a channelType is provided, explicit negotiation for said type | ||
// channel. If a desiredChanType 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. Two booleans are | ||
// returned letting the caller know if the option-scid-alias or zero-conf | ||
// channel types were negotiated. | ||
func negotiateCommitmentType(channelType *lnwire.ChannelType, local, | ||
remote *lnwire.FeatureVector, mustBeExplicit bool) (bool, | ||
*lnwire.ChannelType, lnwallet.CommitmentType, error) { | ||
|
||
if channelType != nil { | ||
// If the peer does know explicit negotiation, let's attempt | ||
// that now. | ||
if hasFeatures( | ||
local, remote, lnwire.ExplicitChannelTypeOptional, | ||
) { | ||
|
||
chanType, err := explicitNegotiateCommitmentType( | ||
*channelType, local, remote, | ||
// Otherwise, implicit negotiation will be attempted. | ||
// | ||
// The returned ChannelType is nil when implicit negotiation is used. An error | ||
// is only returned if desiredChanType is not supported. | ||
func negotiateCommitmentType(desiredChanType *lnwire.ChannelType, local, | ||
remote *lnwire.FeatureVector) (*lnwire.ChannelType, | ||
morehouse marked this conversation as resolved.
Show resolved
Hide resolved
|
||
lnwallet.CommitmentType, error) { | ||
|
||
// BOLT#2 specifies we MUST use explicit negotiation if both peers | ||
// signal for it. | ||
if hasFeatures(local, remote, lnwire.ExplicitChannelTypeOptional) { | ||
if desiredChanType != nil { | ||
commitType, err := explicitNegotiateCommitmentType( | ||
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. 👍 |
||
*desiredChanType, local, remote, | ||
) | ||
return true, channelType, chanType, err | ||
} | ||
|
||
// If we're the funder, and we are attempting to use an | ||
// explicit channel type, but the remote party doesn't signal | ||
// the bit, then we actually want to exit here, to ensure the | ||
// user doesn't end up with an unexpected channel type via | ||
// implicit negotiation. | ||
if mustBeExplicit { | ||
return false, nil, 0, errUnsupportedExplicitNegotiation | ||
return desiredChanType, commitType, err | ||
} | ||
|
||
// Explicitly signal the "implicit" negotiation commitment type | ||
// as default when a desired channel type isn't specified. | ||
chanType, commitType := implicitNegotiateCommitmentType(local, | ||
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. Weird line folding, should be: chanType, commitType := implicitNegotiateCommitmentType(
local, remote,
) 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. Fixed in the refactor commit. |
||
remote) | ||
|
||
return chanType, commitType, nil | ||
} | ||
|
||
// Otherwise, we'll use implicit negotiation. In this case, we are | ||
carlaKC marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// restricted to the newest channel type advertised. If the passed-in | ||
// channelType doesn't match what was advertised, we fail. | ||
chanType, commitType := implicitNegotiateCommitmentType(local, remote) | ||
return false, chanType, commitType, nil | ||
|
||
if desiredChanType != nil { | ||
expected := lnwire.RawFeatureVector(*desiredChanType) | ||
actual := lnwire.RawFeatureVector(*chanType) | ||
if !expected.Equals(&actual) { | ||
return nil, 0, errUnsupportedChannelType | ||
} | ||
} | ||
|
||
return nil, commitType, nil | ||
} | ||
|
||
// explicitNegotiateCommitmentType attempts to explicitly negotiate for a | ||
|
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.
Not sure about the removal of this error. In this case the sender will get less explicit error?
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 error only exists due to a previous bandaid-type fix: #6027.
After the fix in this PR, there seems to be little need for the error message. The only way to get non-default channel types is through explicit negotiation. If the peer doesn't support explicit negotiation it also won't support the desired channel type, so it seems just as accurate to return
errUnsupportedChannelType
.The one case where it would potentially make sense to return
errUnsupportedExplicitNegotiation
is when the default channel type matches the desired channel type and the peer doesn't support explicit negotiation. But this PR makes handles that case by using implicit negotiation instead of failing like we did previously.