Add min amount

pull/1/head
rkfg 2 years ago
parent 2e98c46eb0
commit 83f4ba6a39

@ -48,6 +48,7 @@ rebalance-lnd](https://github.com/accumulator/rebalance-lnd).
-a, --amount= amount to rebalance
--econ-ratio= economical ratio for fee limit calculation as a multiple of target channel fee (for example, 0.5 means you want to pay at max half the fee you might earn for routing out of the target channel)
-b, --probe= if the payment fails at the last hop try to probe lower amount using binary search
--min-amount= if probing is enabled this will be the minimum amount to try
-i, --exclude-channel-in= don't use this channel as incoming (can be specified multiple times)
-o, --exclude-channel-out= don't use this channel as outgoing (can be specified multiple times)
-e, --exclude-channel= don't use this channel at all (can be specified multiple times)

@ -6,6 +6,7 @@
"perc": 20,
"econ_ratio": 0.5,
"amount": 100000,
"min_amount": 50000,
"probe_steps": 5,
"pfrom": 10,
"pto": 30,

@ -31,6 +31,7 @@ var params struct {
Amount int64 `short:"a" long:"amount" description:"amount to rebalance" json:"amount"`
EconRatio float64 `long:"econ-ratio" description:"economical ratio for fee limit calculation as a multiple of target channel fee (for example, 0.5 means you want to pay at max half the fee you might earn for routing out of the target channel)" json:"econ_ratio"`
ProbeSteps int `short:"b" long:"probe-steps" description:"if the payment fails at the last hop try to probe lower amount using this many steps" json:"probe_steps"`
MinAmount int64 `long:"min-amount" description:"if probing is enabled this will be the minimum amount to try" json:"min_amount"`
ExcludeChannelsIn []uint64 `short:"i" long:"exclude-channel-in" description:"don't use this channel as incoming (can be specified multiple times)" json:"exclude_channels_in"`
ExcludeChannelsOut []uint64 `short:"o" long:"exclude-channel-out" description:"don't use this channel as outgoing (can be specified multiple times)" json:"exclude_channels_out"`
ExcludeChannels []uint64 `short:"e" long:"exclude-channel" description:"don't use this channel at all (can be specified multiple times)" json:"exclude_channels"`
@ -104,7 +105,7 @@ func tryRebalance(ctx context.Context, r *regolancer, invoice **lnrpc.AddInvoice
log.Printf("Attempt %s, amount: %s (max fee: %s)", hiWhiteColorF("#%d", *attempt),
hiWhiteColor(amt), hiWhiteColor(fee/1000))
r.printRoute(ctx, route)
err = r.pay(ctx, *invoice, amt, route, params.ProbeSteps)
err = r.pay(ctx, *invoice, amt, params.MinAmount, route, params.ProbeSteps)
if err == nil {
return nil, false
}
@ -120,7 +121,7 @@ func tryRebalance(ctx context.Context, r *regolancer, invoice **lnrpc.AddInvoice
if err != nil {
log.Printf("Error rebuilding the route for probed payment: %s", errColor(err))
} else {
err = r.pay(ctx, probedInvoice, amt, probedRoute, 0)
err = r.pay(ctx, probedInvoice, amt, 0, probedRoute, 0)
if err == nil {
return nil, false
} else {
@ -162,6 +163,9 @@ func main() {
params.FromPerc = params.Perc
params.ToPerc = params.Perc
}
if params.MinAmount > 0 && params.MinAmount > params.Amount {
log.Fatal("Minimum amount should be more than amount")
}
conn, err := lndclient.NewBasicConn(params.Connect, params.TLSCert, params.MacaroonDir, params.Network,
lndclient.MacFilename(params.MacaroonFilename))
if err != nil {

@ -26,7 +26,8 @@ func (r *regolancer) createInvoice(ctx context.Context, from, to uint64, amount
Expiry: int64(time.Hour.Seconds() * 24)})
}
func (r *regolancer) pay(ctx context.Context, invoice *lnrpc.AddInvoiceResponse, amount int64, route *lnrpc.Route, probeSteps int) error {
func (r *regolancer) pay(ctx context.Context, invoice *lnrpc.AddInvoiceResponse, amount int64,
minAmount int64, route *lnrpc.Route, probeSteps int) error {
fmt.Println()
defer fmt.Println()
lastHop := route.Hops[len(route.Hops)-1]
@ -63,7 +64,13 @@ 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, err := r.probeRoute(ctx, route, 0, amount, amount/2, probeSteps, params.EconRatio)
min := int64(0)
start := amount / 2
if minAmount > 0 && minAmount < amount {
min = -minAmount - 1
start = minAmount
}
maxAmount, err := r.probeRoute(ctx, route, min, amount, start, probeSteps, params.EconRatio)
if err != nil {
return err
}

Loading…
Cancel
Save