mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-05-05 09:20:21 +02:00
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:
parent
1ec2a1be11
commit
925b68c1ed
@ -968,6 +968,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
|||||||
inboundFee,
|
inboundFee,
|
||||||
fakeHopHintCapacity,
|
fakeHopHintCapacity,
|
||||||
reverseEdge.edge.IntermediatePayloadSize,
|
reverseEdge.edge.IntermediatePayloadSize,
|
||||||
|
reverseEdge.edge.BlindedPayment(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +51,8 @@ func newNodeEdgeUnifier(sourceNode, toNode route.Vertex, useInboundFees bool,
|
|||||||
// incorrectly specified.
|
// incorrectly specified.
|
||||||
func (u *nodeEdgeUnifier) addPolicy(fromNode route.Vertex,
|
func (u *nodeEdgeUnifier) addPolicy(fromNode route.Vertex,
|
||||||
edge *models.CachedEdgePolicy, inboundFee models.InboundFee,
|
edge *models.CachedEdgePolicy, inboundFee models.InboundFee,
|
||||||
capacity btcutil.Amount, hopPayloadSizeFn PayloadSizeFunc) {
|
capacity btcutil.Amount, hopPayloadSizeFn PayloadSizeFunc,
|
||||||
|
blindedPayment *BlindedPayment) {
|
||||||
|
|
||||||
localChan := fromNode == u.sourceNode
|
localChan := fromNode == u.sourceNode
|
||||||
|
|
||||||
@ -87,7 +88,7 @@ func (u *nodeEdgeUnifier) addPolicy(fromNode route.Vertex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
unifier.edges = append(unifier.edges, newUnifiedEdge(
|
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(
|
u.addPolicy(
|
||||||
channel.OtherNode, channel.InPolicy, inboundFee,
|
channel.OtherNode, channel.InPolicy, inboundFee,
|
||||||
channel.Capacity, defaultHopPayloadSize,
|
channel.Capacity, defaultHopPayloadSize, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -134,18 +135,23 @@ type unifiedEdge struct {
|
|||||||
// is needed because hops of a blinded path differ in their payload
|
// is needed because hops of a blinded path differ in their payload
|
||||||
// structure compared to cleartext hops.
|
// structure compared to cleartext hops.
|
||||||
hopPayloadSizeFn PayloadSizeFunc
|
hopPayloadSizeFn PayloadSizeFunc
|
||||||
|
|
||||||
|
// blindedPayment if set, is the BlindedPayment that this edge was
|
||||||
|
// derived from originally.
|
||||||
|
blindedPayment *BlindedPayment
|
||||||
}
|
}
|
||||||
|
|
||||||
// newUnifiedEdge constructs a new unifiedEdge.
|
// newUnifiedEdge constructs a new unifiedEdge.
|
||||||
func newUnifiedEdge(policy *models.CachedEdgePolicy, capacity btcutil.Amount,
|
func newUnifiedEdge(policy *models.CachedEdgePolicy, capacity btcutil.Amount,
|
||||||
inboundFees models.InboundFee,
|
inboundFees models.InboundFee, hopPayloadSizeFn PayloadSizeFunc,
|
||||||
hopPayloadSizeFn PayloadSizeFunc) *unifiedEdge {
|
blindedPayment *BlindedPayment) *unifiedEdge {
|
||||||
|
|
||||||
return &unifiedEdge{
|
return &unifiedEdge{
|
||||||
policy: policy,
|
policy: policy,
|
||||||
capacity: capacity,
|
capacity: capacity,
|
||||||
inboundFees: inboundFees,
|
inboundFees: inboundFees,
|
||||||
hopPayloadSizeFn: hopPayloadSizeFn,
|
hopPayloadSizeFn: hopPayloadSizeFn,
|
||||||
|
blindedPayment: blindedPayment,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +310,7 @@ func (u *edgeUnifier) getEdgeLocal(netAmtReceived lnwire.MilliSatoshi,
|
|||||||
// Update best edge.
|
// Update best edge.
|
||||||
bestEdge = newUnifiedEdge(
|
bestEdge = newUnifiedEdge(
|
||||||
edge.policy, edge.capacity, edge.inboundFees,
|
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(
|
bestPolicy = newUnifiedEdge(
|
||||||
edge.policy, 0, edge.inboundFees, nil,
|
edge.policy, 0, edge.inboundFees, nil,
|
||||||
|
edge.blindedPayment,
|
||||||
)
|
)
|
||||||
|
|
||||||
// The payload size function for edges to a connected peer is
|
// 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
|
policyCopy.TimeLockDelta = maxTimelock
|
||||||
modifiedEdge := newUnifiedEdge(
|
modifiedEdge := newUnifiedEdge(
|
||||||
&policyCopy, maxCapMsat.ToSatoshis(), bestPolicy.inboundFees,
|
&policyCopy, maxCapMsat.ToSatoshis(), bestPolicy.inboundFees,
|
||||||
hopPayloadSizeFn,
|
hopPayloadSizeFn, bestPolicy.blindedPayment,
|
||||||
)
|
)
|
||||||
|
|
||||||
return modifiedEdge
|
return modifiedEdge
|
||||||
|
@ -59,37 +59,37 @@ func TestNodeEdgeUnifier(t *testing.T) {
|
|||||||
unifierFilled := newNodeEdgeUnifier(source, toNode, false, nil)
|
unifierFilled := newNodeEdgeUnifier(source, toNode, false, nil)
|
||||||
|
|
||||||
unifierFilled.addPolicy(
|
unifierFilled.addPolicy(
|
||||||
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize,
|
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize, nil,
|
||||||
)
|
)
|
||||||
unifierFilled.addPolicy(
|
unifierFilled.addPolicy(
|
||||||
fromNode, &p2, inboundFee2, c2, defaultHopPayloadSize,
|
fromNode, &p2, inboundFee2, c2, defaultHopPayloadSize, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
unifierNoCapacity := newNodeEdgeUnifier(source, toNode, false, nil)
|
unifierNoCapacity := newNodeEdgeUnifier(source, toNode, false, nil)
|
||||||
unifierNoCapacity.addPolicy(
|
unifierNoCapacity.addPolicy(
|
||||||
fromNode, &p1, inboundFee1, 0, defaultHopPayloadSize,
|
fromNode, &p1, inboundFee1, 0, defaultHopPayloadSize, nil,
|
||||||
)
|
)
|
||||||
unifierNoCapacity.addPolicy(
|
unifierNoCapacity.addPolicy(
|
||||||
fromNode, &p2, inboundFee2, 0, defaultHopPayloadSize,
|
fromNode, &p2, inboundFee2, 0, defaultHopPayloadSize, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
unifierNoInfo := newNodeEdgeUnifier(source, toNode, false, nil)
|
unifierNoInfo := newNodeEdgeUnifier(source, toNode, false, nil)
|
||||||
unifierNoInfo.addPolicy(
|
unifierNoInfo.addPolicy(
|
||||||
fromNode, &models.CachedEdgePolicy{}, models.InboundFee{},
|
fromNode, &models.CachedEdgePolicy{}, models.InboundFee{},
|
||||||
0, defaultHopPayloadSize,
|
0, defaultHopPayloadSize, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
unifierInboundFee := newNodeEdgeUnifier(source, toNode, true, nil)
|
unifierInboundFee := newNodeEdgeUnifier(source, toNode, true, nil)
|
||||||
unifierInboundFee.addPolicy(
|
unifierInboundFee.addPolicy(
|
||||||
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize,
|
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize, nil,
|
||||||
)
|
)
|
||||||
unifierInboundFee.addPolicy(
|
unifierInboundFee.addPolicy(
|
||||||
fromNode, &p2, inboundFee2, c2, defaultHopPayloadSize,
|
fromNode, &p2, inboundFee2, c2, defaultHopPayloadSize, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
unifierLocal := newNodeEdgeUnifier(fromNode, toNode, true, nil)
|
unifierLocal := newNodeEdgeUnifier(fromNode, toNode, true, nil)
|
||||||
unifierLocal.addPolicy(
|
unifierLocal.addPolicy(
|
||||||
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize,
|
fromNode, &p1, inboundFee1, c1, defaultHopPayloadSize, nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
inboundFeeZero := models.InboundFee{}
|
inboundFeeZero := models.InboundFee{}
|
||||||
@ -98,10 +98,11 @@ func TestNodeEdgeUnifier(t *testing.T) {
|
|||||||
}
|
}
|
||||||
unifierNegInboundFee := newNodeEdgeUnifier(source, toNode, true, nil)
|
unifierNegInboundFee := newNodeEdgeUnifier(source, toNode, true, nil)
|
||||||
unifierNegInboundFee.addPolicy(
|
unifierNegInboundFee.addPolicy(
|
||||||
fromNode, &p1, inboundFeeZero, c1, defaultHopPayloadSize,
|
fromNode, &p1, inboundFeeZero, c1, defaultHopPayloadSize, nil,
|
||||||
)
|
)
|
||||||
unifierNegInboundFee.addPolicy(
|
unifierNegInboundFee.addPolicy(
|
||||||
fromNode, &p2, inboundFeeNegative, c2, defaultHopPayloadSize,
|
fromNode, &p2, inboundFeeNegative, c2, defaultHopPayloadSize,
|
||||||
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user