Skip to content

Commit 026cf0d

Browse files
committed
sweepbatcher: always try greedy batch selection
Now that sweep.minFeeRate is always set, greedy batch selection has all needed inputs to work even without customFeeRate provider.
1 parent 75641c3 commit 026cf0d

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

sweepbatcher/greedy_batch_selection.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ import (
2828
// creation fails, this method returns an error. If this method fails for any
2929
// reason, the caller falls back to the simple algorithm (method handleSweep).
3030
func (b *Batcher) greedyAddSweep(ctx context.Context, sweep *sweep) error {
31-
if b.customFeeRate == nil {
32-
return errors.New("greedy batch selection algorithm requires " +
33-
"setting custom fee rate provider")
34-
}
35-
3631
// Collect weight and fee rate info about the sweep and new batch.
3732
sweepFeeDetails, newBatchFeeDetails, err := estimateSweepFeeIncrement(
3833
sweep,

sweepbatcher/sweep_batcher.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -474,19 +474,16 @@ func (b *Batcher) handleSweep(ctx context.Context, sweep *sweep,
474474
}
475475
}
476476

477-
// If custom fee rate provider is used, run the greedy algorithm of
478-
// batch selection to minimize costs.
479-
if b.customFeeRate != nil {
480-
err := b.greedyAddSweep(ctx, sweep)
481-
if err == nil {
482-
// The greedy algorithm succeeded.
483-
return nil
484-
}
485-
486-
log.Warnf("Greedy batch selection algorithm failed for sweep "+
487-
"%x, falling back to old approach.", sweep.swapHash[:6])
477+
// Try to run the greedy algorithm of batch selection to minimize costs.
478+
err = b.greedyAddSweep(ctx, sweep)
479+
if err == nil {
480+
// The greedy algorithm succeeded.
481+
return nil
488482
}
489483

484+
log.Warnf("Greedy batch selection algorithm failed for sweep %x: %v. "+
485+
"Falling back to old approach.", sweep.swapHash[:6], err)
486+
490487
// If one of the batches accepts the sweep, we provide it to that batch.
491488
for _, batch := range b.batches {
492489
accepted, err := batch.addSweep(ctx, sweep)

0 commit comments

Comments
 (0)