From 45c6ee69d2727f052ba5b937e039423c1c267597 Mon Sep 17 00:00:00 2001 From: ziggie Date: Fri, 21 Jul 2023 09:53:12 +0200 Subject: [PATCH] chainfee: special case a zero fee estimation. Bitcoind will not report any fee estimation in case it has not enough data available. We used to just set the min mempool fee in such cases but this might not represent the current fee situation of the bitcoin network. We return an error now so that we will use the fallback fee instead. --- lnwallet/chainfee/estimator.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lnwallet/chainfee/estimator.go b/lnwallet/chainfee/estimator.go index 824af3f11..c4ac1591c 100644 --- a/lnwallet/chainfee/estimator.go +++ b/lnwallet/chainfee/estimator.go @@ -311,6 +311,8 @@ type BitcoindEstimator struct { // to "CONSERVATIVE". feeMode string + // TODO(ziggie): introduce an interface for the client to enhance + // testability of the estimator. bitcoindConn *rpcclient.Client } @@ -472,6 +474,13 @@ func (b *BitcoindEstimator) fetchEstimate(confTarget uint32) (SatPerKWeight, err return 0, err } + // Bitcoind will not report any fee estimation if it has not enough + // data available hence the fee will remain zero. We return an error + // here to make sure that we do not use the min relay fee instead. + if satPerKB == 0 { + return 0, fmt.Errorf("fee estimation data not available yet") + } + // Since we use fee rates in sat/kw internally, we'll convert the // estimated fee rate from its sat/kb representation to sat/kw. satPerKw := SatPerKVByte(satPerKB).FeePerKWeight() @@ -479,14 +488,14 @@ func (b *BitcoindEstimator) fetchEstimate(confTarget uint32) (SatPerKWeight, err // Finally, we'll enforce our fee floor. minRelayFee := b.minFeeManager.fetchMinFee() if satPerKw < minRelayFee { - log.Debugf("Estimated fee rate of %v sat/kw is too low, "+ - "using fee floor of %v sat/kw instead", satPerKw, + log.Debugf("Estimated fee rate of %v is too low, "+ + "using fee floor of %v instead", satPerKw, minRelayFee) satPerKw = minRelayFee } - log.Debugf("Returning %v sat/kw for conf target of %v", + log.Debugf("Returning %v for conf target of %v", int64(satPerKw), confTarget) return satPerKw, nil