sweep: leave exclusive group unchanged on parameter update

Exclusive group is a static property that doesn't need to be updated.
Requiring the exclusive group to be passed into UpdateParams creates a
burden for the caller to make sure they supply the existing group.

This change will be beneficial for users that bump anchor sweeps that
have exclusive groups set.
This commit is contained in:
Joost Jager 2020-03-11 18:14:26 +01:00
parent 1c93e9e03d
commit 29e1489179
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
3 changed files with 27 additions and 9 deletions

@ -486,7 +486,7 @@ func (w *WalletKit) BumpFee(ctx context.Context,
// bump its fee, which will result in a replacement transaction (RBF)
// being broadcast. If it is not aware of the input however,
// lnwallet.ErrNotMine is returned.
params := sweep.Params{
params := sweep.ParamsUpdate{
Fee: feePreference,
Force: in.Force,
}

@ -82,6 +82,18 @@ type Params struct {
ExclusiveGroup *uint64
}
// ParamsUpdate contains a new set of parameters to update a pending sweep with.
type ParamsUpdate struct {
// Fee is the fee preference of the client who requested the input to be
// swept. If a confirmation target is specified, then we'll map it into
// a fee rate whenever we attempt to cluster inputs for a sweep.
Fee FeePreference
// Force indicates whether the input should be swept regardless of
// whether it is economical to do so.
Force bool
}
// String returns a human readable interpretation of the sweep parameters.
func (p Params) String() string {
return fmt.Sprintf("fee=%v, force=%v, exclusive_group=%v",
@ -174,7 +186,7 @@ type PendingInput struct {
// intent to update the sweep parameters of a given input.
type updateReq struct {
input wire.OutPoint
params Params
params ParamsUpdate
responseChan chan *updateResp
}
@ -1119,7 +1131,7 @@ func (s *UtxoSweeper) handlePendingSweepsReq(
// is actually successful. The responsibility of doing so should be handled by
// the caller.
func (s *UtxoSweeper) UpdateParams(input wire.OutPoint,
params Params) (chan Result, error) {
params ParamsUpdate) (chan Result, error) {
// Ensure the client provided a sane fee preference.
if _, err := s.feeRateForPreference(params.Fee); err != nil {
@ -1169,10 +1181,16 @@ func (s *UtxoSweeper) handleUpdateReq(req *updateReq, bestHeight int32) (
return nil, lnwallet.ErrNotMine
}
log.Debugf("Updating sweep parameters for %v from %v to %v", req.input,
pendingInput.params, req.params)
// Create the updated parameters struct. Leave the exclusive group
// unchanged.
newParams := pendingInput.params
newParams.Fee = req.params.Fee
newParams.Force = req.params.Force
pendingInput.params = req.params
log.Debugf("Updating sweep parameters for %v from %v to %v", req.input,
pendingInput.params, newParams)
pendingInput.params = newParams
// We'll reset the input's publish height to the current so that a new
// transaction can be created that replaces the transaction currently

@ -1179,7 +1179,7 @@ func TestBumpFeeRBF(t *testing.T) {
// We'll first try to bump the fee of an output currently unknown to the
// UtxoSweeper. Doing so should result in a lnwallet.ErrNotMine error.
_, err := ctx.sweeper.UpdateParams(
wire.OutPoint{}, Params{Fee: lowFeePref},
wire.OutPoint{}, ParamsUpdate{Fee: lowFeePref},
)
if err != lnwallet.ErrNotMine {
t.Fatalf("expected error lnwallet.ErrNotMine, got \"%v\"", err)
@ -1208,13 +1208,13 @@ func TestBumpFeeRBF(t *testing.T) {
ctx.estimator.blocksToFee[highFeePref.ConfTarget] = highFeeRate
// We should expect to see an error if a fee preference isn't provided.
_, err = ctx.sweeper.UpdateParams(*input.OutPoint(), Params{})
_, err = ctx.sweeper.UpdateParams(*input.OutPoint(), ParamsUpdate{})
if err != ErrNoFeePreference {
t.Fatalf("expected ErrNoFeePreference, got %v", err)
}
bumpResult, err := ctx.sweeper.UpdateParams(
*input.OutPoint(), Params{Fee: highFeePref},
*input.OutPoint(), ParamsUpdate{Fee: highFeePref},
)
if err != nil {
t.Fatalf("unable to bump input's fee: %v", err)