From 6ee79136622d3ac89d8135bffadc1f111728e241 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Wed, 24 Nov 2021 17:44:28 +0100 Subject: [PATCH] funding: don't negotiate on known types --- funding/commitment_type_negotiation.go | 17 ++++++----------- funding/commitment_type_negotiation_test.go | 13 ++++++++++--- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/funding/commitment_type_negotiation.go b/funding/commitment_type_negotiation.go index 091c6fcbb..392b7c824 100644 --- a/funding/commitment_type_negotiation.go +++ b/funding/commitment_type_negotiation.go @@ -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 diff --git a/funding/commitment_type_negotiation_test.go b/funding/commitment_type_negotiation_test.go index c9ac25a7a..c3032685c 100644 --- a/funding/commitment_type_negotiation_test.go +++ b/funding/commitment_type_negotiation_test.go @@ -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