Always rebuild routes after probing

pull/1/head
rkfg 2 years ago
parent 69b4af0fe0
commit 77bcea642b

@ -101,10 +101,11 @@ func tryRebalance(ctx context.Context, r *regolancer, invoice **lnrpc.AddInvoice
log.Print("Error creating invoice: ", err)
return ErrRepeat
}
probedRoute, err := r.rebuildRoute(ctx, route, amt)
if err != nil {
log.Printf("Error rebuilding the route for probed payment: %s", errColor(err))
} else {
err = r.pay(attemptCtx, probedInvoice, amt, retryErr.route, 0)
err = r.pay(attemptCtx, probedInvoice, amt, probedRoute, 0)
if err == nil {
return nil
} else {

@ -12,7 +12,6 @@ import (
type ErrRetry struct {
amount int64
route *lnrpc.Route
}
func (e ErrRetry) Error() string {
@ -62,14 +61,14 @@ func (r *regolancer) pay(ctx context.Context, invoice *lnrpc.AddInvoiceResponse,
cyanColor(node1name), cyanColor(node2name))
if int(result.Failure.FailureSourceIndex) == len(route.Hops)-2 && probeSteps > 0 {
fmt.Println("Probing route...")
maxAmount, goodRoute, err := r.probeRoute(ctx, route, 0, amount, amount/2, probeSteps)
maxAmount, err := r.probeRoute(ctx, route, 0, amount, amount/2, probeSteps)
if err != nil {
return err
}
if maxAmount == 0 {
return ErrProbeFailed
}
return ErrRetry{amount: maxAmount, route: goodRoute}
return ErrRetry{amount: maxAmount}
}
return fmt.Errorf("error: %s @ %d", result.Failure.Code.String(), result.Failure.FailureSourceIndex)
} else {

@ -112,30 +112,30 @@ func (r *regolancer) rebuildRoute(ctx context.Context, route *lnrpc.Route, amoun
return resultRoute.Route, err
}
func (r *regolancer) probeRoute(ctx context.Context, route *lnrpc.Route, goodAmount, badAmount, amount int64, steps int) (maxAmount int64,
goodRoute *lnrpc.Route, err error) {
goodRoute, err = r.rebuildRoute(ctx, route, amount)
func (r *regolancer) probeRoute(ctx context.Context, route *lnrpc.Route, goodAmount, badAmount, amount int64,
steps int) (maxAmount int64, err error) {
probedRoute, err := r.rebuildRoute(ctx, route, amount)
if err != nil {
return 0, nil, err
return 0, err
}
fakeHash := make([]byte, 32)
rand.Read(fakeHash)
result, err := r.routerClient.SendToRouteV2(ctx,
&routerrpc.SendToRouteRequest{
PaymentHash: fakeHash,
Route: goodRoute,
Route: probedRoute,
})
if err != nil {
return
}
if result.Status == lnrpc.HTLCAttempt_SUCCEEDED {
return 0, nil, fmt.Errorf("this should never happen")
return 0, fmt.Errorf("this should never happen")
}
if result.Status == lnrpc.HTLCAttempt_FAILED {
if result.Failure.Code == lnrpc.Failure_INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS { // payment can succeed
if steps == 1 || amount == badAmount {
log.Printf("%s is the best amount", hiWhiteColor(amount))
return amount, goodRoute, nil
return amount, nil
}
nextAmount := amount + (badAmount-amount)/2
log.Printf("%s is good enough, trying amount %s, %s steps left",
@ -149,7 +149,7 @@ func (r *regolancer) probeRoute(ctx context.Context, route *lnrpc.Route, goodAmo
bestAmount = hiWhiteColor("unknown")
}
log.Printf("%s is too much, best amount is %s", hiWhiteColor(amount), bestAmount)
return goodAmount, goodRoute, nil
return goodAmount, nil
}
nextAmount := amount + (goodAmount-amount)/2
log.Printf("%s is too much, lowering amount to %s, %s steps left",
@ -161,7 +161,7 @@ func (r *regolancer) probeRoute(ctx context.Context, route *lnrpc.Route, goodAmo
return r.probeRoute(ctx, route, goodAmount, badAmount, amount, steps)
}
}
return 0, nil, fmt.Errorf("unknown error: %+v", result)
return 0, fmt.Errorf("unknown error: %+v", result)
}
func (r *regolancer) addFailedRoute(from, to uint64) {

Loading…
Cancel
Save