Skip to content

Commit 174a6b8

Browse files
authored
Merge pull request #777 from hieblmi/refactor-select-hop-hints
utils: refactor SelectHopHints to use narrower interface
2 parents 3b3d3ac + 5b79705 commit 174a6b8

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,8 @@ func (s *Client) LoopInQuote(ctx context.Context,
683683
// Because the Private flag is set, we'll generate our own
684684
// set of hop hints and use that
685685
request.RouteHints, err = SelectHopHints(
686-
ctx, s.lndServices, request.Amount, DefaultMaxHopHints, includeNodes,
686+
ctx, s.lndServices.Client, request.Amount,
687+
DefaultMaxHopHints, includeNodes,
687688
)
688689
if err != nil {
689690
return nil, err

loopin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
111111
// Because the Private flag is set, we'll generate our own set
112112
// of hop hints.
113113
request.RouteHints, err = SelectHopHints(
114-
globalCtx, cfg.lnd, request.Amount, DefaultMaxHopHints,
115-
includeNodes,
114+
globalCtx, cfg.lnd.Client, request.Amount,
115+
DefaultMaxHopHints, includeNodes,
116116
)
117117
if err != nil {
118118
return nil, err

utils.go

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,30 +30,29 @@ var (
3030

3131
// isPublicNode checks if a node is public, by simply checking if there's any
3232
// channels reported to the node.
33-
func isPublicNode(ctx context.Context, lnd *lndclient.LndServices,
33+
func isPublicNode(ctx context.Context, lndClient lndclient.LightningClient,
3434
pubKey [33]byte) (bool, error) {
3535

3636
// GetNodeInfo doesn't report our private channels with the queried node
37-
// so we can use it to determine if the node is considered public.
38-
nodeInfo, err := lnd.Client.GetNodeInfo(
39-
ctx, pubKey, true,
40-
)
37+
// so, we can use it to determine if the node is considered public.
38+
nodeInfo, err := lndClient.GetNodeInfo(ctx, pubKey, true)
4139

4240
if err != nil {
4341
return false, err
4442
}
4543

46-
return (nodeInfo.ChannelCount > 0), nil
44+
return nodeInfo.ChannelCount > 0, nil
4745
}
4846

4947
// fetchChannelEdgesByID fetches the edge info for the passed channel and
5048
// returns the channeldb structs filled with the data that is needed for
5149
// LND's SelectHopHints implementation.
52-
func fetchChannelEdgesByID(ctx context.Context, lnd *lndclient.LndServices,
53-
chanID uint64) (*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
50+
func fetchChannelEdgesByID(ctx context.Context,
51+
lndClient lndclient.LightningClient, chanID uint64) (
52+
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
5453
*models.ChannelEdgePolicy, error) {
5554

56-
chanInfo, err := lnd.Client.GetChanInfo(ctx, chanID)
55+
chanInfo, err := lndClient.GetChanInfo(ctx, chanID)
5756
if err != nil {
5857
return nil, nil, nil, err
5958
}
@@ -125,14 +124,14 @@ func getAlias(aliasCache map[lnwire.ChannelID]lnwire.ShortChannelID,
125124

126125
// SelectHopHints calls into LND's exposed SelectHopHints prefiltered to the
127126
// includeNodes map (unless it's empty).
128-
func SelectHopHints(ctx context.Context, lnd *lndclient.LndServices,
127+
func SelectHopHints(ctx context.Context, lndClient lndclient.LightningClient,
129128
amt btcutil.Amount, numMaxHophints int,
130129
includeNodes map[route.Vertex]struct{}) ([][]zpay32.HopHint, error) {
131130

132131
aliasCache := make(map[lnwire.ChannelID]lnwire.ShortChannelID)
133132

134133
// Fetch all active and public channels.
135-
channels, err := lnd.Client.ListChannels(ctx, false, false)
134+
channels, err := lndClient.ListChannels(ctx, false, false)
136135
if err != nil {
137136
return nil, err
138137
}
@@ -175,13 +174,13 @@ func SelectHopHints(ctx context.Context, lnd *lndclient.LndServices,
175174

176175
cfg := &SelectHopHintsCfg{
177176
IsPublicNode: func(pubKey [33]byte) (bool, error) {
178-
return isPublicNode(ctx, lnd, pubKey)
177+
return isPublicNode(ctx, lndClient, pubKey)
179178
},
180179
FetchChannelEdgesByID: func(chanID uint64) (
181180
*models.ChannelEdgeInfo, *models.ChannelEdgePolicy,
182181
*models.ChannelEdgePolicy, error) {
183182

184-
return fetchChannelEdgesByID(ctx, lnd, chanID)
183+
return fetchChannelEdgesByID(ctx, lndClient, chanID)
185184
},
186185
GetAlias: func(id lnwire.ChannelID) (
187186
lnwire.ShortChannelID, error) {

0 commit comments

Comments
 (0)