blindedpath: log chosen blinded paths

In this commit, we log selected blinded paths.
This commit is contained in:
Elle Mouton 2024-08-06 15:12:53 +02:00
parent 95477390a4
commit 697f514d09
No known key found for this signature in database
GPG Key ID: D7D916376026F177
2 changed files with 28 additions and 17 deletions

View File

@ -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

View File

@ -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