@@ -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
@@ -199,8 +211,10 @@ func (s *Sweeper) GetSweepFeeDetails(ctx context.Context,
199
211
destAddr btcutil.Address , sweepConfTarget int32 ) (
200
212
btcutil.Amount , chainfee.SatPerKWeight , lntypes.WeightUnit , error ) {
201
213
202
- // Get fee estimate from lnd.
203
- feeRate , err := s .Lnd .WalletKit .EstimateFeeRate (ctx , sweepConfTarget )
214
+ // Get fee estimate from the fee rate provider.
215
+ feeRate , err := s .getFeeRateProvider ().EstimateFeeRate (
216
+ ctx , sweepConfTarget ,
217
+ )
204
218
if err != nil {
205
219
return 0 , 0 , 0 , fmt .Errorf ("estimate fee: %v" , err )
206
220
}
@@ -253,3 +267,14 @@ func AddOutputEstimate(weightEstimate *input.TxWeightEstimator,
253
267
254
268
return nil
255
269
}
270
+
271
+ // getFeeRateProvider returns the fee rate provider to use for the sweeper. If
272
+ // the sweeper has a custom fee rate provider set, it will be used, otherwise
273
+ // the underlying node's walletkit will be used.
274
+ func (s * Sweeper ) getFeeRateProvider () FeeRateProvider {
275
+ if s .FeeRateProvider != nil {
276
+ return s .FeeRateProvider
277
+ }
278
+
279
+ return s .Lnd .WalletKit
280
+ }
0 commit comments