From fa0393b3313533d6fdc9d397b03b518cb2933996 Mon Sep 17 00:00:00 2001 From: George Tsagkarelis Date: Tue, 6 Dec 2022 16:08:56 +0200 Subject: [PATCH] multi: add OutAddr parameter for autoloop loop out --- cmd/loop/liquidity.go | 11 +++++++++++ liquidity/liquidity.go | 7 +++++++ liquidity/parameters.go | 20 +++++++++++++++++++- loopd/swapclient_server.go | 16 +++++++++++----- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/cmd/loop/liquidity.go b/cmd/loop/liquidity.go index b0f4b08..f02cd7e 100644 --- a/cmd/loop/liquidity.go +++ b/cmd/loop/liquidity.go @@ -286,6 +286,12 @@ var setParamsCommand = cli.Command{ "of swaps, limited to the budget set by " + "autobudget", }, + cli.StringFlag{ + Name: "destaddr", + Usage: "custom address to be used as destination for " + + "autoloop loop out, set to \"default\" in " + + "order to revert to default behavior", + }, cli.Uint64Flag{ Name: "autobudget", Usage: "the maximum amount of fees in satoshis that " + @@ -429,6 +435,11 @@ func setParams(ctx *cli.Context) error { flagSet = true } + if ctx.IsSet("destaddr") { + params.AutoloopDestAddress = ctx.String("destaddr") + flagSet = true + } + if ctx.IsSet("budgetstart") { params.AutoloopBudgetStartSec = ctx.Uint64("budgetstart") flagSet = true diff --git a/liquidity/liquidity.go b/liquidity/liquidity.go index a706358..6af48c0 100644 --- a/liquidity/liquidity.go +++ b/liquidity/liquidity.go @@ -380,6 +380,13 @@ func (m *Manager) autoloop(ctx context.Context) error { // Create a copy of our range var so that we can reference it. swap := swap + + // Check if the parameter for custom address is defined for loop + // outs. + if m.params.DestAddr != nil { + swap.DestAddr = m.params.DestAddr + } + loopOut, err := m.cfg.LoopOut(ctx, &swap) if err != nil { return err diff --git a/liquidity/parameters.go b/liquidity/parameters.go index 35cfb67..319fd89 100644 --- a/liquidity/parameters.go +++ b/liquidity/parameters.go @@ -18,9 +18,10 @@ import ( var ( // defaultParameters contains the default parameters that we start our - // liquidity manger with. + // liquidity manager with. defaultParameters = Parameters{ AutoFeeBudget: defaultBudget, + DestAddr: nil, MaxAutoInFlight: defaultMaxInFlight, ChannelRules: make(map[lnwire.ShortChannelID]*SwapRule), PeerRules: make(map[route.Vertex]*SwapRule), @@ -37,6 +38,10 @@ type Parameters struct { // Autoloop enables automatic dispatch of swaps. Autoloop bool + // DestAddr is the address to be used for sweeping the on-chain HTLC that + // is related with a loop out. + DestAddr btcutil.Address + // AutoFeeBudget is the total amount we allow to be spent on // automatically dispatched swaps. Once this budget has been used, we // will stop dispatching swaps until the budget is increased or the @@ -347,12 +352,25 @@ func rpcToParameters(req *clientrpc.LiquidityParameters) (*Parameters, return nil, err } + var destaddr btcutil.Address + if len(req.AutoloopDestAddress) != 0 { + if req.AutoloopDestAddress == "default" { + destaddr = nil + } else { + destaddr, err = btcutil.DecodeAddress(req.AutoloopDestAddress, nil) + if err != nil { + return nil, err + } + } + } + params := &Parameters{ FeeLimit: feeLimit, SweepConfTarget: req.SweepConfTarget, FailureBackOff: time.Duration(req.FailureBackoffSec) * time.Second, Autoloop: req.Autoloop, + DestAddr: destaddr, AutoFeeBudget: btcutil.Amount(req.AutoloopBudgetSat), MaxAutoInFlight: int(req.AutoMaxInFlight), ChannelRules: make( diff --git a/loopd/swapclient_server.go b/loopd/swapclient_server.go index 2d11cfa..45c8f55 100644 --- a/loopd/swapclient_server.go +++ b/loopd/swapclient_server.go @@ -747,12 +747,18 @@ func (s *swapClientServer) GetLiquidityParams(_ context.Context, totalRules := len(cfg.ChannelRules) + len(cfg.PeerRules) + var destaddr string + if cfg.DestAddr != nil { + destaddr = cfg.DestAddr.String() + } + rpcCfg := &clientrpc.LiquidityParameters{ - SweepConfTarget: cfg.SweepConfTarget, - FailureBackoffSec: uint64(cfg.FailureBackOff.Seconds()), - Autoloop: cfg.Autoloop, - AutoloopBudgetSat: uint64(cfg.AutoFeeBudget), - AutoMaxInFlight: uint64(cfg.MaxAutoInFlight), + SweepConfTarget: cfg.SweepConfTarget, + FailureBackoffSec: uint64(cfg.FailureBackOff.Seconds()), + Autoloop: cfg.Autoloop, + AutoloopBudgetSat: uint64(cfg.AutoFeeBudget), + AutoMaxInFlight: uint64(cfg.MaxAutoInFlight), + AutoloopDestAddress: destaddr, Rules: make( []*clientrpc.LiquidityRule, 0, totalRules, ),