From 0b30d4ba3ec0b0b48f2e36f0d1da3716ed7342b9 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 19 Mar 2024 01:14:37 +0800 Subject: [PATCH] lnrpc+sweep: make `FeeEstimateInfo` an optional param This is needed as we soon will remove the usage of the fee preference when sweeping inputs. --- lnrpc/walletrpc/walletkit_server.go | 39 ++++++++++++++++++----------- sweep/sweeper.go | 16 +++++++----- 2 files changed, 34 insertions(+), 21 deletions(-) diff --git a/lnrpc/walletrpc/walletkit_server.go b/lnrpc/walletrpc/walletkit_server.go index 8bd3893c9..7a21190c8 100644 --- a/lnrpc/walletrpc/walletkit_server.go +++ b/lnrpc/walletrpc/walletkit_server.go @@ -883,25 +883,34 @@ func (w *WalletKit) PendingSweeps(ctx context.Context, satPerVbyte := uint64(sweeperInput.LastFeeRate.FeePerVByte()) broadcastAttempts := uint32(sweeperInput.BroadcastAttempts) - feePref := sweeperInput.Params.Fee - requestedFee, ok := feePref.(sweep.FeeEstimateInfo) - if !ok { - return nil, fmt.Errorf("unknown fee preference type: "+ - "%v", feePref) + ps := &PendingSweep{ + Outpoint: op, + WitnessType: witnessType, + AmountSat: amountSat, + SatPerVbyte: satPerVbyte, + BroadcastAttempts: broadcastAttempts, + Force: sweeperInput.Params.Force, } + feePref := sweeperInput.Params.Fee + + // If there's no fee preference specified, we can move to the + // next record. + if feePref == nil { + rpcPendingSweeps = append(rpcPendingSweeps, ps) + continue + } + + requestedFee, ok := feePref.(sweep.FeeEstimateInfo) + if !ok { + return nil, fmt.Errorf("unknown fee "+ + "preference type: "+"%v", feePref) + } requestedFeeRate := uint64(requestedFee.FeeRate.FeePerVByte()) - rpcPendingSweeps = append(rpcPendingSweeps, &PendingSweep{ - Outpoint: op, - WitnessType: witnessType, - AmountSat: amountSat, - SatPerVbyte: satPerVbyte, - BroadcastAttempts: broadcastAttempts, - RequestedSatPerVbyte: requestedFeeRate, - RequestedConfTarget: requestedFee.ConfTarget, - Force: sweeperInput.Params.Force, - }) + ps.RequestedSatPerVbyte = requestedFeeRate + ps.RequestedConfTarget = requestedFee.ConfTarget + rpcPendingSweeps = append(rpcPendingSweeps, ps) } return &PendingSweepsResponse{ diff --git a/sweep/sweeper.go b/sweep/sweeper.go index 581ab8460..0e39e27b8 100644 --- a/sweep/sweeper.go +++ b/sweep/sweeper.go @@ -514,11 +514,15 @@ func (s *UtxoSweeper) SweepInput(input input.Input, } // Ensure the client provided a sane fee preference. - _, err := params.Fee.Estimate( - s.cfg.FeeEstimator, s.cfg.MaxFeeRate.FeePerKWeight(), - ) - if err != nil { - return nil, err + // + // TODO(yy): remove this check? + if params.Fee != nil { + _, err := params.Fee.Estimate( + s.cfg.FeeEstimator, s.cfg.MaxFeeRate.FeePerKWeight(), + ) + if err != nil { + return nil, err + } } absoluteTimeLock, _ := input.RequiredLockTime() @@ -1580,7 +1584,7 @@ func (s *UtxoSweeper) sweepPendingInputs(inputs InputsMap) { } if err != nil { - log.Errorf("Sweep new inputs: %v", err) + log.Errorf("Failed to sweep %v: %v", set, err) } } }