Skip to content

Commit fe42664

Browse files
authored
Merge pull request #332 from carlaKC/autoloop-1-disqualified
autoloop: add reasons to explain no action
2 parents 67f4171 + cf50ffd commit fe42664

File tree

10 files changed

+1054
-357
lines changed

10 files changed

+1054
-357
lines changed

cmd/loop/liquidity.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"strconv"
78

89
"github.com/lightninglabs/loop/liquidity"
910
"github.com/lightninglabs/loop/looprpc"
1011
"github.com/urfave/cli"
12+
"google.golang.org/grpc/codes"
13+
"google.golang.org/grpc/status"
1114
)
1215

1316
var getLiquidityParamsCommand = cli.Command{
@@ -411,11 +414,22 @@ func suggestSwap(ctx *cli.Context) error {
411414
resp, err := client.SuggestSwaps(
412415
context.Background(), &looprpc.SuggestSwapsRequest{},
413416
)
414-
if err != nil {
417+
if err == nil {
418+
printRespJSON(resp)
419+
return nil
420+
}
421+
422+
// If we got an error because no rules are set, we want to display a
423+
// friendly message.
424+
rpcErr, ok := status.FromError(err)
425+
if !ok {
415426
return err
416427
}
417428

418-
printJSON(resp)
429+
if rpcErr.Code() != codes.FailedPrecondition {
430+
return err
431+
}
419432

420-
return nil
433+
return errors.New("no rules set for autolooper, please set rules " +
434+
"using the setrule command")
421435
}

docs/autoloop.md

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,51 @@ in manually dispatched swaps - for loop out, this would mean the channel is
224224
specified in the outgoing channel swap, and for loop in the channel's peer is
225225
specified as the last hop for an ongoing swap. This check is put in place to
226226
prevent the autolooper from interfering with swaps you have created yourself.
227-
If there is an ongoing swap that does not have a restriction placed on it (no
228-
outgoing channel set, or last hop), then the autolooper will take no action
229-
until it has resolved, because it does not know how that swap will affect
230-
liquidity balances.
231227

228+
## Disqualified Swaps
229+
There are various restrictions placed on the client's autoloop functionality.
230+
If a channel is not eligible for a swap at present, or it does not need one
231+
based on the current set of liquidity rules, it will be listed in the
232+
`Disqualified` section of the output of the `SuggestSwaps` API. One of the
233+
following reasons will be displayed:
234+
235+
* Budget not started: if the start date for your budget is in the future,
236+
no swaps will be executed until the start date is reached. See [budget](#budget) to
237+
update.
238+
* Budget elapsed: if the autolooper has elapsed the budget assigned to it for
239+
fees, this reason will be returned. See [budget](#budget) to update.
240+
* Sweep fees: this reason will be displayed if the estimated chain fee rate for
241+
sweeping a loop out swap is higher than the current limit. See [sweep fees](#fee-market-awareness)
242+
to update.
243+
* In flight: there is a limit to the number of automatically dispatched swaps
244+
that the client allows. If this limit has been reached, no further swaps
245+
will be automatically dispatched until the in-flight swaps complete. See
246+
[in flight limit](#in-flight-limit) to update.
247+
* Budget insufficient: if there is not enough remaining budget for a swap,
248+
including the amount currently reserved for in flight swaps, an insufficient
249+
reason will be displayed. This differs from budget elapsed because there is
250+
still budget remaining, just not enough to execute a specific swap.
251+
* Swap fee: there is a limit placed on the fee that the client will pay to the
252+
server for automatically dispatched swaps. The swap fee reason will be shown
253+
if the fees advertised by the server are too high. See [swap fee](#swap-fee)
254+
to update.
255+
* Miner fee: if the estimated on-chain fees for a swap are too high, autoloop
256+
will display a miner fee reason. See [miner fee](#miner-fee) to update.
257+
* Prepay: if the no-show fee that the server will pay in the unlikely event
258+
that the client fails to complete a swap is too high, a prepay reason will
259+
be returned. See [no show fees](#no-show-fee) to update.
260+
* Backoff: if an automatically dispatched swap has recently failed for a channel,
261+
autoloop will backoff for a period before retrying. See [failure backoff](#failure-backoff)
262+
to update.
263+
* Loop out: if there is currently a loop out swap in-flight on a channel, it
264+
will not be used for automated swaps. This issue will resolve itself once the
265+
in-flight swap completes.
266+
* Loop in: if there is currently a loop in swap in-flight for a peer, it will
267+
not be used for automated swaps. This will resolve itself once the swap is
268+
completed.
269+
* Liquidity ok: if a channel's current liquidity balance is within the bound set
270+
by the rule that it applies to, then a liquidity ok reason will be displayed
271+
to indicate that no action is required for that channel.
272+
273+
Further details for all of these reasons can be found in loopd's debug level
274+
logs.

0 commit comments

Comments
 (0)