routing: add BlindedPayment to unifiedEdge

Later on in this series, we will need to know during path finding if an
edge we are traversing was derived from a blinded payment path. In
preparation for that, we add a BlindedPayment member to the
`unifiedEdge` struct.

The reason we will need this later on is because: In the case where we
receive multiple blinded paths from the receipient, we will first swap
out the final hop node of each path with a single unified target node so
that path finding can work as normal. Once we have selected a route
though, we will want to know which path an edge belongs to so that we
can swap the correct destination node back in.
This commit is contained in:
Elle Mouton 2024-05-14 12:53:02 +02:00
parent 1ec2a1be11
commit 925b68c1ed
No known key found for this signature in database
GPG Key ID: D7D916376026F177
3 changed files with 25 additions and 16 deletions

View File

@ -968,6 +968,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
inboundFee,
fakeHopHintCapacity,
reverseEdge.edge.IntermediatePayloadSize,
reverseEdge.edge.BlindedPayment(),
)
}

View File

@ -51,7 +51,8 @@ func newNodeEdgeUnifier(sourceNode, toNode route.Vertex, useInboundFees bool,
// incorrectly specified.
func (u *nodeEdgeUnifier) addPolicy(fromNode route.Vertex,
edge *models.CachedEdgePolicy, inboundFee models.InboundFee,
capacity btcutil.Amount, hopPayloadSizeFn PayloadSizeFunc) {
capacity btcutil.Amount, hopPayloadSizeFn PayloadSizeFunc,
blindedPayment *BlindedPayment) {
localChan := fromNode == u.sourceNode
@ -87,7 +88,7 @@ func (u *nodeEdgeUnifier) addPolicy(fromNode route.Vertex,
}
unifier.edges = append(unifier.edges, newUnifiedEdge(
edge, capacity, inboundFee, hopPayloadSizeFn,
edge, capacity, inboundFee, hopPayloadSizeFn, blindedPayment,
))
}
@ -112,7 +113,7 @@ func (u *nodeEdgeUnifier) addGraphPolicies(g routingGraph) error {
u.addPolicy(
channel.OtherNode, channel.InPolicy, inboundFee,
channel.Capacity, defaultHopPayloadSize,
channel.Capacity, defaultHopPayloadSize, nil,
)
return nil
@ -134,18 +135,23 @@ type unifiedEdge struct {
// is needed because hops of a blinded path differ in their payload
// structure compared to cleartext hops.
hopPayloadSizeFn PayloadSizeFunc
// blindedPayment if set, is the BlindedPayment that this edge was
// derived from originally.
blindedPayment *BlindedPayment
}
// newUnifiedEdge constructs a new unifiedEdge.
func newUnifiedEdge(policy *models.CachedEdgePolicy, capacity btcutil.Amount,
inboundFees models.InboundFee,
hopPayloadSizeFn PayloadSizeFunc) *unifiedEdge {
inboundFees models.InboundFee, hopPayloadSizeFn PayloadSizeFunc,
blindedPayment *BlindedPayment) *unifiedEdge {
return &unifiedEdge{
policy: policy,
capacity: capacity,
inboundFees: inboundFees,
hopPayloadSizeFn: hopPayloadSizeFn,
blindedPayment: blindedPayment,
}
}
@ -304,7 +310,7 @@ func (u *edgeUnifier) getEdgeLocal(netAmtReceived lnwire.MilliSatoshi,
// Update best edge.
bestEdge = newUnifiedEdge(
edge.policy, edge.capacity, edge.inboundFees,
edge.hopPayloadSizeFn,
edge.hopPayloadSizeFn, edge.blindedPayment,
)
}
@ -386,6 +392,7 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,
bestPolicy = newUnifiedEdge(
edge.policy, 0, edge.inboundFees, nil,
edge.blindedPayment,
)
// The payload size function for edges to a connected peer is
@ -414,7 +421,7 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,
policyCopy.TimeLockDelta = maxTimelock
modifiedEdge := newUnifiedEdge(
&policyCopy, maxCapMsat.ToSatoshis(), bestPolicy.inboundFees,
hopPayloadSizeFn,
hopPayloadSizeFn, bestPolicy.blindedPayment,
)
return modifiedEdge

View File

@ -59,37 +59,37 @@ func TestNodeEdgeUnifier(t *testing.T) {
unifierFilled := newNodeEdgeUnifier(source, toNode, false, nil)
unifierFilled.addPolicy(
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize,
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize, nil,
)
unifierFilled.addPolicy(
fromNode, &p2, inboundFee2, c2, defaultHopPayloadSize,
fromNode, &p2, inboundFee2, c2, defaultHopPayloadSize, nil,
)
unifierNoCapacity := newNodeEdgeUnifier(source, toNode, false, nil)
unifierNoCapacity.addPolicy(
fromNode, &p1, inboundFee1, 0, defaultHopPayloadSize,
fromNode, &p1, inboundFee1, 0, defaultHopPayloadSize, nil,
)
unifierNoCapacity.addPolicy(
fromNode, &p2, inboundFee2, 0, defaultHopPayloadSize,
fromNode, &p2, inboundFee2, 0, defaultHopPayloadSize, nil,
)
unifierNoInfo := newNodeEdgeUnifier(source, toNode, false, nil)
unifierNoInfo.addPolicy(
fromNode, &models.CachedEdgePolicy{}, models.InboundFee{},
0, defaultHopPayloadSize,
0, defaultHopPayloadSize, nil,
)
unifierInboundFee := newNodeEdgeUnifier(source, toNode, true, nil)
unifierInboundFee.addPolicy(
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize,
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize, nil,
)
unifierInboundFee.addPolicy(
fromNode, &p2, inboundFee2, c2, defaultHopPayloadSize,
fromNode, &p2, inboundFee2, c2, defaultHopPayloadSize, nil,
)
unifierLocal := newNodeEdgeUnifier(fromNode, toNode, true, nil)
unifierLocal.addPolicy(
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize,
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize, nil,
)
inboundFeeZero := models.InboundFee{}
@ -98,10 +98,11 @@ func TestNodeEdgeUnifier(t *testing.T) {
}
unifierNegInboundFee := newNodeEdgeUnifier(source, toNode, true, nil)
unifierNegInboundFee.addPolicy(
fromNode, &p1, inboundFeeZero, c1, defaultHopPayloadSize,
fromNode, &p1, inboundFeeZero, c1, defaultHopPayloadSize, nil,
)
unifierNegInboundFee.addPolicy(
fromNode, &p2, inboundFeeNegative, c2, defaultHopPayloadSize,
nil,
)
tests := []struct {