sweep: prevent default fee preference fallback

We want to make sure clients are aware of their own fee preferences,
rather than relying on defaults.
This commit is contained in:
Wilmer Paulino 2019-05-29 13:59:00 -07:00
parent 5485101f9f
commit c70858dc46
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F
2 changed files with 16 additions and 0 deletions

View File

@ -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

View File

@ -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,
)