Merge pull request #933 from lightninglabs/autoloop-slow-by-default

liquidity: default to slow swaps for autloop
This commit is contained in:
András Bánki-Horváth 2025-04-30 09:05:09 +02:00 committed by GitHub
commit a889d6226b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 709 additions and 627 deletions

View file

@ -367,6 +367,16 @@ var setParamsCommand = cli.Command{
Usage: "the target size of total local balance in " +
"asset units, used by asset easy autoloop.",
},
cli.BoolFlag{
Name: "fast",
Usage: "if set new swaps are expected to be " +
"published immediately, paying a potentially " +
"higher fee. If not set the swap server " +
"might choose to wait up to 30 minutes " +
"before publishing swap HTLCs on-chain, to " +
"save on chain fees. Not setting this flag " +
"therefore might result in a lower swap fees",
},
},
Action: setParams,
}
@ -577,6 +587,10 @@ func setParams(ctx *cli.Context) error {
flagSet = true
}
if ctx.IsSet("fast") {
params.FastSwapPublication = true
}
if !flagSet {
return fmt.Errorf("at least one flag required to set params")
}

View file

@ -117,7 +117,8 @@ func TestAutoLoopEnabled(t *testing.T) {
chanID1: chanRule,
chanID2: chanRule,
},
HtlcConfTarget: defaultHtlcConfTarget,
HtlcConfTarget: defaultHtlcConfTarget,
FastSwapPublication: true,
}
)
@ -376,7 +377,8 @@ func TestAutoloopAddress(t *testing.T) {
chanID1: chanRule,
chanID2: chanRule,
},
HtlcConfTarget: defaultHtlcConfTarget,
HtlcConfTarget: defaultHtlcConfTarget,
FastSwapPublication: true,
}
)
c := newAutoloopTestCtx(t, params, channels, testRestrictions)
@ -546,7 +548,8 @@ func TestCompositeRules(t *testing.T) {
PeerRules: map[route.Vertex]*SwapRule{
peer2: chanRule,
},
HtlcConfTarget: defaultHtlcConfTarget,
HtlcConfTarget: defaultHtlcConfTarget,
FastSwapPublication: true,
}
)
@ -923,8 +926,9 @@ func TestAutoloopBothTypes(t *testing.T) {
PeerRules: map[route.Vertex]*SwapRule{
peer2: inRule,
},
HtlcConfTarget: htlcConfTarget,
SweepConfTarget: loop.DefaultSweepConfTarget,
HtlcConfTarget: htlcConfTarget,
SweepConfTarget: loop.DefaultSweepConfTarget,
FastSwapPublication: false,
}
)
c := newAutoloopTestCtx(t, params, channels, testRestrictions)
@ -939,9 +943,11 @@ func TestAutoloopBothTypes(t *testing.T) {
}
loopOutQuoteReq = &loop.LoopOutQuoteRequest{
Amount: loopOutAmt,
SweepConfTarget: params.SweepConfTarget,
SwapPublicationDeadline: testTime,
Amount: loopOutAmt,
SweepConfTarget: params.SweepConfTarget,
SwapPublicationDeadline: c.testClock.Now().Add(
defaultSwapPublicationWaitTime,
),
}
prepayMaxFee, routeMaxFee,
@ -962,6 +968,9 @@ func TestAutoloopBothTypes(t *testing.T) {
},
Label: labels.AutoloopLabel(swap.TypeOut),
Initiator: autoloopSwapInitiator,
SwapPublicationDeadline: c.testClock.Now().Add(
defaultSwapPublicationWaitTime,
),
}
loopinQuote = &loop.LoopInQuote{
@ -1069,7 +1078,8 @@ func TestAutoLoopRecurringBudget(t *testing.T) {
chanID1: chanRule,
chanID2: chanRule,
},
HtlcConfTarget: defaultHtlcConfTarget,
HtlcConfTarget: defaultHtlcConfTarget,
FastSwapPublication: true,
}
)
@ -1320,6 +1330,7 @@ func TestEasyAutoloop(t *testing.T) {
EasyAutoloop: true,
EasyAutoloopTarget: 75000,
FeeLimit: defaultFeePortion(),
FastSwapPublication: true,
}
)

View file

@ -3,6 +3,7 @@ package liquidity
import (
"context"
"encoding/hex"
"time"
"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/loop"
@ -14,6 +15,12 @@ import (
"github.com/lightningnetwork/lnd/routing/route"
)
const (
// defaultSwapWaitTime is the default time we set as the deadline by
// which we expect the swap to be published.
defaultSwapPublicationWaitTime = 30 * time.Minute
)
// Compile-time assertion that loopOutBuilder satisfies the swapBuilder
// interface.
var _ swapBuilder = (*loopOutBuilder)(nil)
@ -151,11 +158,18 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
initiator += "-" + assetSwap.assetID
}
var swapPublicationDeadline time.Time
if !params.FastSwapPublication {
swapPublicationDeadline = b.cfg.Clock.Now().Add(
defaultSwapPublicationWaitTime,
)
}
quote, err := b.cfg.LoopOutQuote(
ctx, &loop.LoopOutQuoteRequest{
Amount: amount,
SweepConfTarget: params.SweepConfTarget,
SwapPublicationDeadline: b.cfg.Clock.Now(),
SwapPublicationDeadline: swapPublicationDeadline,
Initiator: initiator,
AssetRFQRequest: assetRfqRequest,
},
@ -193,16 +207,17 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
// swap fee, prepay amount and miner fee from the quote because we have
// already validated them.
request := loop.OutRequest{
Amount: amount,
IsExternalAddr: false,
OutgoingChanSet: chanSet,
MaxPrepayRoutingFee: prepayMaxFee,
MaxSwapRoutingFee: routeMaxFee,
MaxMinerFee: minerFee,
MaxSwapFee: quote.SwapFee,
MaxPrepayAmount: quote.PrepayAmount,
SweepConfTarget: params.SweepConfTarget,
Initiator: initiator,
Amount: amount,
IsExternalAddr: false,
OutgoingChanSet: chanSet,
MaxPrepayRoutingFee: prepayMaxFee,
MaxSwapRoutingFee: routeMaxFee,
MaxMinerFee: minerFee,
MaxSwapFee: quote.SwapFee,
MaxPrepayAmount: quote.PrepayAmount,
SweepConfTarget: params.SweepConfTarget,
Initiator: initiator,
SwapPublicationDeadline: swapPublicationDeadline,
}
if opts.assetSwap != nil {

View file

@ -31,6 +31,7 @@ var (
SweepConfTarget: defaultConfTarget,
HtlcConfTarget: defaultHtlcConfTarget,
FeeLimit: defaultFeePortion(),
FastSwapPublication: true,
}
)
@ -118,6 +119,11 @@ type Parameters struct {
// AssetAutoloopParams maps an asset id hex encoded string to its
// easy autoloop parameters.
AssetAutoloopParams map[string]AssetParams
// FastSwapPublication controls publication deadline for new loop out
// swaps. If set to true, the deadline is set to immediate publication.
// If set to false, the deadline is set to 30 minutes.
FastSwapPublication bool
}
// AssetParams define the asset specific autoloop parameters.
@ -460,10 +466,13 @@ func RpcToParameters(req *clientrpc.LiquidityParameters) (*Parameters,
Minimum: btcutil.Amount(req.MinSwapAmount),
Maximum: btcutil.Amount(req.MaxSwapAmount),
},
HtlcConfTarget: req.HtlcConfTarget,
EasyAutoloop: req.EasyAutoloop,
EasyAutoloopTarget: btcutil.Amount(req.EasyAutoloopLocalTargetSat),
HtlcConfTarget: req.HtlcConfTarget,
EasyAutoloop: req.EasyAutoloop,
EasyAutoloopTarget: btcutil.Amount(
req.EasyAutoloopLocalTargetSat,
),
AssetAutoloopParams: easyAssetParams,
FastSwapPublication: req.FastSwapPublication,
}
if req.AutoloopBudgetRefreshPeriodSec != 0 {
@ -592,6 +601,7 @@ func ParametersToRpc(cfg Parameters) (*clientrpc.LiquidityParameters,
Account: cfg.Account,
AccountAddrType: addrType,
EasyAssetParams: easyAssetMap,
FastSwapPublication: cfg.FastSwapPublication,
}
switch f := cfg.FeeLimit.(type) {

File diff suppressed because it is too large Load diff

View file

@ -1227,6 +1227,14 @@ message LiquidityParameters {
value is the parameters to use for swaps in that asset.
*/
map<string, EasyAssetAutoloopParams> easy_asset_params = 25;
/*
* Set to true to enable fast swap publication. If set, the server will
* publish the HTLC immediately after receiving the swap request. This
* setting has direct implications on the swap fees, as fast swaps may
* not be able to be batched with other swaps.
*/
bool fast_swap_publication = 26;
}
message EasyAssetAutoloopParams {

View file

@ -1296,6 +1296,10 @@
"$ref": "#/definitions/looprpcEasyAssetAutoloopParams"
},
"description": "A map of asset parameters to use for swaps. The key is the asset id and the\nvalue is the parameters to use for swaps in that asset."
},
"fast_swap_publication": {
"type": "boolean",
"description": "Set to true to enable fast swap publication. If set, the server will\npublish the HTLC immediately after receiving the swap request. This\nsetting has direct implications on the swap fees, as fast swaps may\nnot be able to be batched with other swaps."
}
}
},

View file

@ -18,6 +18,11 @@ This file tracks release notes for the loop client.
#### Breaking Changes
* Autoloop now defaults to a slow publication deadline (30 minutes after
initiation) to reduce fees. To revert to the previous behavior, users can run
`loop setparams --fast`, which causes swap HTLCs to be published immediately
after initiation.
#### Bug Fixes
#### Maintenance