Merge pull request #590 from GeorgeTsagk/autoloop-bool-fix

liquidity: get autoloop flag directly from params
pull/594/head
George Tsagkarelis 1 year ago committed by GitHub
commit f4419aa424
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -62,7 +62,7 @@ type swapBuilder interface {
// is just for a dry run. // is just for a dry run.
buildSwap(ctx context.Context, peer route.Vertex, buildSwap(ctx context.Context, peer route.Vertex,
channels []lnwire.ShortChannelID, amount btcutil.Amount, channels []lnwire.ShortChannelID, amount btcutil.Amount,
autoloop bool, params Parameters) (swapSuggestion, error) params Parameters) (swapSuggestion, error)
} }
// swapSuggestion is an interface implemented by suggested swaps for our // swapSuggestion is an interface implemented by suggested swaps for our

@ -417,7 +417,7 @@ func (m *Manager) autoloop(ctx context.Context) error {
// swaps for autoloop. // swaps for autoloop.
m.refreshAutoloopBudget(ctx) m.refreshAutoloopBudget(ctx)
suggestion, err := m.SuggestSwaps(ctx, true) suggestion, err := m.SuggestSwaps(ctx)
if err != nil { if err != nil {
return err return err
} }
@ -613,7 +613,7 @@ func (m *Manager) dispatchBestEasyAutoloopSwap(ctx context.Context) error {
} }
suggestion, err := builder.buildSwap( suggestion, err := builder.buildSwap(
ctx, channel.PubKeyBytes, outgoing, swapAmt, true, easyParams, ctx, channel.PubKeyBytes, outgoing, swapAmt, easyParams,
) )
if err != nil { if err != nil {
return err return err
@ -697,7 +697,7 @@ func (m *Manager) singleReasonSuggestion(reason Reason) *Suggestions {
// suggestions are being used for our internal autolooper. This boolean is used // suggestions are being used for our internal autolooper. This boolean is used
// to determine the information we add to our swap suggestion and whether we // to determine the information we add to our swap suggestion and whether we
// return any suggestions. // return any suggestions.
func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) ( func (m *Manager) SuggestSwaps(ctx context.Context) (
*Suggestions, error) { *Suggestions, error) {
m.paramsLock.Lock() m.paramsLock.Lock()
@ -794,7 +794,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
suggestion, err := m.suggestSwap( suggestion, err := m.suggestSwap(
ctx, traffic, balances, rule, outRestrictions, ctx, traffic, balances, rule, outRestrictions,
inRestrictions, autoloop, inRestrictions,
) )
var reasonErr *reasonError var reasonErr *reasonError
if errors.As(err, &reasonErr) { if errors.As(err, &reasonErr) {
@ -820,7 +820,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
suggestion, err := m.suggestSwap( suggestion, err := m.suggestSwap(
ctx, traffic, balance, rule, outRestrictions, ctx, traffic, balance, rule, outRestrictions,
inRestrictions, autoloop, inRestrictions,
) )
var reasonErr *reasonError var reasonErr *reasonError
@ -922,7 +922,7 @@ func (m *Manager) SuggestSwaps(ctx context.Context, autoloop bool) (
// swap request for the rule provided. // swap request for the rule provided.
func (m *Manager) suggestSwap(ctx context.Context, traffic *swapTraffic, func (m *Manager) suggestSwap(ctx context.Context, traffic *swapTraffic,
balance *balances, rule *SwapRule, outRestrictions *Restrictions, balance *balances, rule *SwapRule, outRestrictions *Restrictions,
inRestrictions *Restrictions, autoloop bool) (swapSuggestion, error) { inRestrictions *Restrictions) (swapSuggestion, error) {
var ( var (
builder swapBuilder builder swapBuilder
@ -967,8 +967,7 @@ func (m *Manager) suggestSwap(ctx context.Context, traffic *swapTraffic,
} }
return builder.buildSwap( return builder.buildSwap(
ctx, balance.pubkey, balance.channels, amount, autoloop, ctx, balance.pubkey, balance.channels, amount, m.params,
m.params,
) )
} }

@ -1846,7 +1846,7 @@ func testSuggestSwaps(t *testing.T, setup *testSuggestSwapsSetup,
err := manager.setParameters(context.Background(), setup.params) err := manager.setParameters(context.Background(), setup.params)
require.NoError(t, err) require.NoError(t, err)
actual, err := manager.SuggestSwaps(context.Background(), false) actual, err := manager.SuggestSwaps(context.Background())
require.Equal(t, expectedErr, err) require.Equal(t, expectedErr, err)
require.Equal(t, expected, actual) require.Equal(t, expected, actual)
} }

@ -84,7 +84,7 @@ func (b *loopInBuilder) inUse(traffic *swapTraffic, peer route.Vertex,
// For loop in, we do not add the autoloop label for dry runs. // For loop in, we do not add the autoloop label for dry runs.
func (b *loopInBuilder) buildSwap(ctx context.Context, pubkey route.Vertex, func (b *loopInBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
_ []lnwire.ShortChannelID, amount btcutil.Amount, _ []lnwire.ShortChannelID, amount btcutil.Amount,
autoloop bool, params Parameters) (swapSuggestion, error) { params Parameters) (swapSuggestion, error) {
quote, err := b.cfg.LoopInQuote(ctx, &loop.LoopInQuoteRequest{ quote, err := b.cfg.LoopInQuote(ctx, &loop.LoopInQuoteRequest{
Amount: amount, Amount: amount,
@ -116,7 +116,7 @@ func (b *loopInBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
Initiator: autoloopSwapInitiator, Initiator: autoloopSwapInitiator,
} }
if autoloop { if params.Autoloop {
request.Label = labels.AutoloopLabel(swap.TypeIn) request.Label = labels.AutoloopLabel(swap.TypeIn)
} }

@ -183,7 +183,7 @@ func TestLoopinBuildSwap(t *testing.T) {
swap, err := builder.buildSwap( swap, err := builder.buildSwap(
context.Background(), peer1, []lnwire.ShortChannelID{ context.Background(), peer1, []lnwire.ShortChannelID{
chan1, chan1,
}, swapAmt, false, params, }, swapAmt, params,
) )
assert.Equal(t, testCase.expectedSwap, swap) assert.Equal(t, testCase.expectedSwap, swap)
assert.Equal(t, testCase.expectedErr, err) assert.Equal(t, testCase.expectedErr, err)

@ -94,7 +94,7 @@ func (b *loopOutBuilder) inUse(traffic *swapTraffic, peer route.Vertex,
// dry-run, and we do not add the autoloop label to the recommended swap. // dry-run, and we do not add the autoloop label to the recommended swap.
func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex, func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
channels []lnwire.ShortChannelID, amount btcutil.Amount, channels []lnwire.ShortChannelID, amount btcutil.Amount,
autoloop bool, params Parameters) (swapSuggestion, error) { params Parameters) (swapSuggestion, error) {
quote, err := b.cfg.LoopOutQuote( quote, err := b.cfg.LoopOutQuote(
ctx, &loop.LoopOutQuoteRequest{ ctx, &loop.LoopOutQuoteRequest{
@ -147,7 +147,7 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
Initiator: autoloopSwapInitiator, Initiator: autoloopSwapInitiator,
} }
if autoloop { if params.Autoloop {
request.Label = labels.AutoloopLabel(swap.TypeOut) request.Label = labels.AutoloopLabel(swap.TypeOut)
addr, err := b.cfg.Lnd.WalletKit.NextAddr( addr, err := b.cfg.Lnd.WalletKit.NextAddr(

@ -844,7 +844,7 @@ func (s *swapClientServer) SetLiquidityParams(ctx context.Context,
func (s *swapClientServer) SuggestSwaps(ctx context.Context, func (s *swapClientServer) SuggestSwaps(ctx context.Context,
_ *clientrpc.SuggestSwapsRequest) (*clientrpc.SuggestSwapsResponse, error) { _ *clientrpc.SuggestSwapsRequest) (*clientrpc.SuggestSwapsResponse, error) {
suggestions, err := s.liquidityMgr.SuggestSwaps(ctx, false) suggestions, err := s.liquidityMgr.SuggestSwaps(ctx)
switch err { switch err {
case liquidity.ErrNoRules: case liquidity.ErrNoRules:
return nil, status.Error(codes.FailedPrecondition, err.Error()) return nil, status.Error(codes.FailedPrecondition, err.Error())

Loading…
Cancel
Save