@@ -18,9 +18,21 @@ import (
18
18
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
19
19
)
20
20
21
+ // FeeRateProvider is a generic provider of fee rate by confirmation target.
22
+ type FeeRateProvider interface {
23
+ // EstimateFeeRate returns the fee rate in sat/kw for a transaction to
24
+ // be confirmed in the given number of blocks.
25
+ EstimateFeeRate (ctx context.Context , confTarget int32 ) (
26
+ chainfee.SatPerKWeight , error )
27
+ }
28
+
21
29
// Sweeper creates htlc sweep txes.
22
30
type Sweeper struct {
23
31
Lnd * lndclient.LndServices
32
+
33
+ // FeeRateProvider if set will be used to estimate the fee rate for the
34
+ // sweep transaction.
35
+ FeeRateProvider FeeRateProvider
24
36
}
25
37
26
38
// CreateUnsignedTaprootKeySpendSweepTx creates a taproot htlc sweep tx using
@@ -200,8 +212,10 @@ func (s *Sweeper) GetSweepFeeDetails(ctx context.Context,
200
212
destAddr btcutil.Address , sweepConfTarget int32 , label string ) (
201
213
btcutil.Amount , chainfee.SatPerKWeight , lntypes.WeightUnit , error ) {
202
214
203
- // Get fee estimate from lnd.
204
- feeRate , err := s .Lnd .WalletKit .EstimateFeeRate (ctx , sweepConfTarget )
215
+ // Get fee estimate from the fee rate provider.
216
+ feeRate , err := s .getFeeRateProvider ().EstimateFeeRate (
217
+ ctx , sweepConfTarget ,
218
+ )
205
219
if err != nil {
206
220
return 0 , 0 , 0 , fmt .Errorf ("estimate fee: %v" , err )
207
221
}
@@ -261,3 +275,14 @@ func AddOutputEstimate(weightEstimate *input.TxWeightEstimator,
261
275
262
276
return nil
263
277
}
278
+
279
+ // getFeeRateProvider returns the fee rate provider to use for the sweeper. If
280
+ // the sweeper has a custom fee rate provider set, it will be used, otherwise
281
+ // the underlying node's walletkit will be used.
282
+ func (s * Sweeper ) getFeeRateProvider () FeeRateProvider {
283
+ if s .FeeRateProvider != nil {
284
+ return s .FeeRateProvider
285
+ }
286
+
287
+ return s .Lnd .WalletKit
288
+ }
0 commit comments