funding: don't negotiate on known types

This commit is contained in:
Oliver Gugger 2021-11-24 17:44:28 +01:00
parent 32d0ecdca1
commit 6ee7913662
No known key found for this signature in database
GPG key ID: 8E4256593F177720
2 changed files with 16 additions and 14 deletions

View file

@ -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

View file

@ -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