Skip to content

Commit 32d01f2

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 d198bb8 commit 32d01f2

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
@@ -200,8 +212,10 @@ func (s *Sweeper) GetSweepFeeDetails(ctx context.Context,
200212
destAddr btcutil.Address, sweepConfTarget int32, label string) (
201213
btcutil.Amount, chainfee.SatPerKWeight, lntypes.WeightUnit, error) {
202214

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

262276
return nil
263277
}
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

Comments
 (0)