mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
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:
parent
0f9023256e
commit
2510ec00f5
@ -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)
|
||||
}
|
||||
|
@ -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},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user