Skip to content

Commit afc41ad

Browse files
authored
Merge pull request #295 from carlaKC/205-autoout
liquidity: add budget-limited autoloop
2 parents 24523b5 + 24fb50a commit afc41ad

20 files changed

+1549
-203
lines changed

cmd/loop/liquidity.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,30 @@ var setParamsCommand = cli.Command{
224224
"previously had a failed swap will be " +
225225
"included in suggestions.",
226226
},
227+
cli.BoolFlag{
228+
Name: "autoout",
229+
Usage: "set to true to enable automated dispatch " +
230+
"of loop out swaps, limited to the budget " +
231+
"set by autobudget",
232+
},
233+
cli.Uint64Flag{
234+
Name: "autobudget",
235+
Usage: "the maximum amount of fees in satoshis that " +
236+
"automatically dispatched loop out swaps may " +
237+
"spend",
238+
},
239+
cli.Uint64Flag{
240+
Name: "budgetstart",
241+
Usage: "the start time for the automated loop " +
242+
"out budget, expressed as a unix timestamp " +
243+
"in seconds",
244+
},
245+
cli.Uint64Flag{
246+
Name: "autoinflight",
247+
Usage: "the maximum number of automatically " +
248+
"dispatched swaps that we allow to be in " +
249+
"flight",
250+
},
227251
},
228252
Action: setParams,
229253
}
@@ -304,6 +328,26 @@ func setParams(ctx *cli.Context) error {
304328
flagSet = true
305329
}
306330

331+
if ctx.IsSet("autoout") {
332+
params.AutoLoopOut = ctx.Bool("autoout")
333+
flagSet = true
334+
}
335+
336+
if ctx.IsSet("autobudget") {
337+
params.AutoOutBudgetSat = ctx.Uint64("autobudget")
338+
flagSet = true
339+
}
340+
341+
if ctx.IsSet("budgetstart") {
342+
params.AutoOutBudgetStartSec = ctx.Uint64("budgetstart")
343+
flagSet = true
344+
}
345+
346+
if ctx.IsSet("autoinflight") {
347+
params.AutoMaxInFlight = ctx.Uint64("autoinflight")
348+
flagSet = true
349+
}
350+
307351
if !flagSet {
308352
return fmt.Errorf("at least one flag required to set params")
309353
}

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ require (
1616
github.com/lightningnetwork/lnd/cert v1.0.3
1717
github.com/lightningnetwork/lnd/clock v1.0.1
1818
github.com/lightningnetwork/lnd/queue v1.0.4
19+
github.com/lightningnetwork/lnd/ticker v1.0.0
1920
github.com/stretchr/testify v1.5.1
2021
github.com/urfave/cli v1.20.0
2122
golang.org/x/net v0.0.0-20191002035440-2ec189313ef0

go.sum

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
2+
git.schwanenlied.me/yawning/bsaes.git v0.0.0-20180720073208-c0276d75487e h1:F2x1bq7RaNCIuqYpswggh1+c1JmwdnkHNC9wy1KDip0=
23
git.schwanenlied.me/yawning/bsaes.git v0.0.0-20180720073208-c0276d75487e/go.mod h1:BWqTsj8PgcPriQJGl7el20J/7TuT1d/hSyFDXMEpoEo=
34
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
45
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
6+
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e h1:n+DcnTNkQnHlwpsrHoQtkrJIO7CBx029fw6oR4vIob4=
57
github.com/NebulousLabs/fastrand v0.0.0-20181203155948-6fb6489aac4e/go.mod h1:Bdzq+51GR4/0DIhaICZEOm+OHvXGwwB2trKZ8B4Y6eQ=
8+
github.com/NebulousLabs/go-upnp v0.0.0-20180202185039-29b680b06c82 h1:MG93+PZYs9PyEsj/n5/haQu2gK0h4tUtSy9ejtMwWa0=
69
github.com/NebulousLabs/go-upnp v0.0.0-20180202185039-29b680b06c82/go.mod h1:GbuBk21JqF+driLX3XtJYNZjGa45YDoa9IqCTzNSfEc=
710
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
11+
github.com/Yawning/aez v0.0.0-20180114000226-4dad034d9db2 h1:2be4ykKKov3M1yISM2E8gnGXZ/N2SsPawfnGiXxaYEU=
812
github.com/Yawning/aez v0.0.0-20180114000226-4dad034d9db2/go.mod h1:9pIqrY6SXNL8vjRQE5Hd/OL5GyK/9MrGUWs87z/eFfk=
913
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da h1:KjTM2ks9d14ZYCvmHS9iAKVt9AyzRSqNU1qabPih5BY=
1014
github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da/go.mod h1:eHEWzANqSiWQsof+nXEI9bUVUyV6F53Fp89EuCh2EAA=
@@ -131,7 +135,9 @@ github.com/grpc-ecosystem/grpc-gateway v1.14.3 h1:OCJlWkOUoTnl0neNGlf4fUm3TmbEtg
131135
github.com/grpc-ecosystem/grpc-gateway v1.14.3/go.mod h1:6CwZWGDSPRJidgKAtJVvND6soZe6fT7iteq8wDPdhb0=
132136
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
133137
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
138+
github.com/jackpal/gateway v1.0.5 h1:qzXWUJfuMdlLMtt0a3Dgt+xkWQiA5itDEITVJtuSwMc=
134139
github.com/jackpal/gateway v1.0.5/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
140+
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad h1:heFfj7z0pGsNCekUlsFhO2jstxO4b5iQ665LjwM5mDc=
135141
github.com/jackpal/go-nat-pmp v0.0.0-20170405195558-28a68d0c24ad/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc=
136142
github.com/jedib0t/go-pretty v4.3.0+incompatible/go.mod h1:XemHduiw8R651AF9Pt4FwCTKeG3oo7hrHJAoznj9nag=
137143
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
@@ -253,6 +259,7 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
253259
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
254260
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 h1:LnC5Kc/wtumK+WB441p7ynQJzVuNRJiqddSIE3IlSEQ=
255261
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
262+
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02 h1:tcJ6OjwOMvExLlzrAVZute09ocAGa7KqOON60++Gz4E=
256263
github.com/tv42/zbase32 v0.0.0-20160707012821-501572607d02/go.mod h1:tHlrkM198S068ZqfrO6S8HsoJq2bF3ETfTL+kt4tInY=
257264
github.com/urfave/cli v1.18.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA=
258265
github.com/urfave/cli v1.20.0 h1:fDqGv3UG/4jbVl/QkFwEdddtEDjh/5Ov6X+0B/3bPaw=

labels/labels.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package labels
22

33
import (
44
"errors"
5+
"fmt"
6+
"strings"
57
)
68

79
const (
@@ -11,6 +13,10 @@ const (
1113
// Reserved is used as a prefix to separate labels that are created by
1214
// loopd from those created by users.
1315
Reserved = "[reserved]"
16+
17+
// autoOut is the label used for loop out swaps that are automatically
18+
// dispatched.
19+
autoOut = "autoloop-out"
1420
)
1521

1622
var (
@@ -22,23 +28,23 @@ var (
2228
ErrReservedPrefix = errors.New("label contains reserved prefix")
2329
)
2430

31+
// AutoOutLabel returns a label with the reserved prefix that identifies
32+
// automatically dispatched loop outs.
33+
func AutoOutLabel() string {
34+
return fmt.Sprintf("%v: %v", Reserved, autoOut)
35+
}
36+
2537
// Validate checks that a label is of appropriate length and is not in our list
2638
// of reserved labels.
2739
func Validate(label string) error {
2840
if len(label) > MaxLength {
2941
return ErrLabelTooLong
3042
}
3143

32-
// If the label is shorter than our reserved prefix, it cannot contain
33-
// it.
34-
if len(label) < len(Reserved) {
35-
return nil
36-
}
37-
3844
// Check if our label begins with our reserved prefix. We don't mind if
3945
// it has our reserved prefix in another case, we just need to be able
4046
// to reserve a subset of labels with this prefix.
41-
if label[0:len(Reserved)] == Reserved {
47+
if strings.HasPrefix(label, Reserved) {
4248
return ErrReservedPrefix
4349
}
4450

0 commit comments

Comments
 (0)