mirror of
https://github.com/lightninglabs/loop.git
synced 2026-08-13 12:33:03 +02:00
Merge pull request #777 from hieblmi/refactor-select-hop-hints
utils: refactor SelectHopHints to use narrower interface
This commit is contained in:
commit
174a6b888b
3 changed files with 16 additions and 16 deletions
|
|
@ -683,7 +683,8 @@ func (s *Client) LoopInQuote(ctx context.Context,
|
|||
// Because the Private flag is set, we'll generate our own
|
||||
// set of hop hints and use that
|
||||
request.RouteHints, err = SelectHopHints(
|
||||
ctx, s.lndServices, request.Amount, DefaultMaxHopHints, includeNodes,
|
||||
ctx, s.lndServices.Client, request.Amount,
|
||||
DefaultMaxHopHints, includeNodes,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -111,8 +111,8 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
|
|||
// Because the Private flag is set, we'll generate our own set
|
||||
// of hop hints.
|
||||
request.RouteHints, err = SelectHopHints(
|
||||
globalCtx, cfg.lnd, request.Amount, DefaultMaxHopHints,
|
||||
includeNodes,
|
||||
globalCtx, cfg.lnd.Client, request.Amount,
|
||||
DefaultMaxHopHints, includeNodes,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
25
utils.go
25
utils.go
|
|
@ -30,30 +30,29 @@ var (
|
|||
|
||||
// isPublicNode checks if a node is public, by simply checking if there's any
|
||||
// channels reported to the node.
|
||||
func isPublicNode(ctx context.Context, lnd *lndclient.LndServices,
|
||||
func isPublicNode(ctx context.Context, lndClient lndclient.LightningClient,
|
||||
pubKey [33]byte) (bool, error) {
|
||||
|
||||
// GetNodeInfo doesn't report our private channels with the queried node
|
||||
// so we can use it to determine if the node is considered public.
|
||||
nodeInfo, err := lnd.Client.GetNodeInfo(
|
||||
ctx, pubKey, true,
|
||||
)
|
||||
// so, we can use it to determine if the node is considered public.
|
||||
nodeInfo, err := lndClient.GetNodeInfo(ctx, pubKey, true)
|
||||
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return (nodeInfo.ChannelCount > 0), nil
|
||||
return nodeInfo.ChannelCount > 0, nil
|
||||
}
|
||||
|
||||
// fetchChannelEdgesByID fetches the edge info for the passed channel and
|
||||
// returns the channeldb structs filled with the data that is needed for
|
||||
// LND's SelectHopHints implementation.
|
||||
func fetchChannelEdgesByID(ctx context.Context, lnd *lndclient.LndServices,
|
||||
chanID uint64) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
func fetchChannelEdgesByID(ctx context.Context,
|
||||
lndClient lndclient.LightningClient, chanID uint64) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
chanInfo, err := lnd.Client.GetChanInfo(ctx, chanID)
|
||||
chanInfo, err := lndClient.GetChanInfo(ctx, chanID)
|
||||
if err != nil {
|
||||
return nil, nil, nil, err
|
||||
}
|
||||
|
|
@ -125,14 +124,14 @@ func getAlias(aliasCache map[lnwire.ChannelID]lnwire.ShortChannelID,
|
|||
|
||||
// SelectHopHints calls into LND's exposed SelectHopHints prefiltered to the
|
||||
// includeNodes map (unless it's empty).
|
||||
func SelectHopHints(ctx context.Context, lnd *lndclient.LndServices,
|
||||
func SelectHopHints(ctx context.Context, lndClient lndclient.LightningClient,
|
||||
amt btcutil.Amount, numMaxHophints int,
|
||||
includeNodes map[route.Vertex]struct{}) ([][]zpay32.HopHint, error) {
|
||||
|
||||
aliasCache := make(map[lnwire.ChannelID]lnwire.ShortChannelID)
|
||||
|
||||
// Fetch all active and public channels.
|
||||
channels, err := lnd.Client.ListChannels(ctx, false, false)
|
||||
channels, err := lndClient.ListChannels(ctx, false, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -175,13 +174,13 @@ func SelectHopHints(ctx context.Context, lnd *lndclient.LndServices,
|
|||
|
||||
cfg := &SelectHopHintsCfg{
|
||||
IsPublicNode: func(pubKey [33]byte) (bool, error) {
|
||||
return isPublicNode(ctx, lnd, pubKey)
|
||||
return isPublicNode(ctx, lndClient, pubKey)
|
||||
},
|
||||
FetchChannelEdgesByID: func(chanID uint64) (
|
||||
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
|
||||
*models.ChannelEdgePolicy, error) {
|
||||
|
||||
return fetchChannelEdgesByID(ctx, lnd, chanID)
|
||||
return fetchChannelEdgesByID(ctx, lndClient, chanID)
|
||||
},
|
||||
GetAlias: func(id lnwire.ChannelID) (
|
||||
lnwire.ShortChannelID, error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue