mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 01:36:24 +01:00
funding: don't negotiate on known types
This commit is contained in:
parent
32d0ecdca1
commit
6ee7913662
2 changed files with 16 additions and 14 deletions
|
@ -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.
|
||||
|
@ -29,12 +23,13 @@ func negotiateCommitmentType(channelType *lnwire.ChannelType,
|
|||
local, remote *lnwire.FeatureVector) (lnwallet.CommitmentType, error) {
|
||||
|
||||
if channelType != nil {
|
||||
if !hasFeatures(local, remote, lnwire.ExplicitChannelTypeOptional) {
|
||||
return 0, errUnsupportedExplicitNegotiation
|
||||
// If the peer does know explicit negotiation, let's attempt
|
||||
// that now.
|
||||
if hasFeatures(local, remote, lnwire.ExplicitChannelTypeOptional) {
|
||||
return explicitNegotiateCommitmentType(
|
||||
*channelType, local, remote,
|
||||
)
|
||||
}
|
||||
return explicitNegotiateCommitmentType(
|
||||
*channelType, local, remote,
|
||||
)
|
||||
}
|
||||
|
||||
return implicitNegotiateCommitmentType(local, remote), nil
|
||||
|
|
|
@ -36,7 +36,8 @@ func TestCommitmentTypeNegotiation(t *testing.T) {
|
|||
lnwire.StaticRemoteKeyOptional,
|
||||
lnwire.AnchorsZeroFeeHtlcTxOptional,
|
||||
),
|
||||
expectsErr: errUnsupportedExplicitNegotiation,
|
||||
expectsRes: lnwallet.CommitmentTypeAnchorsZeroFeeHtlcTx,
|
||||
expectsErr: nil,
|
||||
},
|
||||
{
|
||||
name: "explicit missing remote commitment feature",
|
||||
|
@ -181,8 +182,14 @@ func TestCommitmentTypeNegotiation(t *testing.T) {
|
|||
return
|
||||
}
|
||||
|
||||
require.Equal(t, testCase.expectsRes, localType)
|
||||
require.Equal(t, testCase.expectsRes, remoteType)
|
||||
require.Equal(
|
||||
t, testCase.expectsRes, localType,
|
||||
testCase.name,
|
||||
)
|
||||
require.Equal(
|
||||
t, testCase.expectsRes, remoteType,
|
||||
testCase.name,
|
||||
)
|
||||
})
|
||||
if !ok {
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue