Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sweep: add support for a custom fee rate provider #858

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions sweep/sweeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@ import (
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
)

// FeeRateProvider is a generic provider of fee rate by confirmation target.
type FeeRateProvider interface {
// EstimateFeeRate returns the fee rate in sat/kw for a transaction to
// be confirmed in the given number of blocks.
EstimateFeeRate(ctx context.Context, confTarget int32) (
chainfee.SatPerKWeight, error)
}

// Sweeper creates htlc sweep txes.
type Sweeper struct {
Lnd *lndclient.LndServices

// FeeRateProvider if set will be used to estimate the fee rate for the
// sweep transaction.
FeeRateProvider FeeRateProvider
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to add a unit test for this feature.

}

// CreateUnsignedTaprootKeySpendSweepTx creates a taproot htlc sweep tx using
Expand Down Expand Up @@ -200,8 +212,10 @@ func (s *Sweeper) GetSweepFeeDetails(ctx context.Context,
destAddr btcutil.Address, sweepConfTarget int32, label string) (
btcutil.Amount, chainfee.SatPerKWeight, lntypes.WeightUnit, error) {

// Get fee estimate from lnd.
feeRate, err := s.Lnd.WalletKit.EstimateFeeRate(ctx, sweepConfTarget)
// Get fee estimate from the fee rate provider.
feeRate, err := s.getFeeRateProvider().EstimateFeeRate(
ctx, sweepConfTarget,
)
if err != nil {
return 0, 0, 0, fmt.Errorf("estimate fee: %v", err)
}
Expand Down Expand Up @@ -261,3 +275,14 @@ func AddOutputEstimate(weightEstimate *input.TxWeightEstimator,

return nil
}

// getFeeRateProvider returns the fee rate provider to use for the sweeper. If
// the sweeper has a custom fee rate provider set, it will be used, otherwise
// the underlying node's walletkit will be used.
func (s *Sweeper) getFeeRateProvider() FeeRateProvider {
if s.FeeRateProvider != nil {
return s.FeeRateProvider
}

return s.Lnd.WalletKit
}
Loading