@@ -1522,28 +1522,12 @@ func (b *Batcher) loadSweep(ctx context.Context, swapHash lntypes.Hash,
15221522
15231523 // Find minimum fee rate for the sweep. Use customFeeRate if it is
15241524 // provided, otherwise use wallet's EstimateFeeRate.
1525- var minFeeRate chainfee.SatPerKWeight
1526- if b .customFeeRate != nil {
1527- minFeeRate , err = b .customFeeRate (ctx , swapHash , outpoint )
1528- if err != nil {
1529- return nil , fmt .Errorf ("failed to fetch min fee rate " +
1530- "for %x: %w" , swapHash [:6 ], err )
1531- }
1532- if minFeeRate < chainfee .AbsoluteFeePerKwFloor {
1533- return nil , fmt .Errorf ("min fee rate too low (%v) for " +
1534- "%x" , minFeeRate , swapHash [:6 ])
1535- }
1536- } else {
1537- if s .ConfTarget == 0 {
1538- warnf ("Fee estimation was requested for zero " +
1539- "confTarget for sweep %x." , swapHash [:6 ])
1540- }
1541- minFeeRate , err = b .wallet .EstimateFeeRate (ctx , s .ConfTarget )
1542- if err != nil {
1543- return nil , fmt .Errorf ("failed to estimate fee rate " +
1544- "for %x, confTarget=%d: %w" , swapHash [:6 ],
1545- s .ConfTarget , err )
1546- }
1525+ minFeeRate , err := minimumSweepFeeRate (
1526+ ctx , b .customFeeRate , b .wallet ,
1527+ swapHash , outpoint , s .ConfTarget ,
1528+ )
1529+ if err != nil {
1530+ return nil , err
15471531 }
15481532
15491533 return & sweep {
@@ -1567,11 +1551,53 @@ func (b *Batcher) loadSweep(ctx context.Context, swapHash lntypes.Hash,
15671551 }, nil
15681552}
15691553
1554+ // feeRateEstimator determines feerate by confTarget.
1555+ type feeRateEstimator interface {
1556+ // EstimateFeeRate returns feerate corresponding to the confTarget.
1557+ EstimateFeeRate (ctx context.Context ,
1558+ confTarget int32 ) (chainfee.SatPerKWeight , error )
1559+ }
1560+
1561+ // minimumSweepFeeRate determines minimum feerate for a sweep.
1562+ func minimumSweepFeeRate (ctx context.Context , customFeeRate FeeRateProvider ,
1563+ wallet feeRateEstimator , swapHash lntypes.Hash , outpoint wire.OutPoint ,
1564+ sweepConfTarget int32 ) (chainfee.SatPerKWeight , error ) {
1565+
1566+ // Find minimum fee rate for the sweep. Use customFeeRate if it is
1567+ // provided, otherwise use wallet's EstimateFeeRate.
1568+ if customFeeRate != nil {
1569+ minFeeRate , err := customFeeRate (ctx , swapHash , outpoint )
1570+ if err != nil {
1571+ return 0 , fmt .Errorf ("failed to fetch min fee rate " +
1572+ "for %x: %w" , swapHash [:6 ], err )
1573+ }
1574+ if minFeeRate < chainfee .AbsoluteFeePerKwFloor {
1575+ return 0 , fmt .Errorf ("min fee rate too low (%v) for " +
1576+ "%x" , minFeeRate , swapHash [:6 ])
1577+ }
1578+
1579+ return minFeeRate , nil
1580+ }
1581+
1582+ if sweepConfTarget == 0 {
1583+ warnf ("Fee estimation was requested for zero " +
1584+ "confTarget for sweep %x." , swapHash [:6 ])
1585+ }
1586+ minFeeRate , err := wallet .EstimateFeeRate (ctx , sweepConfTarget )
1587+ if err != nil {
1588+ return 0 , fmt .Errorf ("failed to estimate fee rate " +
1589+ "for %x, confTarget=%d: %w" , swapHash [:6 ],
1590+ sweepConfTarget , err )
1591+ }
1592+
1593+ return minFeeRate , nil
1594+ }
1595+
15701596// newBatchConfig creates new batch config.
15711597func (b * Batcher ) newBatchConfig (maxTimeoutDistance int32 ) batchConfig {
15721598 return batchConfig {
15731599 maxTimeoutDistance : maxTimeoutDistance ,
1574- noBumping : b .customFeeRate != nil ,
1600+ customFeeRate : b .customFeeRate ,
15751601 txLabeler : b .txLabeler ,
15761602 customMuSig2Signer : b .customMuSig2Signer ,
15771603 presignedHelper : b .presignedHelper ,
0 commit comments