Skip to content

Commit 693d3a4

Browse files
committed
liquidity: default to slow swaps for autloop
1 parent 565acbb commit 693d3a4

File tree

4 files changed

+73
-23
lines changed

4 files changed

+73
-23
lines changed

cmd/loop/liquidity.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,16 @@ var setParamsCommand = cli.Command{
367367
Usage: "the target size of total local balance in " +
368368
"asset units, used by asset easy autoloop.",
369369
},
370+
cli.BoolFlag{
371+
Name: "fast",
372+
Usage: "if set new swaps are expected to be " +
373+
"published immediately, paying a potentially " +
374+
"higher fee. If not set the swap server " +
375+
"might choose to wait up to 30 minutes " +
376+
"before publishing swap HTLCs on-chain, to " +
377+
"save on chain fees. Not setting this flag " +
378+
"therefore might result in a lower swap fees",
379+
},
370380
},
371381
Action: setParams,
372382
}
@@ -577,6 +587,10 @@ func setParams(ctx *cli.Context) error {
577587
flagSet = true
578588
}
579589

590+
if ctx.IsSet("fast") {
591+
params.FastSwapPublication = true
592+
}
593+
580594
if !flagSet {
581595
return fmt.Errorf("at least one flag required to set params")
582596
}

liquidity/autoloop_test.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ func TestAutoLoopEnabled(t *testing.T) {
117117
chanID1: chanRule,
118118
chanID2: chanRule,
119119
},
120-
HtlcConfTarget: defaultHtlcConfTarget,
120+
HtlcConfTarget: defaultHtlcConfTarget,
121+
FastSwapPublication: true,
121122
}
122123
)
123124

@@ -376,7 +377,8 @@ func TestAutoloopAddress(t *testing.T) {
376377
chanID1: chanRule,
377378
chanID2: chanRule,
378379
},
379-
HtlcConfTarget: defaultHtlcConfTarget,
380+
HtlcConfTarget: defaultHtlcConfTarget,
381+
FastSwapPublication: true,
380382
}
381383
)
382384
c := newAutoloopTestCtx(t, params, channels, testRestrictions)
@@ -546,7 +548,8 @@ func TestCompositeRules(t *testing.T) {
546548
PeerRules: map[route.Vertex]*SwapRule{
547549
peer2: chanRule,
548550
},
549-
HtlcConfTarget: defaultHtlcConfTarget,
551+
HtlcConfTarget: defaultHtlcConfTarget,
552+
FastSwapPublication: true,
550553
}
551554
)
552555

@@ -923,8 +926,9 @@ func TestAutoloopBothTypes(t *testing.T) {
923926
PeerRules: map[route.Vertex]*SwapRule{
924927
peer2: inRule,
925928
},
926-
HtlcConfTarget: htlcConfTarget,
927-
SweepConfTarget: loop.DefaultSweepConfTarget,
929+
HtlcConfTarget: htlcConfTarget,
930+
SweepConfTarget: loop.DefaultSweepConfTarget,
931+
FastSwapPublication: false,
928932
}
929933
)
930934
c := newAutoloopTestCtx(t, params, channels, testRestrictions)
@@ -939,9 +943,11 @@ func TestAutoloopBothTypes(t *testing.T) {
939943
}
940944

941945
loopOutQuoteReq = &loop.LoopOutQuoteRequest{
942-
Amount: loopOutAmt,
943-
SweepConfTarget: params.SweepConfTarget,
944-
SwapPublicationDeadline: testTime,
946+
Amount: loopOutAmt,
947+
SweepConfTarget: params.SweepConfTarget,
948+
SwapPublicationDeadline: c.testClock.Now().Add(
949+
defaultSwapPublicationWaitTime,
950+
),
945951
}
946952

947953
prepayMaxFee, routeMaxFee,
@@ -962,6 +968,9 @@ func TestAutoloopBothTypes(t *testing.T) {
962968
},
963969
Label: labels.AutoloopLabel(swap.TypeOut),
964970
Initiator: autoloopSwapInitiator,
971+
SwapPublicationDeadline: c.testClock.Now().Add(
972+
defaultSwapPublicationWaitTime,
973+
),
965974
}
966975

967976
loopinQuote = &loop.LoopInQuote{
@@ -1069,7 +1078,8 @@ func TestAutoLoopRecurringBudget(t *testing.T) {
10691078
chanID1: chanRule,
10701079
chanID2: chanRule,
10711080
},
1072-
HtlcConfTarget: defaultHtlcConfTarget,
1081+
HtlcConfTarget: defaultHtlcConfTarget,
1082+
FastSwapPublication: true,
10731083
}
10741084
)
10751085

@@ -1320,6 +1330,7 @@ func TestEasyAutoloop(t *testing.T) {
13201330
EasyAutoloop: true,
13211331
EasyAutoloopTarget: 75000,
13221332
FeeLimit: defaultFeePortion(),
1333+
FastSwapPublication: true,
13231334
}
13241335
)
13251336

liquidity/loopout_builder.go

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package liquidity
33
import (
44
"context"
55
"encoding/hex"
6+
"time"
67

78
"github.com/btcsuite/btcd/btcutil"
89
"github.com/lightninglabs/loop"
@@ -14,6 +15,12 @@ import (
1415
"github.com/lightningnetwork/lnd/routing/route"
1516
)
1617

18+
const (
19+
// defaultSwapWaitTime is the default time we set as the deadline by
20+
// which we expect the swap to be published.
21+
defaultSwapPublicationWaitTime = 30 * time.Minute
22+
)
23+
1724
// Compile-time assertion that loopOutBuilder satisfies the swapBuilder
1825
// interface.
1926
var _ swapBuilder = (*loopOutBuilder)(nil)
@@ -151,11 +158,18 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
151158
initiator += "-" + assetSwap.assetID
152159
}
153160

161+
var swapPublicationDeadline time.Time
162+
if !params.FastSwapPublication {
163+
swapPublicationDeadline = b.cfg.Clock.Now().Add(
164+
defaultSwapPublicationWaitTime,
165+
)
166+
}
167+
154168
quote, err := b.cfg.LoopOutQuote(
155169
ctx, &loop.LoopOutQuoteRequest{
156170
Amount: amount,
157171
SweepConfTarget: params.SweepConfTarget,
158-
SwapPublicationDeadline: b.cfg.Clock.Now(),
172+
SwapPublicationDeadline: swapPublicationDeadline,
159173
Initiator: initiator,
160174
AssetRFQRequest: assetRfqRequest,
161175
},
@@ -193,16 +207,17 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
193207
// swap fee, prepay amount and miner fee from the quote because we have
194208
// already validated them.
195209
request := loop.OutRequest{
196-
Amount: amount,
197-
IsExternalAddr: false,
198-
OutgoingChanSet: chanSet,
199-
MaxPrepayRoutingFee: prepayMaxFee,
200-
MaxSwapRoutingFee: routeMaxFee,
201-
MaxMinerFee: minerFee,
202-
MaxSwapFee: quote.SwapFee,
203-
MaxPrepayAmount: quote.PrepayAmount,
204-
SweepConfTarget: params.SweepConfTarget,
205-
Initiator: initiator,
210+
Amount: amount,
211+
IsExternalAddr: false,
212+
OutgoingChanSet: chanSet,
213+
MaxPrepayRoutingFee: prepayMaxFee,
214+
MaxSwapRoutingFee: routeMaxFee,
215+
MaxMinerFee: minerFee,
216+
MaxSwapFee: quote.SwapFee,
217+
MaxPrepayAmount: quote.PrepayAmount,
218+
SweepConfTarget: params.SweepConfTarget,
219+
Initiator: initiator,
220+
SwapPublicationDeadline: swapPublicationDeadline,
206221
}
207222

208223
if opts.assetSwap != nil {

liquidity/parameters.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ var (
3131
SweepConfTarget: defaultConfTarget,
3232
HtlcConfTarget: defaultHtlcConfTarget,
3333
FeeLimit: defaultFeePortion(),
34+
FastSwapPublication: true,
3435
}
3536
)
3637

@@ -118,6 +119,11 @@ type Parameters struct {
118119
// AssetAutoloopParams maps an asset id hex encoded string to its
119120
// easy autoloop parameters.
120121
AssetAutoloopParams map[string]AssetParams
122+
123+
// FastSwapPublication controls publication deadline for new loop out
124+
// swaps. If set to true, the deadline is set to immediate publication.
125+
// If set to false, the deadline is set to 30 minutes.
126+
FastSwapPublication bool
121127
}
122128

123129
// AssetParams define the asset specific autoloop parameters.
@@ -460,10 +466,13 @@ func RpcToParameters(req *clientrpc.LiquidityParameters) (*Parameters,
460466
Minimum: btcutil.Amount(req.MinSwapAmount),
461467
Maximum: btcutil.Amount(req.MaxSwapAmount),
462468
},
463-
HtlcConfTarget: req.HtlcConfTarget,
464-
EasyAutoloop: req.EasyAutoloop,
465-
EasyAutoloopTarget: btcutil.Amount(req.EasyAutoloopLocalTargetSat),
469+
HtlcConfTarget: req.HtlcConfTarget,
470+
EasyAutoloop: req.EasyAutoloop,
471+
EasyAutoloopTarget: btcutil.Amount(
472+
req.EasyAutoloopLocalTargetSat,
473+
),
466474
AssetAutoloopParams: easyAssetParams,
475+
FastSwapPublication: req.FastSwapPublication,
467476
}
468477

469478
if req.AutoloopBudgetRefreshPeriodSec != 0 {
@@ -592,6 +601,7 @@ func ParametersToRpc(cfg Parameters) (*clientrpc.LiquidityParameters,
592601
Account: cfg.Account,
593602
AccountAddrType: addrType,
594603
EasyAssetParams: easyAssetMap,
604+
FastSwapPublication: cfg.FastSwapPublication,
595605
}
596606

597607
switch f := cfg.FeeLimit.(type) {

0 commit comments

Comments
 (0)