Skip to content

Commit 319a519

Browse files
authored
Merge pull request #591 from GeorgeTsagk/autoloop-easy-tag
Autoloop easy tag
2 parents 5e2cb14 + 1f72dcc commit 319a519

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

labels/labels.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ const (
2323
// autoIn is the label used for loop in swaps that are automatically
2424
// dispatched.
2525
autoIn = "autoloop-in"
26+
27+
// easyAutoOut is the label used for easy loop out swaps that are
28+
// automatically dispatched.
29+
easyAutoOut = "easy-autoloop-out"
30+
31+
// easyAutoIn is the label used for easy loop in swaps that are
32+
// automatically dispatched.
33+
easyAutoIn = "easy-autoloop-in"
2634
)
2735

2836
var (
@@ -44,6 +52,16 @@ func AutoloopLabel(swapType swap.Type) string {
4452
return fmt.Sprintf("%v: %v", Reserved, autoIn)
4553
}
4654

55+
// EasyAutoloopLabel returns a label with the reserved prefix that identifies
56+
// automatically dispatched swaps depending on the type of swap being executed.
57+
func EasyAutoloopLabel(swapType swap.Type) string {
58+
if swapType == swap.TypeOut {
59+
return fmt.Sprintf("%v: %v", Reserved, easyAutoOut)
60+
}
61+
62+
return fmt.Sprintf("%v: %v", Reserved, easyAutoIn)
63+
}
64+
4765
// Validate checks that a label is of appropriate length and is not in our list
4866
// of reserved labels.
4967
func Validate(label string) error {

liquidity/liquidity.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context,
10521052
var summary existingAutoLoopSummary
10531053

10541054
for _, out := range loopOuts {
1055-
if out.Contract.Label != labels.AutoloopLabel(swap.TypeOut) {
1055+
if !isAutoloopLabel(out.Contract.Label) {
10561056
continue
10571057
}
10581058

@@ -1082,7 +1082,7 @@ func (m *Manager) checkExistingAutoLoops(ctx context.Context,
10821082
}
10831083

10841084
for _, in := range loopIns {
1085-
if in.Contract.Label != labels.AutoloopLabel(swap.TypeIn) {
1085+
if !isAutoloopLabel(in.Contract.Label) {
10861086
continue
10871087
}
10881088

@@ -1466,6 +1466,26 @@ func (m *Manager) checkSummaryInflight(
14661466
return allowedSwaps, nil
14671467
}
14681468

1469+
// isAutoloopLabel is a helper function that returns a flag indicating whether
1470+
// the provided label corresponds to an autoloop swap.
1471+
func isAutoloopLabel(label string) bool {
1472+
switch label {
1473+
case labels.AutoloopLabel(swap.TypeOut):
1474+
return true
1475+
1476+
case labels.AutoloopLabel(swap.TypeIn):
1477+
return true
1478+
1479+
case labels.EasyAutoloopLabel(swap.TypeOut):
1480+
return true
1481+
1482+
case labels.EasyAutoloopLabel(swap.TypeIn):
1483+
return true
1484+
}
1485+
1486+
return false
1487+
}
1488+
14691489
// swapTraffic contains a summary of our current and previously failed swaps.
14701490
type swapTraffic struct {
14711491
ongoingLoopOut map[lnwire.ShortChannelID]bool

liquidity/loopin_builder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ func (b *loopInBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
118118

119119
if params.Autoloop {
120120
request.Label = labels.AutoloopLabel(swap.TypeIn)
121+
122+
if params.EasyAutoloop {
123+
request.Label = labels.EasyAutoloopLabel(swap.TypeIn)
124+
}
121125
}
122126

123127
return &loopInSwapSuggestion{

liquidity/loopout_builder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
150150
if params.Autoloop {
151151
request.Label = labels.AutoloopLabel(swap.TypeOut)
152152

153+
if params.EasyAutoloop {
154+
request.Label = labels.EasyAutoloopLabel(swap.TypeOut)
155+
}
156+
153157
addr, err := b.cfg.Lnd.WalletKit.NextAddr(
154158
ctx, "", walletrpc.AddressType_WITNESS_PUBKEY_HASH,
155159
false,

0 commit comments

Comments
 (0)