From 29e1489179bccb6ac6568111b7341669c583f949 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 11 Mar 2020 18:14:26 +0100 Subject: [PATCH] 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. --- lnrpc/walletrpc/walletkit_server.go | 2 +- sweep/sweeper.go | 28 +++++++++++++++++++++++----- sweep/sweeper_test.go | 6 +++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index 42534c653..1cc5282da 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -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, } diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 95c0ff2be..f176f703b 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -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 diff --git a/sweep/sweeper_test.go b/sweep/sweeper_test.go index 85908f7e8..5fbfce4c0 100644 --- a/sweep/sweeper_test.go +++ b/sweep/sweeper_test.go @@ -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)