Skip to content

Commit

Permalink
docs(README.md): update README with additional information about the …
Browse files Browse the repository at this point in the history
…CLI tool and its requirements, build & test instructions, dev environment setup, and exposed metrics

feat(flags.go): add flags for sleepBetweenRetries, sleepBetweenRetriesBackoff, and sleepMax to allow configuring sleep intervals and backoff for retries
refactor(liquidator.go): refactor variable declarations for better readability and add new variables for sleep intervals and backoff
  • Loading branch information
markettes committed Mar 27, 2024
1 parent 76ca6e9 commit 31efe71
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 19 deletions.
52 changes: 39 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# NodeGuard Liquidator

[![Go Report Card](https://goreportcard.com/badge/github.com/Elenpay/liquidator)](https://goreportcard.com/report/github.com/Elenpay/liquidator)

<p align="center">
<img src="liquidator.png" width="100px" />
</p>

# Description

A CLI tool to monitor and automate the liquidity of your LND channels

```
Usage:
liquidator [flags]
Expand All @@ -25,8 +29,11 @@ Flags:
--swapPublicationOffset string Swap publication deadline offset (Maximum time for the swap provider to publish the swap) (default "60m")
--sweepConfTarget string Target number of confirmations for swaps, this uses bitcoin core broken estimator, procced with caution (default "400")
```

# Requirements

This project uses [just](https://github.com/casey/just) with the following recipes

```
Available recipes:
build
Expand All @@ -50,6 +57,7 @@ Available recipes:
test
unzip-loopd-datadir
```

# Environment Variables / Flags

All the flags can be set as environment variables, with the following format, except stated, they are all mandatory:
Expand All @@ -64,53 +72,71 @@ All the flags can be set as environment variables, with the following format, ex
- RETRIESBEFOREBACKOFF (optional) : Number of retries before applying backoff to the swap (default: 3)
- BACKOFFCOEFFICIENT (optional) : Coefficient to apply to the backoff (default: 0.95)
- BACKOFFLIMIT (optional) : Limit coefficient of the backoff (default: 0.1)
- SLEEPBETWEENRETRIESMS (optional) : Base time to sleep between retries (default: 500ms)
- SLEEPBETWEENRETRIESBACKOFF (optional) : Coefficient to apply to the backoff (default: 1.05)
- SLEEPMAX (optional) : Maximum time to sleep between retries (default: 60)

# Build & test

## Build

```
just build
```

## Testing

```
just test
```

# Dev environment

1. Launch a local regtest with polar from regtest.polar.zip
2. Lauch with VS Code pre-defined configuration

## Setup loop/loopd/loopserver regtest environment

1. Make sure your regtest.polar.zip network in polar is running
2. Unzip loopd datadir
````

```
just unzip-loopd-datadir
````
```

3. Get git submodules
````

```
just init-submodules
````
```

4. Compile and install loopd/loop binaries (Make sure your golang install bin dir is reachable from your PATH)
````

```
just install-loopd-loop
````
```

5. Using just, run the following command:
````

```
just start-all
````
```

6. This comand should have build a `loopserver `docker image, and started a `loopserver` container along with loopd as a native binary.

## Loop just recipes
There are a few recipes using `just -l` to interact with loopd for loop in, loop out and calling loop CLI with args (`just loop <args>`).



There are a few recipes using `just -l` to interact with loopd for loop in, loop out and calling loop CLI with args (`just loop <args>`).

# Metrics

The following metrics are exposed in the `/metrics` endpoint on port `9000` (e.g. `localhost:9000/metrics`)):

- `liquidator_channel_balance`: Channel balance ratio in 0 to 1 range, 0 means all the balance is on the local side of the channel, 1 means all the balance is on the remote side of the channel

Example:
```

```
liquidator_channel_balance{active="false",chan_id="118747255865345",local_node_alias="alice",local_node_pubkey="03b48034270e522e4033afdbe43383d66d426638927b940d09a8a7a0de4d96e807",remote_node_alias="",remote_node_pubkey="02f97d034c6c8f5ad95b1fe6abfe68ab154e85b1f5bb909815baeb5c8a46cdf622",initiator="false"} 0.99
liquidator_channel_balance{active="false",chan_id="125344325632000",local_node_alias="alice",local_node_pubkey="03b48034270e522e4033afdbe43383d66d426638927b940d09a8a7a0de4d96e807",remote_node_alias="",remote_node_pubkey="02f97d034c6c8f5ad95b1fe6abfe68ab154e85b1f5bb909815baeb5c8a46cdf622",initiator="false"} 0
Expand Down
17 changes: 17 additions & 0 deletions flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package main
import (
"os"
"strings"
"time"

log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -121,6 +122,18 @@ func init() {
rootCmd.Flags().String("sweepConfTarget", "400", "Target number of confirmations for swaps, this uses bitcoin core broken estimator, procced with caution")
viper.BindPFlag("sweepConfTarget", rootCmd.Flags().Lookup("sweepConfTarget"))

//Sleep between retries
rootCmd.Flags().Duration("sleepBetweenRetries", 500*time.Millisecond, "Sleep between retries")
viper.BindPFlag("sleepBetweenRetries", rootCmd.Flags().Lookup("sleepBetweenRetries"))

//Sleep between retries backoff
rootCmd.Flags().Float64("sleepBetweenRetriesBackoff", 1.5, "Sleep between retries backoff")
viper.BindPFlag("sleepBetweenRetriesBackoff", rootCmd.Flags().Lookup("sleepBetweenRetriesBackoff"))

//Sleep max
rootCmd.Flags().Duration("sleepMax", 60*time.Second, "Sleep max")
viper.BindPFlag("sleepMax", rootCmd.Flags().Lookup("sleepMax"))

//Now we set the global vars

pollingInterval = viper.GetDuration("pollingInterval")
Expand All @@ -133,6 +146,10 @@ func init() {
backoffLimit = viper.GetFloat64("backoffLimit")
limitFees = viper.GetFloat64("limitFees")

sleepBetweenRetries = viper.GetDuration("sleepBetweenRetries")
sleepBetweenRetriesBackoff = viper.GetFloat64("sleepBetweenRetriesBackoff")
sleepMax = viper.GetDuration("sleepMax")

//Set log level and format

logLevel, err := log.ParseLevel(viper.GetString("logLevel"))
Expand Down
15 changes: 9 additions & 6 deletions liquidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ import (
)

var (
prometheusMetrics *metrics
rulesCache cache.Cache
retries int
backoffCoefficient float64
backoffLimit float64
limitFees float64
prometheusMetrics *metrics
rulesCache cache.Cache
retries int
backoffCoefficient float64
backoffLimit float64
limitFees float64
sleepBetweenRetries time.Duration
sleepBetweenRetriesBackoff float64
sleepMax time.Duration
)

// Entrypoint of liquidator main logic
Expand Down

0 comments on commit 31efe71

Please sign in to comment.