From 2449e66d29434eb6e7dd1e5515280b4a3924d42a Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Fri, 10 Dec 2021 13:06:48 +0200 Subject: [PATCH] lnwallet+docs: minrelayfee always above fee floor The minimum relay fee is always ensured to be above our fee floor except in the very first min relay fee query to bitcoind. This commit ensures that the fee floor is respected in this first query. --- docs/release-notes/release-notes-0.14.2.md | 4 ++++ lnwallet/chainfee/minfeemanager.go | 6 ++++++ lnwallet/chainfee/minfeemanager_test.go | 9 +++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/docs/release-notes/release-notes-0.14.2.md b/docs/release-notes/release-notes-0.14.2.md index b47a4c63..d0adc275 100644 --- a/docs/release-notes/release-notes-0.14.2.md +++ b/docs/release-notes/release-notes-0.14.2.md @@ -35,6 +35,9 @@ * [Fix memory corruption in Mission Control Store](https://github.com/lightningnetwork/lnd/pull/6068) + +* [Ensure that the min relay fee is always clamped by our fee + floor](https://github.com/lightningnetwork/lnd/pull/6076) ## RPC Server @@ -49,6 +52,7 @@ * Andras Banki-Horvath * Bjarne Magnussen +* Elle Mouton * Harsha Goli * Martin Habovštiak * Naveen Srinivasan diff --git a/lnwallet/chainfee/minfeemanager.go b/lnwallet/chainfee/minfeemanager.go index 1f377d2c..7eaef3e8 100644 --- a/lnwallet/chainfee/minfeemanager.go +++ b/lnwallet/chainfee/minfeemanager.go @@ -32,6 +32,12 @@ func newMinFeeManager(minUpdateInterval time.Duration, return nil, err } + // Ensure that the minimum fee we use is always clamped by our fee + // floor. + if minFee < FeePerKwFloor { + minFee = FeePerKwFloor + } + return &minFeeManager{ minFeePerKW: minFee, lastUpdatedTime: time.Now(), diff --git a/lnwallet/chainfee/minfeemanager_test.go b/lnwallet/chainfee/minfeemanager_test.go index 0209f1a2..b498e796 100644 --- a/lnwallet/chainfee/minfeemanager_test.go +++ b/lnwallet/chainfee/minfeemanager_test.go @@ -23,8 +23,10 @@ func (m *mockChainBackend) fetchFee() (SatPerKWeight, error) { func TestMinFeeManager(t *testing.T) { t.Parallel() + // Initialize the mock backend and let it have a minimum fee rate + // below our fee floor. chainBackend := &mockChainBackend{ - minFee: SatPerKWeight(1000), + minFee: FeePerKwFloor - 1, } // Initialise the min fee manager. This should call the chain backend @@ -36,11 +38,14 @@ func TestMinFeeManager(t *testing.T) { require.NoError(t, err) require.Equal(t, 1, chainBackend.callCount) + // Check that the minimum fee rate is clamped by our fee floor. + require.Equal(t, feeManager.minFeePerKW, FeePerKwFloor) + // If the fee is requested again, the stored fee should be returned // and the chain backend should not be queried. chainBackend.minFee = SatPerKWeight(2000) minFee := feeManager.fetchMinFee() - require.Equal(t, minFee, SatPerKWeight(1000)) + require.Equal(t, minFee, FeePerKwFloor) require.Equal(t, 1, chainBackend.callCount) // Fake the passing of time.