watchtower/wtwire/init: use feature.ValidateRequired

This allows us to remove the custom error type originally implemented
for this purpose.
This commit is contained in:
Conner Fromknecht 2020-01-08 12:26:00 -08:00
parent 0f9023256e
commit 2510ec00f5
No known key found for this signature in database
GPG Key ID: E7D737B67FA592C7
2 changed files with 5 additions and 29 deletions

View File

@ -5,6 +5,7 @@ import (
"io"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/lightningnetwork/lnd/feature"
"github.com/lightningnetwork/lnd/lnwire"
)
@ -92,12 +93,7 @@ func (msg *Init) CheckRemoteInit(remoteInit *Init,
// Check that the remote peer doesn't have any required connection
// feature bits that we ourselves are unaware of.
unknownConnFeatures := remoteConnFeatures.UnknownRequiredFeatures()
if len(unknownConnFeatures) > 0 {
return NewErrUnknownRequiredFeatures(unknownConnFeatures...)
}
return nil
return feature.ValidateRequired(remoteConnFeatures)
}
// ErrUnknownChainHash signals that the remote Init has a different chain hash
@ -116,24 +112,3 @@ func NewErrUnknownChainHash(hash chainhash.Hash) *ErrUnknownChainHash {
func (e *ErrUnknownChainHash) Error() string {
return fmt.Sprintf("remote init has unknown chain hash: %s", e.hash)
}
// ErrUnknownRequiredFeatures signals that the remote Init has required feature
// bits that were unknown to us.
type ErrUnknownRequiredFeatures struct {
unknownFeatures []lnwire.FeatureBit
}
// NewErrUnknownRequiredFeatures creates an ErrUnknownRequiredFeatures using the
// remote Init's required features that were unknown to us.
func NewErrUnknownRequiredFeatures(
unknownFeatures ...lnwire.FeatureBit) *ErrUnknownRequiredFeatures {
return &ErrUnknownRequiredFeatures{unknownFeatures}
}
// Error returns a human-readable error displaying the unknown required feature
// bits.
func (e *ErrUnknownRequiredFeatures) Error() string {
return fmt.Sprintf("remote init has unknown required features: %v",
e.unknownFeatures)
}

View File

@ -5,6 +5,7 @@ import (
"github.com/btcsuite/btcd/chaincfg"
"github.com/btcsuite/btcd/chaincfg/chainhash"
"github.com/lightningnetwork/lnd/feature"
"github.com/lightningnetwork/lnd/lnwire"
"github.com/lightningnetwork/lnd/watchtower/wtwire"
)
@ -60,8 +61,8 @@ var checkRemoteInitTests = []checkRemoteInitTest{
lHash: testnetChainHash,
rFeatures: lnwire.NewRawFeatureVector(lnwire.GossipQueriesRequired),
rHash: testnetChainHash,
expErr: wtwire.NewErrUnknownRequiredFeatures(
lnwire.GossipQueriesRequired,
expErr: feature.NewErrUnknownRequired(
[]lnwire.FeatureBit{lnwire.GossipQueriesRequired},
),
},
}