From baf2e445f46446bd6748039b46af95475873c5c7 Mon Sep 17 00:00:00 2001 From: Alex Pilon Date: Tue, 6 May 2025 13:39:23 -0400 Subject: [PATCH 1/2] lncli: Add --route_hints flag support Adds --route_hints flag to sendpayment. Hints should be JSON encoded (see usage for example). Adds --route_hints flag to queryroutes. Errors if blinded paths are set. --- cmd/commands/cmd_payments.go | 50 ++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/cmd/commands/cmd_payments.go b/cmd/commands/cmd_payments.go index 45d64796e..d83200596 100644 --- a/cmd/commands/cmd_payments.go +++ b/cmd/commands/cmd_payments.go @@ -5,6 +5,7 @@ import ( "context" "crypto/rand" "encoding/hex" + "encoding/json" "errors" "fmt" "io" @@ -254,6 +255,15 @@ var SendPaymentCommand = cli.Command{ Name: "keysend", Usage: "will generate a pre-image and encode it in the sphinx packet, a dest must be set [experimental]", }, + cli.StringFlag{ + Name: "route_hints", + Usage: `route hints for sending through private ` + + `channels. eg: ` + + `'[{"hop_hints":[{"node_id":"A","chan_id":1,` + + `"fee_base_msat":2,` + + `"fee_proportional_millionths":3,` + + `"cltv_expiry_delta":4}]}]'`, + }, ), Action: SendPayment, } @@ -473,6 +483,20 @@ func SendPayment(ctx *cli.Context) error { req.PaymentAddr = payAddr + if ctx.IsSet("route_hints") { + // Parse the route hints JSON. + routeHintsJSON := ctx.String("route_hints") + var routeHints []*lnrpc.RouteHint + + err := json.Unmarshal([]byte(routeHintsJSON), &routeHints) + if err != nil { + return fmt.Errorf("error unmarshaling route_hints "+ + "json: %w", err) + } + + req.RouteHints = routeHints + } + return SendPaymentRequest(ctx, req, conn, conn, routerRPCSendPayment) } @@ -1154,6 +1178,15 @@ var queryRoutesCommand = cli.Command{ blindedBaseFlag, blindedPPMFlag, blindedCLTVFlag, + cli.StringFlag{ + Name: "route_hints", + Usage: `route hints for searching through private ` + + `channels (and no blinded paths set). eg: ` + + `'[{"hop_hints":[{"node_id":"A","chan_id":1,` + + `"fee_base_msat":2,` + + `"fee_proportional_millionths":3,` + + `"cltv_expiry_delta":4}]}]'`, + }, }, Action: actionDecorator(queryRoutes), } @@ -1248,6 +1281,23 @@ func queryRoutes(ctx *cli.Context) error { BlindedPaymentPaths: blindedRoutes, } + if ctx.IsSet("route_hints") { + if len(blindedRoutes) > 0 { + return fmt.Errorf("--route_hints should not be used " + + "if blinded paths are set") + } + routeHintsJSON := ctx.String("route_hints") + var routeHints []*lnrpc.RouteHint + + err := json.Unmarshal([]byte(routeHintsJSON), &routeHints) + if err != nil { + return fmt.Errorf("error unmarshaling route_hints "+ + "json: %w", err) + } + + req.RouteHints = routeHints + } + route, err := client.QueryRoutes(ctxc, req) if err != nil { return err From 0437850089e40792ca97cc6bd893c9deca5b757f Mon Sep 17 00:00:00 2001 From: Alex Pilon Date: Tue, 6 May 2025 13:59:15 -0400 Subject: [PATCH 2/2] docs: Update release notes for --route_hints flag --- docs/release-notes/release-notes-0.20.0.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/release-notes/release-notes-0.20.0.md b/docs/release-notes/release-notes-0.20.0.md index fd8df9579..a78b3919c 100644 --- a/docs/release-notes/release-notes-0.20.0.md +++ b/docs/release-notes/release-notes-0.20.0.md @@ -28,6 +28,10 @@ ## lncli Additions +* [`lncli sendpayment` and `lncli queryroutes` now support the + `--route_hints` flag](https://github.com/lightningnetwork/lnd/pull/9721) to + support routing through private channels. + # Improvements ## Functional Updates