Skip to content

Commit

Permalink
sweepbatcher: always try greedy batch selection
Browse files Browse the repository at this point in the history
Now that sweep.minFeeRate is always set, greedy batch selection has all needed
inputs to work even without customFeeRate provider.
  • Loading branch information
starius committed Jul 18, 2024
1 parent 75641c3 commit 026cf0d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
5 changes: 0 additions & 5 deletions sweepbatcher/greedy_batch_selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@ import (
// creation fails, this method returns an error. If this method fails for any
// reason, the caller falls back to the simple algorithm (method handleSweep).
func (b *Batcher) greedyAddSweep(ctx context.Context, sweep *sweep) error {
if b.customFeeRate == nil {
return errors.New("greedy batch selection algorithm requires " +
"setting custom fee rate provider")
}

// Collect weight and fee rate info about the sweep and new batch.
sweepFeeDetails, newBatchFeeDetails, err := estimateSweepFeeIncrement(
sweep,
Expand Down
19 changes: 8 additions & 11 deletions sweepbatcher/sweep_batcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,19 +474,16 @@ func (b *Batcher) handleSweep(ctx context.Context, sweep *sweep,
}
}

// If custom fee rate provider is used, run the greedy algorithm of
// batch selection to minimize costs.
if b.customFeeRate != nil {
err := b.greedyAddSweep(ctx, sweep)
if err == nil {
// The greedy algorithm succeeded.
return nil
}

log.Warnf("Greedy batch selection algorithm failed for sweep "+
"%x, falling back to old approach.", sweep.swapHash[:6])
// Try to run the greedy algorithm of batch selection to minimize costs.
err = b.greedyAddSweep(ctx, sweep)
if err == nil {
// The greedy algorithm succeeded.
return nil
}

log.Warnf("Greedy batch selection algorithm failed for sweep %x: %v. "+
"Falling back to old approach.", sweep.swapHash[:6], err)

// If one of the batches accepts the sweep, we provide it to that batch.
for _, batch := range b.batches {
accepted, err := batch.addSweep(ctx, sweep)
Expand Down

0 comments on commit 026cf0d

Please sign in to comment.