Skip to content

Commit 1a49e56

Browse files
committed
sweep: add support for a custom fee rate provider
With this commit we can parametrize the sweeper with a custom fee rate provider to use instead of the default walletkit one.
1 parent 15ee978 commit 1a49e56

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

sweep/sweeper.go

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@ import (
1818
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
1919
)
2020

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+
2129
// Sweeper creates htlc sweep txes.
2230
type Sweeper struct {
2331
Lnd *lndclient.LndServices
32+
33+
// FeeRateProvider if set will be used to estimate the fee rate for the
34+
// sweep transaction.
35+
FeeRateProvider FeeRateProvider
2436
}
2537

2638
// CreateUnsignedTaprootKeySpendSweepTx creates a taproot htlc sweep tx using
@@ -199,8 +211,10 @@ func (s *Sweeper) GetSweepFeeDetails(ctx context.Context,
199211
destAddr btcutil.Address, sweepConfTarget int32) (
200212
btcutil.Amount, chainfee.SatPerKWeight, lntypes.WeightUnit, error) {
201213

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+
)
204218
if err != nil {
205219
return 0, 0, 0, fmt.Errorf("estimate fee: %v", err)
206220
}
@@ -253,3 +267,14 @@ func AddOutputEstimate(weightEstimate *input.TxWeightEstimator,
253267

254268
return nil
255269
}
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

Comments
 (0)