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.
This commit is contained in:
Boris Nagaev 2024-07-15 12:26:43 -03:00
parent 75641c3573
commit 026cf0d47a
No known key found for this signature in database
2 changed files with 8 additions and 16 deletions

View file

@ -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,

View file

@ -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)