-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1041 from lightninglabs/funding-fast-fail
tapchannel: check for feature bits before opening chans
- Loading branch information
Showing
5 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package taprootassets | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/btcsuite/btcd/btcec/v2" | ||
"github.com/lightninglabs/lndclient" | ||
"github.com/lightninglabs/taproot-assets/tapchannel" | ||
"github.com/lightningnetwork/lnd/lnwire" | ||
"github.com/lightningnetwork/lnd/routing/route" | ||
) | ||
|
||
// LndFeatureBitVerifier is a struct that verifies that the feature bits of a | ||
// target connected peer, using our registered lnd node. | ||
type LndFeatureBitVerifier struct { | ||
lnd *lndclient.LndServices | ||
} | ||
|
||
// NewLndFeatureBitVerifier creates a new LndFeatureBitVerifier instance. | ||
func NewLndFeatureBitVerifier( | ||
lnd *lndclient.LndServices) *LndFeatureBitVerifier { | ||
|
||
return &LndFeatureBitVerifier{ | ||
lnd: lnd, | ||
} | ||
} | ||
|
||
// HasFeature returns true if the peer has the given feature bit set. If the | ||
// peer can't be found, then ErrNoPeer is returned. | ||
func (l *LndFeatureBitVerifier) HasFeature(ctx context.Context, | ||
peerPub btcec.PublicKey, bit lnwire.FeatureBit) (bool, error) { | ||
|
||
peerBytes := route.NewVertex(&peerPub) | ||
|
||
peers, err := l.lnd.Client.ListPeers(ctx) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
for _, peer := range peers { | ||
if peer.Pubkey != peerBytes { | ||
continue | ||
} | ||
|
||
return peer.Features.HasFeature(bit), nil | ||
} | ||
|
||
// If we get to this point, we weren't able to find the peer. | ||
return false, tapchannel.ErrNoPeer | ||
} | ||
|
||
// A compile-time check to ensure that LndFeatureBitVerifier implements the | ||
// FeatureBitVerifier interface. | ||
var _ tapchannel.FeatureBitVerifer = (*LndFeatureBitVerifier)(nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters