Skip to content

Commit e871103

Browse files
committed
routing: final changes to BlindedPaymentPathSet
Continue adding some complexity behind the BlindedPaymentPathSet. What we do here is add a new IntroNodeOnlyPath method. The assumption we make here is: If multiple blinded paths are provided to us in an invoice but one of those paths only includes an intro node, then there is no point in looking at any other path since we know that the intro node is the destination node. So in such a case, we would have discarded any other path in the `NewBlindedPaymentPathSet` constructor. So then we would only have a single blinded path made up of an introduction node only. In this specific case, in the `newRoute` function, no edge passed to the function would have a blindedPayment associated with it (since there are no blinded hops in this case). So we will have a case where `blindedPathSet` passed to `newRoute` is not nil but `blindedPayment` is nil since nonce was extacted from any edge. If this happens then we can assume that this is the Intro-Node-Only situation described above. And so we grabe the associated payment from the path set.
1 parent daaa24b commit e871103

File tree

4 files changed

+51
-15
lines changed

4 files changed

+51
-15
lines changed

routing/blinding.go

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,36 @@ func (s *BlindedPaymentPathSet) Features() *lnwire.FeatureVector {
154154
return s.features
155155
}
156156

157-
// GetPath is a temporary getter for the single path that the set holds.
158-
// This will be removed later on in this PR.
159-
func (s *BlindedPaymentPathSet) GetPath() *BlindedPayment {
160-
return s.paths[0]
157+
// IntroNodeOnlyPath can be called if it is expected that the path set only
158+
// contains a single payment path which itself only has one hop. It errors if
159+
// this is not the case.
160+
func (s *BlindedPaymentPathSet) IntroNodeOnlyPath() (*BlindedPayment, error) {
161+
if len(s.paths) != 1 {
162+
return nil, fmt.Errorf("expected only a single path in the "+
163+
"blinded payment set, got %d", len(s.paths))
164+
}
165+
166+
if len(s.paths[0].BlindedPath.BlindedHops) > 1 {
167+
return nil, fmt.Errorf("an intro node only path cannot have " +
168+
"more than one hop")
169+
}
170+
171+
return s.paths[0], nil
172+
}
173+
174+
// IsIntroNode returns true if the given vertex is an introduction node for one
175+
// of the paths in the blinded payment path set.
176+
func (s *BlindedPaymentPathSet) IsIntroNode(source route.Vertex) bool {
177+
for _, path := range s.paths {
178+
introVertex := route.NewVertex(
179+
path.BlindedPath.IntroductionPoint,
180+
)
181+
if source == introVertex {
182+
return true
183+
}
184+
}
185+
186+
return false
161187
}
162188

163189
// FinalCLTVDelta is the minimum CLTV delta to use for the final hop on the

routing/pathfind.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,11 @@ func newRoute(sourceVertex route.Vertex,
309309
// we can assume the relevant payment is the only one in the
310310
// payment set.
311311
if blindedPayment == nil {
312-
blindedPayment = blindedPathSet.GetPath()
312+
var err error
313+
blindedPayment, err = blindedPathSet.IntroNodeOnlyPath()
314+
if err != nil {
315+
return nil, err
316+
}
313317
}
314318

315319
var (

routing/pathfind_test.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3296,10 +3296,21 @@ func TestBlindedRouteConstruction(t *testing.T) {
32963296
daveEveEdge := blindedEdges[daveBlindedVertex][0]
32973297

32983298
edges := []*unifiedEdge{
3299-
{policy: aliceBobEdge},
3300-
{policy: bobCarolEdge},
3301-
{policy: carolDaveEdge.EdgePolicy()},
3302-
{policy: daveEveEdge.EdgePolicy()},
3299+
{
3300+
policy: aliceBobEdge,
3301+
},
3302+
{
3303+
policy: bobCarolEdge,
3304+
blindedPayment: blindedPayment,
3305+
},
3306+
{
3307+
policy: carolDaveEdge.EdgePolicy(),
3308+
blindedPayment: blindedPayment,
3309+
},
3310+
{
3311+
policy: daveEveEdge.EdgePolicy(),
3312+
blindedPayment: blindedPayment,
3313+
},
33033314
}
33043315

33053316
// Total timelock for the route should include:

routing/router.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -505,12 +505,7 @@ func NewRouteRequest(source route.Vertex, target *route.Vertex,
505505
)
506506

507507
if blindedPathSet != nil {
508-
blindedPayment := blindedPathSet.GetPath()
509-
510-
introVertex := route.NewVertex(
511-
blindedPayment.BlindedPath.IntroductionPoint,
512-
)
513-
if source == introVertex {
508+
if blindedPathSet.IsIntroNode(source) {
514509
return nil, ErrSelfIntro
515510
}
516511

0 commit comments

Comments
 (0)