Add fee limit ppm

pull/11/head
rkfg 2 years ago
parent 872e073cb8
commit 71103e9448

@ -32,6 +32,7 @@ var params struct {
Perc int64 `short:"p" long:"perc" description:"use this value as both pfrom and pto from above" json:"perc"`
Amount int64 `short:"a" long:"amount" description:"amount to rebalance" json:"amount"`
EconRatio float64 `short:"r" 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" toml:"econ_ratio"`
FeeLimitPPM int64 `short:"F" long:"fee-limit-ppm" description:"don't consider the target channel fee and use this max fee ppm instead (can rebalance at a loss, be careful)" json:"fee_limit_ppm" toml:"fee_limit_ppm"`
LostProfit bool `short:"l" long:"lost-profit" description:"also consider the outbound channel fees when looking for profitable routes so that outbound_fee+inbound_fee < route_fee" json:"lost_profit" toml:"lost_profit"`
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" toml:"probe_steps"`
MinAmount int64 `long:"min-amount" description:"if probing is enabled this will be the minimum amount to try" json:"min_amount" toml:"min_amount"`
@ -177,7 +178,7 @@ func main() {
if params.ToPerc == 0 {
params.ToPerc = 50
}
if params.EconRatio == 0 {
if params.EconRatio == 0 && params.FeeLimitPPM == 0 {
params.EconRatio = 1
}
if params.Perc > 0 {

@ -28,7 +28,21 @@ func (r *regolancer) getChanInfo(ctx context.Context, chanId uint64) (*lnrpc.Cha
return c, nil
}
func (r *regolancer) calcFeeMsat(ctx context.Context, from, to uint64, amtMsat int64, ratio float64) (feeMsat int64,
func (r *regolancer) calcFeeLimitMsat(ctx context.Context, to uint64,
amtMsat int64, ppm int64) (feeMsat int64, lastPKstr string, err error) {
cTo, err := r.getChanInfo(ctx, to)
if err != nil {
return 0, "", err
}
lastPKstr = cTo.Node1Pub
if lastPKstr == r.myPK {
lastPKstr = cTo.Node2Pub
}
feeMsat = amtMsat * ppm / 1e6
return
}
func (r *regolancer) calcEconFeeMsat(ctx context.Context, from, to uint64, amtMsat int64, ratio float64) (feeMsat int64,
lastPKstr string, err error) {
cTo, err := r.getChanInfo(ctx, to)
if err != nil {
@ -61,6 +75,15 @@ func (r *regolancer) calcFeeMsat(ctx context.Context, from, to uint64, amtMsat i
return
}
func (r *regolancer) calcFeeMsat(ctx context.Context, from, to uint64,
amtMsat int64, ratio float64) (feeMsat int64, lastPKstr string, err error) {
if params.FeeLimitPPM > 0 {
return r.calcFeeLimitMsat(ctx, to, amtMsat, params.FeeLimitPPM)
} else {
return r.calcEconFeeMsat(ctx, from, to, amtMsat, params.EconRatio)
}
}
func (r *regolancer) getRoutes(ctx context.Context, from, to uint64, amtMsat int64) ([]*lnrpc.Route, int64, error) {
routeCtx, cancel := context.WithTimeout(ctx, time.Second*30)
defer cancel()

Loading…
Cancel
Save