mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-28 10:41:57 +01:00
invoicerpc: return hop hints from select hop hint rather than functions
Update SelectHopHints to return a set of hop hints that can be converted to route hints / functional options by the caller. This change allows external code to call SelectHopHints to get a set of route hints and use them as it likes, rather than limiting the return value to functional options for invoice creation.
This commit is contained in:
parent
00a47740c8
commit
80bf4bf014
@ -407,7 +407,15 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
|
|||||||
numMaxHophints,
|
numMaxHophints,
|
||||||
)
|
)
|
||||||
|
|
||||||
options = append(options, hopHints...)
|
// Convert our set of selected hop hints into route
|
||||||
|
// hints and add to our invoice options.
|
||||||
|
for _, hopHint := range hopHints {
|
||||||
|
routeHint := zpay32.RouteHint(hopHint)
|
||||||
|
|
||||||
|
options = append(
|
||||||
|
options, routeHint,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -540,7 +548,7 @@ func chanCanBeHopHint(channel *HopHintInfo, cfg *SelectHopHintsCfg) (
|
|||||||
|
|
||||||
// addHopHint creates a hop hint out of the passed channel and channel policy.
|
// addHopHint creates a hop hint out of the passed channel and channel policy.
|
||||||
// The new hop hint is appended to the passed slice.
|
// The new hop hint is appended to the passed slice.
|
||||||
func addHopHint(hopHints *[]func(*zpay32.Invoice),
|
func addHopHint(hopHints *[][]zpay32.HopHint,
|
||||||
channel *HopHintInfo, chanPolicy *channeldb.ChannelEdgePolicy) {
|
channel *HopHintInfo, chanPolicy *channeldb.ChannelEdgePolicy) {
|
||||||
|
|
||||||
hopHint := zpay32.HopHint{
|
hopHint := zpay32.HopHint{
|
||||||
@ -552,9 +560,8 @@ func addHopHint(hopHints *[]func(*zpay32.Invoice),
|
|||||||
),
|
),
|
||||||
CLTVExpiryDelta: chanPolicy.TimeLockDelta,
|
CLTVExpiryDelta: chanPolicy.TimeLockDelta,
|
||||||
}
|
}
|
||||||
*hopHints = append(
|
|
||||||
*hopHints, zpay32.RouteHint([]zpay32.HopHint{hopHint}),
|
*hopHints = append(*hopHints, []zpay32.HopHint{hopHint})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HopHintInfo contains the channel information required to create a hop hint.
|
// HopHintInfo contains the channel information required to create a hop hint.
|
||||||
@ -623,14 +630,14 @@ func newSelectHopHintsCfg(invoicesCfg *AddInvoiceConfig) *SelectHopHintsCfg {
|
|||||||
// TODO(roasbeef): do proper sub-set sum max hints usually << numChans
|
// TODO(roasbeef): do proper sub-set sum max hints usually << numChans
|
||||||
func SelectHopHints(amtMSat lnwire.MilliSatoshi, cfg *SelectHopHintsCfg,
|
func SelectHopHints(amtMSat lnwire.MilliSatoshi, cfg *SelectHopHintsCfg,
|
||||||
openChannels []*HopHintInfo,
|
openChannels []*HopHintInfo,
|
||||||
numMaxHophints int) []func(*zpay32.Invoice) {
|
numMaxHophints int) [][]zpay32.HopHint {
|
||||||
|
|
||||||
// We'll add our hop hints in two passes, first we'll add all channels
|
// We'll add our hop hints in two passes, first we'll add all channels
|
||||||
// that are eligible to be hop hints, and also have a local balance
|
// that are eligible to be hop hints, and also have a local balance
|
||||||
// above the payment amount.
|
// above the payment amount.
|
||||||
var totalHintBandwidth lnwire.MilliSatoshi
|
var totalHintBandwidth lnwire.MilliSatoshi
|
||||||
hopHintChans := make(map[wire.OutPoint]struct{})
|
hopHintChans := make(map[wire.OutPoint]struct{})
|
||||||
hopHints := make([]func(*zpay32.Invoice), 0, numMaxHophints)
|
hopHints := make([][]zpay32.HopHint, 0, numMaxHophints)
|
||||||
for _, channel := range openChannels {
|
for _, channel := range openChannels {
|
||||||
// If this channel can't be a hop hint, then skip it.
|
// If this channel can't be a hop hint, then skip it.
|
||||||
edgePolicy, canBeHopHint := chanCanBeHopHint(channel, cfg)
|
edgePolicy, canBeHopHint := chanCanBeHopHint(channel, cfg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user