Respect min amount when picking channels

pull/1/head v1.1.0
rkfg 2 years ago
parent 8e4521e033
commit 869fcdb466

@ -76,7 +76,7 @@ func min(args ...int64) (result int64) {
return
}
func (r *regolancer) pickChannelPair(amount int64) (from uint64, to uint64, maxAmount int64, err error) {
func (r *regolancer) pickChannelPair(amount, minAmount int64) (from uint64, to uint64, maxAmount int64, err error) {
if len(r.channelPairs) == 0 {
if !r.routeFound {
return 0, 0, 0, errors.New("no routes")
@ -107,6 +107,10 @@ func (r *regolancer) pickChannelPair(amount int64) (from uint64, to uint64, maxA
} else {
maxAmount = min(maxFrom, maxTo, amount)
}
if maxAmount < minAmount {
r.addFailedRoute(fromChan.ChanId, toChan.ChanId)
return r.pickChannelPair(amount, minAmount)
}
for k, v := range r.failureCache {
if v.expiration.Before(time.Now()) {
r.channelPairs[k] = v.channelPair

@ -86,7 +86,7 @@ func loadConfig() {
func tryRebalance(ctx context.Context, r *regolancer, invoice **lnrpc.AddInvoiceResponse,
attempt *int) (err error, repeat bool) {
from, to, amt, err := r.pickChannelPair(params.Amount)
from, to, amt, err := r.pickChannelPair(params.Amount, params.MinAmount)
if err != nil {
log.Printf(errColor("Error during picking channel: %s"), err)
return err, false

Loading…
Cancel
Save