From 9be5b370a758418106d8d1a052be4b034c606416 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 9 Apr 2024 20:05:00 +0800 Subject: [PATCH] sweep+contractcourt: replace `ParamsUpdate` with `Params` --- contractcourt/commit_sweep_resolver_test.go | 2 +- contractcourt/interfaces.go | 2 +- lnrpc/walletrpc/walletkit_server.go | 2 +- sweep/sweeper.go | 26 +++++++-------------- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/contractcourt/commit_sweep_resolver_test.go b/contractcourt/commit_sweep_resolver_test.go index b3221f5c5..2b63384dd 100644 --- a/contractcourt/commit_sweep_resolver_test.go +++ b/contractcourt/commit_sweep_resolver_test.go @@ -167,7 +167,7 @@ func (s *mockSweeper) RelayFeePerKW() chainfee.SatPerKWeight { } func (s *mockSweeper) UpdateParams(input wire.OutPoint, - params sweep.ParamsUpdate) (chan sweep.Result, error) { + params sweep.Params) (chan sweep.Result, error) { s.updatedInputs <- input diff --git a/contractcourt/interfaces.go b/contractcourt/interfaces.go index c1b0211ba..0d53b07b6 100644 --- a/contractcourt/interfaces.go +++ b/contractcourt/interfaces.go @@ -59,7 +59,7 @@ type UtxoSweeper interface { // fee preference that will be used for a new sweep transaction of the // input that will act as a replacement transaction (RBF) of the // original sweeping transaction, if any. - UpdateParams(input wire.OutPoint, params sweep.ParamsUpdate) ( + UpdateParams(input wire.OutPoint, params sweep.Params) ( chan sweep.Result, error) } diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index e7dfe695c..8c94b29f0 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -988,7 +988,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.ParamsUpdate{ + params := sweep.Params{ Fee: feePreference, Immediate: in.Immediate, } diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 970bdb1c8..cfedfb010 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -71,22 +71,6 @@ type Params struct { StartingFeeRate fn.Option[chainfee.SatPerKWeight] } -// 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 - - // Immediate indicates that the input should be swept immediately - // without waiting for blocks to come. - Immediate bool - - // StartingFeeRate is an optional parameter that can be used to specify - // the initial fee rate to use for the fee function. - StartingFeeRate fn.Option[chainfee.SatPerKWeight] -} - // String returns a human readable interpretation of the sweep parameters. func (p Params) String() string { deadline := "none" @@ -283,7 +267,7 @@ type PendingInputResponse struct { // intent to update the sweep parameters of a given input. type updateReq struct { input wire.OutPoint - params ParamsUpdate + params Params responseChan chan *updateResp } @@ -700,6 +684,12 @@ func (s *UtxoSweeper) collector(blockEpochs <-chan *chainntnfs.BlockEpoch) { err: err, } + // Perform an sweep immediately if asked. + if req.params.Immediate { + inputs := s.updateSweeperInputs() + s.sweepPendingInputs(inputs) + } + case result := <-s.bumpResultChan: // Handle the bump event. err := s.handleBumpEvent(result) @@ -1095,7 +1085,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 ParamsUpdate) (chan Result, error) { + params Params) (chan Result, error) { // Ensure the client provided a sane fee preference. _, err := params.Fee.Estimate(