From 04783c561eb033e48fd35c96daa9eea22af4b467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20A=2EP?= Date: Fri, 12 Jan 2024 15:07:22 +0100 Subject: [PATCH] feat(Dockerfile): upgrade golang version from 1.20.4 to 1.21.4 for latest features and security updates docs(README.md): update flags documentation to reflect recent changes and additions feat(flags.go): increase swapPublicationOffset from 30m to 60m for more flexibility feat(flags.go): add new flag sweepConfTarget for configurable confirmation targets refactor(loop_provider.go): replace hardcoded SweepConfTarget with configurable value from flags fix(loop_provider.go): remove unnecessary whitespace for cleaner code --- Dockerfile | 2 +- README.md | 11 ++++++----- flags.go | 6 +++++- provider/loop_provider.go | 4 ++-- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index d3598bb..cdd4158 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.4-alpine AS builder +FROM golang:1.21.4-alpine AS builder WORKDIR /src/ COPY . . RUN go get -d -v ./... diff --git a/README.md b/README.md index c1cd2b0..49d2b45 100644 --- a/README.md +++ b/README.md @@ -11,18 +11,19 @@ Usage: liquidator [flags] Flags: + --backoffCoefficient float Coefficient to apply to the backoff (default 0.95) + --backoffLimit float Limit coefficient of the backoff (default 0.1) -h, --help help for liquidator + --limitFees float Limit fees for swaps e.g. 0.01 = 1% (default 0.007) --lndconnecturis string CSV of lndconnect strings to connect to lnd(s) - --backoffCoefficient float Coefficient to apply to the backoff (default: 0.95) - --backoffLimit float Limit coefficient of the backoff (default: 0.1) - --limitFees float Limit to total Swap Fees (default 0.007 -> 0.7% Swap size) --logFormat string Log format from: {text, json} (default "text") --logLevel string Log level from values: {trace, debug, info, warn, error, fatal, panic} (default "info") --loopdconnecturis string CSV of loopdconnect strings to connect to loopd(s) --nodeguardHost string Hostname:port to connect to nodeguard --pollingInterval string Interval to poll data (default "15s") - --retriesBeforeBackoff int Number of retries before applying backoff to the swap (default: 3) - --swapPublicationOffset string Swap publication deadline offset (Maximum time for the swap provider to publish the swap) (default "30m") + --retriesBeforeBackoff int Number of retries before applying backoff to the swap (default 3) + --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 diff --git a/flags.go b/flags.go index 67e4a80..db6565e 100644 --- a/flags.go +++ b/flags.go @@ -98,7 +98,7 @@ func init() { viper.BindPFlag("nodeguardHost", rootCmd.Flags().Lookup("nodeguardHost")) //Swap Publication Offset in minutes - rootCmd.Flags().String("swapPublicationOffset", "30m", "Swap publication deadline offset (Maximum time for the swap provider to publish the swap)") + rootCmd.Flags().String("swapPublicationOffset", "60m", "Swap publication deadline offset (Maximum time for the swap provider to publish the swap)") viper.BindPFlag("swapPublicationOffset", rootCmd.Flags().Lookup("swapPublicationOffset")) // Retries before applying backoff to the swap @@ -117,6 +117,10 @@ func init() { rootCmd.Flags().Float64("limitFees", 0.007, "Limit fees for swaps e.g. 0.01 = 1%") viper.BindPFlag("limitFees", rootCmd.Flags().Lookup("limitFees")) + //Sweep conf + 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")) + //Now we set the global vars pollingInterval = viper.GetDuration("pollingInterval") diff --git a/provider/loop_provider.go b/provider/loop_provider.go index b789d4d..a2cb334 100644 --- a/provider/loop_provider.go +++ b/provider/loop_provider.go @@ -247,7 +247,7 @@ func (l *LoopProvider) RequestReverseSubmarineSwap(ctx context.Context, request sumFees := quote.SwapFeeSat + quote.HtlcSweepFeeSat + quote.PrepayAmtSat maximumFeesAllowed := int64(float64(request.SatsAmount) * limitFees) - + if sumFees > maximumFeesAllowed { err := fmt.Errorf("swap fees are greater than max limit fees, quote fees: %d, maximum fees allowed: %d", sumFees, maximumFeesAllowed) log.Error(err) @@ -272,7 +272,7 @@ func (l *LoopProvider) RequestReverseSubmarineSwap(ctx context.Context, request MaxPrepayRoutingFee: int64(limits.maxPrepayRoutingFee), MaxSwapRoutingFee: int64(limits.maxSwapRoutingFee), OutgoingChanSet: request.ChannelSet, - SweepConfTarget: 3, //TODO Make this configurable + SweepConfTarget: viper.GetInt32("sweepConfTarget"), HtlcConfirmations: 3, //The publication deadline is maximum the offset of the swap deadline conf plus the current time SwapPublicationDeadline: uint64(time.Now().Add(viper.GetDuration("swapPublicationOffset") * time.Minute).Unix()),