From 697f514d09a5e32c9be878e284cd40b5c7833980 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 6 Aug 2024 15:12:53 +0200 Subject: [PATCH] blindedpath: log chosen blinded paths In this commit, we log selected blinded paths. --- itest/lnd_route_blinding_test.go | 4 --- routing/blindedpath/blinded_path.go | 41 ++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/itest/lnd_route_blinding_test.go b/itest/lnd_route_blinding_test.go index f7c4acc2d..08bb10a75 100644 --- a/itest/lnd_route_blinding_test.go +++ b/itest/lnd_route_blinding_test.go @@ -1220,10 +1220,6 @@ func testBlindedRouteDummyHops(ht *lntest.HarnessTest) { // Assert that it contains a single blinded path and that the // introduction node is Carol. payReq = dave.RPC.DecodePayReq(invoiceResp.PaymentRequest) - for _, path := range payReq.BlindedPaths { - ht.Logf("intro node: %x", path.BlindedPath.IntroductionNode) - } - require.Len(ht, payReq.BlindedPaths, 1) // The total number of hop payloads is 3: one for the introduction node diff --git a/routing/blindedpath/blinded_path.go b/routing/blindedpath/blinded_path.go index 11890dcc4..8c2275f9d 100644 --- a/routing/blindedpath/blinded_path.go +++ b/routing/blindedpath/blinded_path.go @@ -132,9 +132,14 @@ func BuildBlindedPaymentPaths(cfg *BuildBlindedPathCfg) ( // For each route returned, we will construct the associated blinded // payment path. for _, route := range routes { - path, err := buildBlindedPaymentPath( - cfg, extractCandidatePath(route), - ) + // Extract the information we need from the route. + candidatePath := extractCandidatePath(route) + + // Pad the given route with dummy hops until the minimum number + // of hops is met. + candidatePath.padWithDummyHops(cfg.MinNumHops) + + path, err := buildBlindedPaymentPath(cfg, candidatePath) if errors.Is(err, errInvalidBlindedPath) { log.Debugf("Not using route (%s) as a blinded path "+ "since it resulted in an invalid blinded path", @@ -148,6 +153,8 @@ func BuildBlindedPaymentPaths(cfg *BuildBlindedPathCfg) ( continue } + log.Debugf("Route selected for blinded path: %s", candidatePath) + paths = append(paths, path) } @@ -163,13 +170,6 @@ func BuildBlindedPaymentPaths(cfg *BuildBlindedPathCfg) ( func buildBlindedPaymentPath(cfg *BuildBlindedPathCfg, path *candidatePath) ( *zpay32.BlindedPaymentPath, error) { - // Pad the given route with dummy hops until the minimum number of hops - // is met. - err := path.padWithDummyHops(cfg.MinNumHops) - if err != nil { - return nil, err - } - hops, minHTLC, maxHTLC, err := collectRelayInfo(cfg, path) if err != nil { return nil, fmt.Errorf("could not collect blinded path relay "+ @@ -664,19 +664,34 @@ type candidatePath struct { hops []*blindedPathHop } +// String returns a string representation of the candidatePath which can be +// useful for logging and debugging. +func (c *candidatePath) String() string { + str := fmt.Sprintf("[%s (intro node)]", c.introNode) + + for _, hop := range c.hops { + if hop.isDummy { + str += "--->[dummy hop]" + continue + } + + str += fmt.Sprintf("--<%d>-->[%s]", hop.channelID, hop.pubKey) + } + + return str +} + // padWithDummyHops will append n dummy hops to the candidatePath hop set. The // pub key for the dummy hop will be the same as the pub key for the final hop // of the path. That way, the final hop will be able to decrypt the data // encrypted for each dummy hop. -func (c *candidatePath) padWithDummyHops(n uint8) error { +func (c *candidatePath) padWithDummyHops(n uint8) { for len(c.hops) < int(n) { c.hops = append(c.hops, &blindedPathHop{ pubKey: c.finalNodeID, isDummy: true, }) } - - return nil } // blindedPathHop holds the information we need to know about a hop in a route