Skip to content

Commit a4eebf1

Browse files
committed
fixup! utils: fix SelectHopHints for lnd0.15.3
1 parent 69d9df3 commit a4eebf1

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

utils.go

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,23 +111,26 @@ func parseOutPoint(s string) (*wire.OutPoint, error) {
111111
}, nil
112112
}
113113

114+
// getAlias tries to get the ShortChannelId from the passed ChannelId and
115+
// aliasCache.
116+
func getAlias(aliasCache map[lnwire.ChannelID]lnwire.ShortChannelID,
117+
channelID lnwire.ChannelID) (lnwire.ShortChannelID, error) {
118+
119+
if channelID, ok := aliasCache[channelID]; ok {
120+
return channelID, nil
121+
}
122+
123+
return lnwire.ShortChannelID{}, fmt.Errorf("can't find channelId")
124+
}
125+
114126
// SelectHopHints calls into LND's exposed SelectHopHints prefiltered to the
115127
// includeNodes map (unless it's empty).
116128
func SelectHopHints(ctx context.Context, lnd *lndclient.LndServices,
117129
amt btcutil.Amount, numMaxHophints int,
118130
includeNodes map[route.Vertex]struct{}) ([][]zpay32.HopHint, error) {
119131

120-
cfg := &SelectHopHintsCfg{
121-
IsPublicNode: func(pubKey [33]byte) (bool, error) {
122-
return isPublicNode(ctx, lnd, pubKey)
123-
},
124-
FetchChannelEdgesByID: func(chanID uint64) (
125-
*channeldb.ChannelEdgeInfo, *channeldb.ChannelEdgePolicy,
126-
*channeldb.ChannelEdgePolicy, error) {
132+
aliasCache := make(map[lnwire.ChannelID]lnwire.ShortChannelID)
127133

128-
return fetchChannelEdgesByID(ctx, lnd, chanID)
129-
},
130-
}
131134
// Fetch all active and public channels.
132135
channels, err := lnd.Client.ListChannels(ctx, false, false)
133136
if err != nil {
@@ -164,6 +167,27 @@ func SelectHopHints(ctx context.Context, lnd *lndclient.LndServices,
164167
ShortChannelID: channel.ChannelID,
165168
},
166169
)
170+
171+
channelID := lnwire.NewChanIDFromOutPoint(outPoint)
172+
scID := lnwire.NewShortChanIDFromInt(channel.ChannelID)
173+
aliasCache[channelID] = scID
174+
}
175+
176+
cfg := &SelectHopHintsCfg{
177+
IsPublicNode: func(pubKey [33]byte) (bool, error) {
178+
return isPublicNode(ctx, lnd, pubKey)
179+
},
180+
FetchChannelEdgesByID: func(chanID uint64) (
181+
*channeldb.ChannelEdgeInfo, *channeldb.ChannelEdgePolicy,
182+
*channeldb.ChannelEdgePolicy, error) {
183+
184+
return fetchChannelEdgesByID(ctx, lnd, chanID)
185+
},
186+
GetAlias: func(id lnwire.ChannelID) (
187+
lnwire.ShortChannelID, error) {
188+
189+
return getAlias(aliasCache, id)
190+
},
167191
}
168192

169193
routeHints := invoicesrpcSelectHopHints(

0 commit comments

Comments
 (0)