diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 6fe39855..2f9f9b19 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -46,6 +46,10 @@ var ( // for the configured max number of attempts. ErrTooManyAttempts = errors.New("sweep failed after max attempts") + // ErrNoFeePreference is returned when we attempt to satisfy a sweep + // request from a client whom did not specify a fee preference. + ErrNoFeePreference = errors.New("no fee preference specified") + // ErrSweeperShuttingDown is an error returned when a client attempts to // make a request to the UtxoSweeper, but it is unable to handle it as // it is/has already been stoppepd. @@ -394,6 +398,12 @@ func (s *UtxoSweeper) SweepInput(input input.Input, func (s *UtxoSweeper) feeRateForPreference( feePreference FeePreference) (lnwallet.SatPerKWeight, error) { + // Ensure a type of fee preference is specified to prevent using a + // default below. + if feePreference.FeeRate == 0 && feePreference.ConfTarget == 0 { + return 0, ErrNoFeePreference + } + feeRate, err := DetermineFeePerKw(s.cfg.FeeEstimator, feePreference) if err != nil { return 0, err diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index d494b996..6d099901 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -372,6 +372,12 @@ func assertTxFeeRate(t *testing.T, tx *wire.MsgTx, func TestSuccess(t *testing.T) { ctx := createSweeperTestContext(t) + // Sweeping an input without a fee preference should result in an error. + _, err := ctx.sweeper.SweepInput( spendableInputs[0], FeePreference{}) + if err != ErrNoFeePreference { + t.Fatalf("expected ErrNoFeePreference, got %v", err) + } + resultChan, err := ctx.sweeper.SweepInput( spendableInputs[0], defaultFeePref, )