From 5cdf31bfc8873bf71ed3f116570c6928e110ff98 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Mon, 29 May 2023 13:33:06 +0300 Subject: [PATCH 1/2] labels: add easy autoloop labels --- labels/labels.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/labels/labels.go b/labels/labels.go index e17f907..c06e180 100644 --- a/labels/labels.go +++ b/labels/labels.go @@ -23,6 +23,14 @@ const ( // autoIn is the label used for loop in swaps that are automatically // dispatched. autoIn = "autoloop-in" + + // easyAutoOut is the label used for easy loop out swaps that are + // automatically dispatched. + easyAutoOut = "easy-autoloop-out" + + // easyAutoIn is the label used for easy loop in swaps that are + // automatically dispatched. + easyAutoIn = "easy-autoloop-in" ) var ( @@ -44,6 +52,16 @@ func AutoloopLabel(swapType swap.Type) string { return fmt.Sprintf("%v: %v", Reserved, autoIn) } +// EasyAutoloopLabel returns a label with the reserved prefix that identifies +// automatically dispatched swaps depending on the type of swap being executed. +func EasyAutoloopLabel(swapType swap.Type) string { + if swapType == swap.TypeOut { + return fmt.Sprintf("%v: %v", Reserved, easyAutoOut) + } + + return fmt.Sprintf("%v: %v", Reserved, easyAutoIn) +} + // Validate checks that a label is of appropriate length and is not in our list // of reserved labels. func Validate(label string) error { From 1f72dcc09513d75bf21cb19bbd3c01b3501b64be Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Mon, 29 May 2023 13:33:18 +0300 Subject: [PATCH 2/2] liquidity: use easy autoloop labels --- liquidity/liquidity.go | 24 ++++++++++++++++++++++-- liquidity/loopin_builder.go | 4 ++++ liquidity/loopout_builder.go | 4 ++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/liquidity/liquidity.go b/liquidity/liquidity.go index 891baec..9efd526 100644 --- a/liquidity/liquidity.go +++ b/liquidity/liquidity.go @@ -1052,7 +1052,7 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context, var summary existingAutoLoopSummary for _, out := range loopOuts { - if out.Contract.Label != labels.AutoloopLabel(swap.TypeOut) { + if !isAutoloopLabel(out.Contract.Label) { continue } @@ -1082,7 +1082,7 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context, } for _, in := range loopIns { - if in.Contract.Label != labels.AutoloopLabel(swap.TypeIn) { + if !isAutoloopLabel(in.Contract.Label) { continue } @@ -1466,6 +1466,26 @@ func (m *Manager) checkSummaryInflight( return allowedSwaps, nil } +// isAutoloopLabel is a helper function that returns a flag indicating whether +// the provided label corresponds to an autoloop swap. +func isAutoloopLabel(label string) bool { + switch label { + case labels.AutoloopLabel(swap.TypeOut): + return true + + case labels.AutoloopLabel(swap.TypeIn): + return true + + case labels.EasyAutoloopLabel(swap.TypeOut): + return true + + case labels.EasyAutoloopLabel(swap.TypeIn): + return true + } + + return false +} + // swapTraffic contains a summary of our current and previously failed swaps. type swapTraffic struct { ongoingLoopOut map[lnwire.ShortChannelID]bool diff --git a/liquidity/loopin_builder.go b/liquidity/loopin_builder.go index cfe75f0..b94fca7 100644 --- a/liquidity/loopin_builder.go +++ b/liquidity/loopin_builder.go @@ -118,6 +118,10 @@ func (b *loopInBuilder) buildSwap(ctx context.Context, pubkey route.Vertex, if params.Autoloop { request.Label = labels.AutoloopLabel(swap.TypeIn) + + if params.EasyAutoloop { + request.Label = labels.EasyAutoloopLabel(swap.TypeIn) + } } return &loopInSwapSuggestion{ diff --git a/liquidity/loopout_builder.go b/liquidity/loopout_builder.go index 424a977..b8726b3 100644 --- a/liquidity/loopout_builder.go +++ b/liquidity/loopout_builder.go @@ -150,6 +150,10 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex, if params.Autoloop { request.Label = labels.AutoloopLabel(swap.TypeOut) + if params.EasyAutoloop { + request.Label = labels.EasyAutoloopLabel(swap.TypeOut) + } + addr, err := b.cfg.Lnd.WalletKit.NextAddr( ctx, "", walletrpc.AddressType_WITNESS_PUBKEY_HASH, false,