mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-11-18 01:56:55 +01:00
invoicesrpc: remove a context.TODO
This commit is contained in:
@@ -462,7 +462,7 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
|
|||||||
|
|
||||||
hopHintsCfg := newSelectHopHintsCfg(cfg, totalHopHints)
|
hopHintsCfg := newSelectHopHintsCfg(cfg, totalHopHints)
|
||||||
hopHints, err := PopulateHopHints(
|
hopHints, err := PopulateHopHints(
|
||||||
hopHintsCfg, amtMSat, invoice.RouteHints,
|
ctx, hopHintsCfg, amtMSat, invoice.RouteHints,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("unable to populate hop "+
|
return nil, nil, fmt.Errorf("unable to populate hop "+
|
||||||
@@ -624,10 +624,8 @@ func AddInvoice(ctx context.Context, cfg *AddInvoiceConfig,
|
|||||||
|
|
||||||
// chanCanBeHopHint returns true if the target channel is eligible to be a hop
|
// chanCanBeHopHint returns true if the target channel is eligible to be a hop
|
||||||
// hint.
|
// hint.
|
||||||
func chanCanBeHopHint(channel *HopHintInfo, cfg *SelectHopHintsCfg) (
|
func chanCanBeHopHint(ctx context.Context, channel *HopHintInfo,
|
||||||
*models.ChannelEdgePolicy, bool) {
|
cfg *SelectHopHintsCfg) (*models.ChannelEdgePolicy, bool) {
|
||||||
|
|
||||||
ctx := context.TODO()
|
|
||||||
|
|
||||||
// Since we're only interested in our private channels, we'll skip
|
// Since we're only interested in our private channels, we'll skip
|
||||||
// public ones.
|
// public ones.
|
||||||
@@ -862,7 +860,7 @@ func getPotentialHints(cfg *SelectHopHintsCfg) ([]*channeldb.OpenChannel,
|
|||||||
|
|
||||||
// shouldIncludeChannel returns true if the channel passes all the checks to
|
// shouldIncludeChannel returns true if the channel passes all the checks to
|
||||||
// be a hopHint in a given invoice.
|
// be a hopHint in a given invoice.
|
||||||
func shouldIncludeChannel(cfg *SelectHopHintsCfg,
|
func shouldIncludeChannel(ctx context.Context, cfg *SelectHopHintsCfg,
|
||||||
channel *channeldb.OpenChannel,
|
channel *channeldb.OpenChannel,
|
||||||
alreadyIncluded map[uint64]bool) (zpay32.HopHint, lnwire.MilliSatoshi,
|
alreadyIncluded map[uint64]bool) (zpay32.HopHint, lnwire.MilliSatoshi,
|
||||||
bool) {
|
bool) {
|
||||||
@@ -878,7 +876,7 @@ func shouldIncludeChannel(cfg *SelectHopHintsCfg,
|
|||||||
hopHintInfo := newHopHintInfo(channel, cfg.IsChannelActive(chanID))
|
hopHintInfo := newHopHintInfo(channel, cfg.IsChannelActive(chanID))
|
||||||
|
|
||||||
// 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(hopHintInfo, cfg)
|
edgePolicy, canBeHopHint := chanCanBeHopHint(ctx, hopHintInfo, cfg)
|
||||||
if edgePolicy == nil || !canBeHopHint {
|
if edgePolicy == nil || !canBeHopHint {
|
||||||
return zpay32.HopHint{}, 0, false
|
return zpay32.HopHint{}, 0, false
|
||||||
}
|
}
|
||||||
@@ -907,7 +905,7 @@ func shouldIncludeChannel(cfg *SelectHopHintsCfg,
|
|||||||
//
|
//
|
||||||
// NOTE: selectHopHints expects potentialHints to be already sorted in
|
// NOTE: selectHopHints expects potentialHints to be already sorted in
|
||||||
// descending priority.
|
// descending priority.
|
||||||
func selectHopHints(cfg *SelectHopHintsCfg, nHintsLeft int,
|
func selectHopHints(ctx context.Context, cfg *SelectHopHintsCfg, nHintsLeft int,
|
||||||
targetBandwidth lnwire.MilliSatoshi,
|
targetBandwidth lnwire.MilliSatoshi,
|
||||||
potentialHints []*channeldb.OpenChannel,
|
potentialHints []*channeldb.OpenChannel,
|
||||||
alreadyIncluded map[uint64]bool) [][]zpay32.HopHint {
|
alreadyIncluded map[uint64]bool) [][]zpay32.HopHint {
|
||||||
@@ -923,7 +921,7 @@ func selectHopHints(cfg *SelectHopHintsCfg, nHintsLeft int,
|
|||||||
}
|
}
|
||||||
|
|
||||||
hopHint, remoteBalance, include := shouldIncludeChannel(
|
hopHint, remoteBalance, include := shouldIncludeChannel(
|
||||||
cfg, channel, alreadyIncluded,
|
ctx, cfg, channel, alreadyIncluded,
|
||||||
)
|
)
|
||||||
|
|
||||||
if include {
|
if include {
|
||||||
@@ -951,8 +949,9 @@ func selectHopHints(cfg *SelectHopHintsCfg, nHintsLeft int,
|
|||||||
// options that'll append the route hint to the set of all route hints.
|
// options that'll append the route hint to the set of all route hints.
|
||||||
//
|
//
|
||||||
// TODO(roasbeef): do proper sub-set sum max hints usually << numChans.
|
// TODO(roasbeef): do proper sub-set sum max hints usually << numChans.
|
||||||
func PopulateHopHints(cfg *SelectHopHintsCfg, amtMSat lnwire.MilliSatoshi,
|
func PopulateHopHints(ctx context.Context, cfg *SelectHopHintsCfg,
|
||||||
forcedHints [][]zpay32.HopHint) ([][]zpay32.HopHint, error) {
|
amtMSat lnwire.MilliSatoshi, forcedHints [][]zpay32.HopHint) (
|
||||||
|
[][]zpay32.HopHint, error) {
|
||||||
|
|
||||||
hopHints := forcedHints
|
hopHints := forcedHints
|
||||||
|
|
||||||
@@ -974,7 +973,7 @@ func PopulateHopHints(cfg *SelectHopHintsCfg, amtMSat lnwire.MilliSatoshi,
|
|||||||
|
|
||||||
targetBandwidth := amtMSat * hopHintFactor
|
targetBandwidth := amtMSat * hopHintFactor
|
||||||
selectedHints := selectHopHints(
|
selectedHints := selectHopHints(
|
||||||
cfg, nHintsLeft, targetBandwidth, potentialHints,
|
ctx, cfg, nHintsLeft, targetBandwidth, potentialHints,
|
||||||
alreadyIncluded,
|
alreadyIncluded,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -435,6 +435,7 @@ var shouldIncludeChannelTestCases = []struct {
|
|||||||
}}
|
}}
|
||||||
|
|
||||||
func TestShouldIncludeChannel(t *testing.T) {
|
func TestShouldIncludeChannel(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
for _, tc := range shouldIncludeChannelTestCases {
|
for _, tc := range shouldIncludeChannelTestCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
|
|
||||||
@@ -456,7 +457,7 @@ func TestShouldIncludeChannel(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hopHint, remoteBalance, include := shouldIncludeChannel(
|
hopHint, remoteBalance, include := shouldIncludeChannel(
|
||||||
cfg, tc.channel, tc.alreadyIncluded,
|
ctx, cfg, tc.channel, tc.alreadyIncluded,
|
||||||
)
|
)
|
||||||
|
|
||||||
require.Equal(t, tc.include, include)
|
require.Equal(t, tc.include, include)
|
||||||
@@ -868,6 +869,7 @@ func setupMockTwoChannels(h *hopHintsConfigMock) (lnwire.ChannelID,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPopulateHopHints(t *testing.T) {
|
func TestPopulateHopHints(t *testing.T) {
|
||||||
|
ctx := context.Background()
|
||||||
for _, tc := range populateHopHintsTestCases {
|
for _, tc := range populateHopHintsTestCases {
|
||||||
tc := tc
|
tc := tc
|
||||||
|
|
||||||
@@ -890,7 +892,7 @@ func TestPopulateHopHints(t *testing.T) {
|
|||||||
MaxHopHints: tc.maxHopHints,
|
MaxHopHints: tc.maxHopHints,
|
||||||
}
|
}
|
||||||
hopHints, err := PopulateHopHints(
|
hopHints, err := PopulateHopHints(
|
||||||
cfg, tc.amount, tc.forcedHints,
|
ctx, cfg, tc.amount, tc.forcedHints,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
// We shuffle the elements in the hop hint list so we
|
// We shuffle the elements in the hop hint list so we
|
||||||
|
|||||||
Reference in New Issue
Block a user