mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 09:48:19 +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 (
|
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
|
// errUnsupportedCommitmentType is an error returned when a specific
|
||||||
// channel commitment type is being explicitly negotiated but either
|
// channel commitment type is being explicitly negotiated but either
|
||||||
// peer of the channel does not support it.
|
// peer of the channel does not support it.
|
||||||
|
@ -29,12 +23,13 @@ func negotiateCommitmentType(channelType *lnwire.ChannelType,
|
||||||
local, remote *lnwire.FeatureVector) (lnwallet.CommitmentType, error) {
|
local, remote *lnwire.FeatureVector) (lnwallet.CommitmentType, error) {
|
||||||
|
|
||||||
if channelType != nil {
|
if channelType != nil {
|
||||||
if !hasFeatures(local, remote, lnwire.ExplicitChannelTypeOptional) {
|
// If the peer does know explicit negotiation, let's attempt
|
||||||
return 0, errUnsupportedExplicitNegotiation
|
// that now.
|
||||||
|
if hasFeatures(local, remote, lnwire.ExplicitChannelTypeOptional) {
|
||||||
|
return explicitNegotiateCommitmentType(
|
||||||
|
*channelType, local, remote,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
return explicitNegotiateCommitmentType(
|
|
||||||
*channelType, local, remote,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return implicitNegotiateCommitmentType(local, remote), nil
|
return implicitNegotiateCommitmentType(local, remote), nil
|
||||||
|
|
|
@ -36,7 +36,8 @@ func TestCommitmentTypeNegotiation(t *testing.T) {
|
||||||
lnwire.StaticRemoteKeyOptional,
|
lnwire.StaticRemoteKeyOptional,
|
||||||
lnwire.AnchorsZeroFeeHtlcTxOptional,
|
lnwire.AnchorsZeroFeeHtlcTxOptional,
|
||||||
),
|
),
|
||||||
expectsErr: errUnsupportedExplicitNegotiation,
|
expectsRes: lnwallet.CommitmentTypeAnchorsZeroFeeHtlcTx,
|
||||||
|
expectsErr: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "explicit missing remote commitment feature",
|
name: "explicit missing remote commitment feature",
|
||||||
|
@ -181,8 +182,14 @@ func TestCommitmentTypeNegotiation(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Equal(t, testCase.expectsRes, localType)
|
require.Equal(
|
||||||
require.Equal(t, testCase.expectsRes, remoteType)
|
t, testCase.expectsRes, localType,
|
||||||
|
testCase.name,
|
||||||
|
)
|
||||||
|
require.Equal(
|
||||||
|
t, testCase.expectsRes, remoteType,
|
||||||
|
testCase.name,
|
||||||
|
)
|
||||||
})
|
})
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue