From 063fb9dd43f30d5fbd72b1580bc94cdd45b6cd66 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Wed, 12 Jul 2023 21:35:22 +0800 Subject: [PATCH] multi: make max fee rate configurable --- config.go | 1 + lncfg/sweeper.go | 25 ++++++++++++++++++++++++- sample-lnd.conf | 5 +++++ server.go | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 51aa2e840..844e56158 100644 --- a/config.go +++ b/config.go @@ -684,6 +684,7 @@ func DefaultConfig() Config { }, Sweeper: &lncfg.Sweeper{ BatchWindowDuration: sweep.DefaultBatchWindowDuration, + MaxFeeRate: sweep.DefaultMaxFeeRate, }, Htlcswitch: &lncfg.Htlcswitch{ MailboxDeliveryTimeout: htlcswitch.DefaultMailboxDeliveryTimeout, diff --git a/lncfg/sweeper.go b/lncfg/sweeper.go index feca51ccb..08b12f6da 100644 --- a/lncfg/sweeper.go +++ b/lncfg/sweeper.go @@ -3,11 +3,24 @@ package lncfg import ( "fmt" "time" + + "github.com/lightningnetwork/lnd/lnwallet/chainfee" +) + +const ( + // MaxFeeRateFloor is the smallest config value allowed for the max fee + // rate in sat/vb. + MaxFeeRateFloor chainfee.SatPerVByte = 100 + + // MaxAllowedFeeRate is the largest fee rate in sat/vb that we allow + // when configuring the MaxFeeRate. + MaxAllowedFeeRate = 10_000 ) //nolint:lll type Sweeper struct { - BatchWindowDuration time.Duration `long:"batchwindowduration" description:"Duration of the sweep batch window. The sweep is held back during the batch window to allow more inputs to be added and thereby lower the fee per input."` + BatchWindowDuration time.Duration `long:"batchwindowduration" description:"Duration of the sweep batch window. The sweep is held back during the batch window to allow more inputs to be added and thereby lower the fee per input."` + MaxFeeRate chainfee.SatPerVByte `long:"maxfeerate" description:"Maximum fee rate in sat/vb that the sweeper is allowed to use when sweeping funds. Setting this value too low can result in transactions not being confirmed in time, causing HTLCs to expire hence potentially losing funds."` } // Validate checks the values configured for the sweeper. @@ -16,5 +29,15 @@ func (s *Sweeper) Validate() error { return fmt.Errorf("batchwindowduration must be positive") } + // We require the max fee rate to be at least 100 sat/vbyte. + if s.MaxFeeRate < MaxFeeRateFloor { + return fmt.Errorf("maxfeerate must be >= 100 sat/vb") + } + + // We require the max fee rate to be no greater than 10_000 sat/vbyte. + if s.MaxFeeRate > MaxAllowedFeeRate { + return fmt.Errorf("maxfeerate must be <= 10000 sat/vb") + } + return nil } diff --git a/sample-lnd.conf b/sample-lnd.conf index 2a6c47ab9..3d8a7b292 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -1590,6 +1590,11 @@ ; window to allow more inputs to be added and thereby lower the fee per input. ; sweeper.batchwindowduration=30s +; The max fee rate in sat/vb which can be used when sweeping funds. Setting +; this value too low can result in transactions not being confirmed in time, +; causing HTLCs to expire hence potentially losing funds. +; sweeper.maxfeerate=1000 + [htlcswitch] diff --git a/server.go b/server.go index 1a8aaa9fd..eab28fea3 100644 --- a/server.go +++ b/server.go @@ -1071,7 +1071,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, MaxInputsPerTx: sweep.DefaultMaxInputsPerTx, MaxSweepAttempts: sweep.DefaultMaxSweepAttempts, NextAttemptDeltaFunc: sweep.DefaultNextAttemptDeltaFunc, - MaxFeeRate: sweep.DefaultMaxFeeRate, + MaxFeeRate: cfg.Sweeper.MaxFeeRate, FeeRateBucketSize: sweep.DefaultFeeRateBucketSize, })