@@ -121,10 +121,6 @@ type SweepInfo struct {
121121
122122 // DestAddr is the destination address of the sweep.
123123 DestAddr btcutil.Address
124-
125- // MinFeeRate is minimum fee rate that must be used by a batch of
126- // the sweep. If it is specified, confTarget is ignored.
127- MinFeeRate chainfee.SatPerKWeight
128124}
129125
130126// SweepFetcher is used to get details of a sweep.
@@ -151,6 +147,11 @@ type SignMuSig2 func(ctx context.Context, muSig2Version input.MuSig2Version,
151147// signature.
152148type VerifySchnorrSig func (pubKey * btcec.PublicKey , hash , sig []byte ) error
153149
150+ // FeeRateProvider is a function that returns min fee rate of a batch sweeping
151+ // the UTXO of the swap.
152+ type FeeRateProvider func (ctx context.Context ,
153+ swapHash lntypes.Hash ) (chainfee.SatPerKWeight , error )
154+
154155// SweepRequest is a request to sweep a specific outpoint.
155156type SweepRequest struct {
156157 // SwapHash is the hash of the swap that is being swept.
@@ -247,11 +248,10 @@ type Batcher struct {
247248 // exit.
248249 wg sync.WaitGroup
249250
250- // noBumping instructs sweepbatcher not to fee bump itself and rely on
251- // external source of fee rates (MinFeeRate). To change the fee rate,
252- // the caller has to update it in the source of SweepInfo (interface
253- // SweepFetcher) and re-add the sweep by calling AddSweep.
254- noBumping bool
251+ // customFeeRate provides custom min fee rate per swap. The batch uses
252+ // max of the fee rates of its swaps. In this mode confTarget is
253+ // ignored and fee bumping by sweepbatcher is disabled.
254+ customFeeRate FeeRateProvider
255255
256256 // customMuSig2Signer is a custom signer. If it is set, it is used to
257257 // create musig2 signatures instead of musig2SignSweep and signerClient.
@@ -262,11 +262,10 @@ type Batcher struct {
262262
263263// BatcherConfig holds batcher configuration.
264264type BatcherConfig struct {
265- // noBumping instructs sweepbatcher not to fee bump itself and rely on
266- // external source of fee rates (MinFeeRate). To change the fee rate,
267- // the caller has to update it in the source of SweepInfo (interface
268- // SweepFetcher) and re-add the sweep by calling AddSweep.
269- noBumping bool
265+ // customFeeRate provides custom min fee rate per swap. The batch uses
266+ // max of the fee rates of its swaps. In this mode confTarget is
267+ // ignored and fee bumping by sweepbatcher is disabled.
268+ customFeeRate FeeRateProvider
270269
271270 // customMuSig2Signer is a custom signer. If it is set, it is used to
272271 // create musig2 signatures instead of musig2SignSweep and signerClient.
@@ -278,13 +277,12 @@ type BatcherConfig struct {
278277// BatcherOption configures batcher behaviour.
279278type BatcherOption func (* BatcherConfig )
280279
281- // WithNoBumping instructs sweepbatcher not to fee bump itself and
282- // rely on external source of fee rates (MinFeeRate). To change the
283- // fee rate, the caller has to update it in the source of SweepInfo
284- // (interface SweepFetcher) and re-add the sweep by calling AddSweep.
285- func WithNoBumping () BatcherOption {
280+ // WithCustomFeeRate instructs sweepbatcher not to fee bump itself and rely on
281+ // external source of fee rates (FeeRateProvider). To apply a fee rate change,
282+ // the caller should re-add the sweep by calling AddSweep.
283+ func WithCustomFeeRate (customFeeRate FeeRateProvider ) BatcherOption {
286284 return func (cfg * BatcherConfig ) {
287- cfg .noBumping = true
285+ cfg .customFeeRate = customFeeRate
288286 }
289287}
290288
@@ -331,7 +329,7 @@ func NewBatcher(wallet lndclient.WalletKitClient,
331329 chainParams : chainparams ,
332330 store : store ,
333331 sweepStore : sweepStore ,
334- noBumping : cfg .noBumping ,
332+ customFeeRate : cfg .customFeeRate ,
335333 customMuSig2Signer : cfg .customMuSig2Signer ,
336334 }
337335}
@@ -859,6 +857,22 @@ func (b *Batcher) loadSweep(ctx context.Context, swapHash lntypes.Hash,
859857 swapHash [:6 ], err )
860858 }
861859
860+ // minFeeRate is 0 by default. If customFeeRate is not provided, then
861+ // rbfCache.FeeRate is also 0 and method batch.updateRbfRate() updates
862+ // it to current fee rate according to batchConfTarget.
863+ var minFeeRate chainfee.SatPerKWeight
864+ if b .customFeeRate != nil {
865+ minFeeRate , err = b .customFeeRate (ctx , swapHash )
866+ if err != nil {
867+ return nil , fmt .Errorf ("failed to fetch min fee rate " +
868+ "for %x: %w" , swapHash [:6 ], err )
869+ }
870+ if minFeeRate < chainfee .AbsoluteFeePerKwFloor {
871+ return nil , fmt .Errorf ("min fee rate too low (%v) for " +
872+ "%x" , minFeeRate , swapHash [:6 ])
873+ }
874+ }
875+
862876 return & sweep {
863877 swapHash : swapHash ,
864878 outpoint : outpoint ,
@@ -874,15 +888,15 @@ func (b *Batcher) loadSweep(ctx context.Context, swapHash lntypes.Hash,
874888 protocolVersion : s .ProtocolVersion ,
875889 isExternalAddr : s .IsExternalAddr ,
876890 destAddr : s .DestAddr ,
877- minFeeRate : s . MinFeeRate ,
891+ minFeeRate : minFeeRate ,
878892 }, nil
879893}
880894
881895// newBatchConfig creates new batch config.
882896func (b * Batcher ) newBatchConfig (maxTimeoutDistance int32 ) batchConfig {
883897 return batchConfig {
884898 maxTimeoutDistance : maxTimeoutDistance ,
885- noBumping : b .noBumping ,
899+ noBumping : b .customFeeRate != nil ,
886900 customMuSig2Signer : b .customMuSig2Signer ,
887901 }
888902}
0 commit comments