Skip to content

Commit fa0393b

Browse files
committed
multi: add OutAddr parameter for autoloop loop out
1 parent 0ef205c commit fa0393b

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

cmd/loop/liquidity.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,12 @@ var setParamsCommand = cli.Command{
286286
"of swaps, limited to the budget set by " +
287287
"autobudget",
288288
},
289+
cli.StringFlag{
290+
Name: "destaddr",
291+
Usage: "custom address to be used as destination for " +
292+
"autoloop loop out, set to \"default\" in " +
293+
"order to revert to default behavior",
294+
},
289295
cli.Uint64Flag{
290296
Name: "autobudget",
291297
Usage: "the maximum amount of fees in satoshis that " +
@@ -429,6 +435,11 @@ func setParams(ctx *cli.Context) error {
429435
flagSet = true
430436
}
431437

438+
if ctx.IsSet("destaddr") {
439+
params.AutoloopDestAddress = ctx.String("destaddr")
440+
flagSet = true
441+
}
442+
432443
if ctx.IsSet("budgetstart") {
433444
params.AutoloopBudgetStartSec = ctx.Uint64("budgetstart")
434445
flagSet = true

liquidity/liquidity.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,13 @@ func (m *Manager) autoloop(ctx context.Context) error {
380380

381381
// Create a copy of our range var so that we can reference it.
382382
swap := swap
383+
384+
// Check if the parameter for custom address is defined for loop
385+
// outs.
386+
if m.params.DestAddr != nil {
387+
swap.DestAddr = m.params.DestAddr
388+
}
389+
383390
loopOut, err := m.cfg.LoopOut(ctx, &swap)
384391
if err != nil {
385392
return err

liquidity/parameters.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ import (
1818

1919
var (
2020
// defaultParameters contains the default parameters that we start our
21-
// liquidity manger with.
21+
// liquidity manager with.
2222
defaultParameters = Parameters{
2323
AutoFeeBudget: defaultBudget,
24+
DestAddr: nil,
2425
MaxAutoInFlight: defaultMaxInFlight,
2526
ChannelRules: make(map[lnwire.ShortChannelID]*SwapRule),
2627
PeerRules: make(map[route.Vertex]*SwapRule),
@@ -37,6 +38,10 @@ type Parameters struct {
3738
// Autoloop enables automatic dispatch of swaps.
3839
Autoloop bool
3940

41+
// DestAddr is the address to be used for sweeping the on-chain HTLC that
42+
// is related with a loop out.
43+
DestAddr btcutil.Address
44+
4045
// AutoFeeBudget is the total amount we allow to be spent on
4146
// automatically dispatched swaps. Once this budget has been used, we
4247
// will stop dispatching swaps until the budget is increased or the
@@ -347,12 +352,25 @@ func rpcToParameters(req *clientrpc.LiquidityParameters) (*Parameters,
347352
return nil, err
348353
}
349354

355+
var destaddr btcutil.Address
356+
if len(req.AutoloopDestAddress) != 0 {
357+
if req.AutoloopDestAddress == "default" {
358+
destaddr = nil
359+
} else {
360+
destaddr, err = btcutil.DecodeAddress(req.AutoloopDestAddress, nil)
361+
if err != nil {
362+
return nil, err
363+
}
364+
}
365+
}
366+
350367
params := &Parameters{
351368
FeeLimit: feeLimit,
352369
SweepConfTarget: req.SweepConfTarget,
353370
FailureBackOff: time.Duration(req.FailureBackoffSec) *
354371
time.Second,
355372
Autoloop: req.Autoloop,
373+
DestAddr: destaddr,
356374
AutoFeeBudget: btcutil.Amount(req.AutoloopBudgetSat),
357375
MaxAutoInFlight: int(req.AutoMaxInFlight),
358376
ChannelRules: make(

loopd/swapclient_server.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,18 @@ func (s *swapClientServer) GetLiquidityParams(_ context.Context,
747747

748748
totalRules := len(cfg.ChannelRules) + len(cfg.PeerRules)
749749

750+
var destaddr string
751+
if cfg.DestAddr != nil {
752+
destaddr = cfg.DestAddr.String()
753+
}
754+
750755
rpcCfg := &clientrpc.LiquidityParameters{
751-
SweepConfTarget: cfg.SweepConfTarget,
752-
FailureBackoffSec: uint64(cfg.FailureBackOff.Seconds()),
753-
Autoloop: cfg.Autoloop,
754-
AutoloopBudgetSat: uint64(cfg.AutoFeeBudget),
755-
AutoMaxInFlight: uint64(cfg.MaxAutoInFlight),
756+
SweepConfTarget: cfg.SweepConfTarget,
757+
FailureBackoffSec: uint64(cfg.FailureBackOff.Seconds()),
758+
Autoloop: cfg.Autoloop,
759+
AutoloopBudgetSat: uint64(cfg.AutoFeeBudget),
760+
AutoMaxInFlight: uint64(cfg.MaxAutoInFlight),
761+
AutoloopDestAddress: destaddr,
756762
Rules: make(
757763
[]*clientrpc.LiquidityRule, 0, totalRules,
758764
),

0 commit comments

Comments
 (0)