Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions cmd/loop/liquidity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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")
}
Expand Down
29 changes: 20 additions & 9 deletions liquidity/autoloop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ func TestAutoLoopEnabled(t *testing.T) {
chanID1: chanRule,
chanID2: chanRule,
},
HtlcConfTarget: defaultHtlcConfTarget,
HtlcConfTarget: defaultHtlcConfTarget,
FastSwapPublication: true,
}
)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -546,7 +548,8 @@ func TestCompositeRules(t *testing.T) {
PeerRules: map[route.Vertex]*SwapRule{
peer2: chanRule,
},
HtlcConfTarget: defaultHtlcConfTarget,
HtlcConfTarget: defaultHtlcConfTarget,
FastSwapPublication: true,
}
)

Expand Down Expand Up @@ -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)
Expand All @@ -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,
Expand All @@ -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{
Expand Down Expand Up @@ -1069,7 +1078,8 @@ func TestAutoLoopRecurringBudget(t *testing.T) {
chanID1: chanRule,
chanID2: chanRule,
},
HtlcConfTarget: defaultHtlcConfTarget,
HtlcConfTarget: defaultHtlcConfTarget,
FastSwapPublication: true,
}
)

Expand Down Expand Up @@ -1320,6 +1330,7 @@ func TestEasyAutoloop(t *testing.T) {
EasyAutoloop: true,
EasyAutoloopTarget: 75000,
FeeLimit: defaultFeePortion(),
FastSwapPublication: true,
}
)

Expand Down
37 changes: 26 additions & 11 deletions liquidity/loopout_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package liquidity
import (
"context"
"encoding/hex"
"time"

"github.com/btcsuite/btcd/btcutil"
"github.com/lightninglabs/loop"
Expand All @@ -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)
Expand Down Expand Up @@ -151,11 +158,18 @@ func (b *loopOutBuilder) buildSwap(ctx context.Context, pubkey route.Vertex,
initiator += "-" + assetSwap.assetID
}

var swapPublicationDeadline time.Time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be initialized as time.Now(), as now if you have set FastSwapPublication it will just be time.Time{}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the end-result is the same, we just want something that's presumably in the past. With that in mind the value should not matter and can just be empty for simplicity. wdyt?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thanks for the explanationj

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,
},
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 13 additions & 3 deletions liquidity/parameters.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
SweepConfTarget: defaultConfTarget,
HtlcConfTarget: defaultHtlcConfTarget,
FeeLimit: defaultFeePortion(),
FastSwapPublication: true,
}
)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
Loading