Report max attempt fee

pull/1/head
rkfg 2 years ago
parent 2ea942f357
commit 316874c97f

@ -4,7 +4,8 @@ import "github.com/fatih/color"
var (
faintWhiteColor = color.New(color.FgWhite, color.Faint).SprintFunc()
hiWhiteColor = color.New(color.FgHiWhite, color.Bold).SprintfFunc()
hiWhiteColor = color.New(color.FgHiWhite, color.Bold).SprintFunc()
hiWhiteColorF = color.New(color.FgHiWhite, color.Bold).SprintfFunc()
cyanColor = color.New(color.FgBlue, color.Bold).SprintFunc()
errColor = color.New(color.FgHiRed, color.Bold).SprintFunc()
)

@ -84,12 +84,13 @@ func main() {
log.Fatal("Error creating invoice: ", err)
}
}
routes, err := r.getRoutes(from, to, amt*1000, params.EconRatio)
routes, fee, err := r.getRoutes(from, to, amt*1000, params.EconRatio)
if err != nil {
continue
}
for _, route := range routes {
log.Printf("Attempt %s, amount: %s", hiWhiteColor("#%d", attempt), hiWhiteColor("%d", amt))
log.Printf("Attempt %s, amount: %s (max fee: %s)", hiWhiteColorF("#%d", attempt),
hiWhiteColor(amt), hiWhiteColor(fee/1000))
r.printRoute(route)
err = r.pay(invoice, amt, route)
if err == nil {

@ -50,7 +50,7 @@ func (r *regolancer) pay(invoice *lnrpc.AddInvoiceResponse, amount int64, route
cyanColor(node1name), cyanColor(node2name))
return fmt.Errorf("error: %s @ %d", result.Failure.Code.String(), result.Failure.FailureSourceIndex)
} else {
log.Printf("Success! Paid %s in fees", hiWhiteColor("%d", result.Route.TotalFeesMsat/1000))
log.Printf("Success! Paid %s in fees", hiWhiteColor(result.Route.TotalFeesMsat/1000))
return nil
}
}

@ -9,8 +9,8 @@ import (
"github.com/lightningnetwork/lnd/lnrpc"
)
func calcFeeMsat(amtMsat int64, policy *lnrpc.RoutingPolicy) int64 {
return policy.FeeBaseMsat + amtMsat*policy.FeeRateMilliMsat/1e6
func calcFeeMsat(amtMsat int64, policy *lnrpc.RoutingPolicy) float64 {
return float64(policy.FeeBaseMsat+amtMsat*policy.FeeRateMilliMsat) / 1e6
}
func (r *regolancer) getChanInfo(ctx context.Context, chanId uint64) (*lnrpc.ChannelEdge, error) {
@ -25,12 +25,12 @@ func (r *regolancer) getChanInfo(ctx context.Context, chanId uint64) (*lnrpc.Cha
return c, nil
}
func (r *regolancer) getRoutes(from, to uint64, amtMsat int64, ratio float64) ([]*lnrpc.Route, error) {
func (r *regolancer) getRoutes(from, to uint64, amtMsat int64, ratio float64) ([]*lnrpc.Route, int64, error) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()
c, err := r.getChanInfo(ctx, to)
if err != nil {
return nil, err
return nil, 0, err
}
lastPKstr := c.Node1Pub
policy := c.Node2Policy
@ -38,10 +38,10 @@ func (r *regolancer) getRoutes(from, to uint64, amtMsat int64, ratio float64) ([
lastPKstr = c.Node2Pub
policy = c.Node1Policy
}
feeMsat := float64(calcFeeMsat(amtMsat, policy)) * ratio
feeMsat := int64(calcFeeMsat(amtMsat, policy) * ratio)
lastPK, err := hex.DecodeString(lastPKstr)
if err != nil {
return nil, err
return nil, 0, err
}
routes, err := r.lnClient.QueryRoutes(ctx, &lnrpc.QueryRoutesRequest{
PubKey: r.myPK,
@ -49,12 +49,12 @@ func (r *regolancer) getRoutes(from, to uint64, amtMsat int64, ratio float64) ([
LastHopPubkey: lastPK,
AmtMsat: amtMsat,
UseMissionControl: true,
FeeLimit: &lnrpc.FeeLimit{Limit: &lnrpc.FeeLimit_FixedMsat{FixedMsat: int64(feeMsat)}},
FeeLimit: &lnrpc.FeeLimit{Limit: &lnrpc.FeeLimit_FixedMsat{FixedMsat: feeMsat}},
})
if err != nil {
return nil, err
return nil, 0, err
}
return routes.Routes, nil
return routes.Routes, feeMsat, nil
}
func (r *regolancer) getNodeInfo(pk string) (*lnrpc.NodeInfo, error) {
@ -73,16 +73,16 @@ func (r *regolancer) printRoute(route *lnrpc.Route) {
return
}
errs := ""
fmt.Printf("%s %s\n", faintWhiteColor("Total fee:"), hiWhiteColor("%d", (route.TotalFeesMsat-route.Hops[0].FeeMsat)/1000))
fmt.Printf("%s %s\n", faintWhiteColor("Total fee:"), hiWhiteColor((route.TotalFeesMsat-route.Hops[0].FeeMsat)/1000))
for i, hop := range route.Hops {
nodeInfo, err := r.getNodeInfo(hop.PubKey)
if err != nil {
errs = errs + err.Error() + "\n"
continue
}
fee := hiWhiteColor("%-6d", hop.FeeMsat)
fee := hiWhiteColorF("%-6d", hop.FeeMsat)
if i == 0 {
fee = hiWhiteColor("%-6s", "")
fee = hiWhiteColorF("%-6s", "")
}
fmt.Printf("%s %s %s\n", faintWhiteColor(hop.ChanId), fee, cyanColor(nodeInfo.Node.Alias))
}

Loading…
Cancel
Save