Skip to content

Commit a48924a

Browse files
committed
liquidity: get autoloop flag directly from params
Previously we would exclusively pass the autoloop boolean to multiple functions while they had directly access to the manager's parameters. With this commit we remove this explicit flag from the various function interfaces and retrieve the value directly from the parameters.
1 parent 62eced6 commit a48924a

File tree

7 files changed

+15
-16
lines changed

7 files changed

+15
-16
lines changed

liquidity/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ type swapBuilder interface {
6262
// is just for a dry run.
6363
buildSwap(ctx context.Context, peer route.Vertex,
6464
channels []lnwire.ShortChannelID, amount btcutil.Amount,
65-
autoloop bool, params Parameters) (swapSuggestion, error)
65+
params Parameters) (swapSuggestion, error)
6666
}
6767

6868
// swapSuggestion is an interface implemented by suggested swaps for our

liquidity/liquidity.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ func (m *Manager) autoloop(ctx context.Context) error {
417417
// swaps for autoloop.
418418
m.refreshAutoloopBudget(ctx)
419419

420-
suggestion, err := m.SuggestSwaps(ctx, true)
420+
suggestion, err := m.SuggestSwaps(ctx)
421421
if err != nil {
422422
return err
423423
}
@@ -613,7 +613,7 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
613613
}
614614

615615
suggestion, err := builder.buildSwap(
616-
ctx, channel.PubKeyBytes, outgoing, swapAmt, true, easyParams,
616+
ctx, channel.PubKeyBytes, outgoing, swapAmt, easyParams,
617617
)
618618
if err != nil {
619619
return err
@@ -697,7 +697,7 @@ func (m *Manager) singleReasonSuggestion(reason Reason) *Suggestions {
697697
// suggestions are being used for our internal autolooper. This boolean is used
698698
// to determine the information we add to our swap suggestion and whether we
699699
// return any suggestions.
700-
func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
700+
func (m *Manager) SuggestSwaps(ctx context.Context) (
701701
*Suggestions, error) {
702702

703703
m.paramsLock.Lock()
@@ -794,7 +794,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
794794

795795
suggestion, err := m.suggestSwap(
796796
ctx, traffic, balances, rule, outRestrictions,
797-
inRestrictions, autoloop,
797+
inRestrictions,
798798
)
799799
var reasonErr *reasonError
800800
if errors.As(err, &reasonErr) {
@@ -820,7 +820,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
820820

821821
suggestion, err := m.suggestSwap(
822822
ctx, traffic, balance, rule, outRestrictions,
823-
inRestrictions, autoloop,
823+
inRestrictions,
824824
)
825825

826826
var reasonErr *reasonError
@@ -922,7 +922,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
922922
// swap request for the rule provided.
923923
func (m *Manager) suggestSwap(ctx context.Context, traffic *swapTraffic,
924924
balance *balances, rule *SwapRule, outRestrictions *Restrictions,
925-
inRestrictions *Restrictions, autoloop bool) (swapSuggestion, error) {
925+
inRestrictions *Restrictions) (swapSuggestion, error) {
926926

927927
var (
928928
builder swapBuilder
@@ -967,8 +967,7 @@ func (m *Manager) suggestSwap(ctx context.Context, traffic *swapTraffic,
967967
}
968968

969969
return builder.buildSwap(
970-
ctx, balance.pubkey, balance.channels, amount, autoloop,
971-
m.params,
970+
ctx, balance.pubkey, balance.channels, amount, m.params,
972971
)
973972
}
974973

liquidity/liquidity_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1846,7 +1846,7 @@ func testSuggestSwaps(t *testing.T, setup *testSuggestSwapsSetup,
18461846
err := manager.setParameters(context.Background(), setup.params)
18471847
require.NoError(t, err)
18481848

1849-
actual, err := manager.SuggestSwaps(context.Background(), false)
1849+
actual, err := manager.SuggestSwaps(context.Background())
18501850
require.Equal(t, expectedErr, err)
18511851
require.Equal(t, expected, actual)
18521852
}

liquidity/loopin_builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (b *loopInBuilder) inUse(traffic *swapTraffic, peer route.Vertex,
8484
// For loop in, we do not add the autoloop label for dry runs.
8585
func (b *loopInBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
8686
_ []lnwire.ShortChannelID, amount btcutil.Amount,
87-
autoloop bool, params Parameters) (swapSuggestion, error) {
87+
params Parameters) (swapSuggestion, error) {
8888

8989
quote, err := b.cfg.LoopInQuote(ctx, &loop.LoopInQuoteRequest{
9090
Amount: amount,
@@ -116,7 +116,7 @@ func (b *loopInBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
116116
Initiator: autoloopSwapInitiator,
117117
}
118118

119-
if autoloop {
119+
if params.Autoloop {
120120
request.Label = labels.AutoloopLabel(swap.TypeIn)
121121
}
122122

liquidity/loopin_builder_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func TestLoopinBuildSwap(t *testing.T) {
183183
swap, err := builder.buildSwap(
184184
context.Background(), peer1, []lnwire.ShortChannelID{
185185
chan1,
186-
}, swapAmt, false, params,
186+
}, swapAmt, params,
187187
)
188188
assert.Equal(t, testCase.expectedSwap, swap)
189189
assert.Equal(t, testCase.expectedErr, err)

liquidity/loopout_builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func (b *loopOutBuilder) inUse(traffic *swapTraffic, peer route.Vertex,
9494
// dry-run, and we do not add the autoloop label to the recommended swap.
9595
func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
9696
channels []lnwire.ShortChannelID, amount btcutil.Amount,
97-
autoloop bool, params Parameters) (swapSuggestion, error) {
97+
params Parameters) (swapSuggestion, error) {
9898

9999
quote, err := b.cfg.LoopOutQuote(
100100
ctx, &loop.LoopOutQuoteRequest{
@@ -147,7 +147,7 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
147147
Initiator: autoloopSwapInitiator,
148148
}
149149

150-
if autoloop {
150+
if params.Autoloop {
151151
request.Label = labels.AutoloopLabel(swap.TypeOut)
152152

153153
addr, err := b.cfg.Lnd.WalletKit.NextAddr(

loopd/swapclient_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ func (s *swapClientServer) SetLiquidityParams(ctx context.Context,
844844
func (s *swapClientServer) SuggestSwaps(ctx context.Context,
845845
_ *clientrpc.SuggestSwapsRequest) (*clientrpc.SuggestSwapsResponse, error) {
846846

847-
suggestions, err := s.liquidityMgr.SuggestSwaps(ctx, false)
847+
suggestions, err := s.liquidityMgr.SuggestSwaps(ctx)
848848
switch err {
849849
case liquidity.ErrNoRules:
850850
return nil, status.Error(codes.FailedPrecondition, err.Error())

0 commit comments

Comments
 (0)