routing: return *unifiedPolicyEdge in getPolicy
We encapsulate the capacity inside a unifiedPolicyEdge for later usage. The meaning of "policy" has changed now, which will be refactored in the next commmit.
This commit is contained in:
4 files changed
+23
-19
No files matched your search
+7
-7
@@ -628,7 +628,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
|||||||
// satisfy our specific requirements.
|
// satisfy our specific requirements.
|
||||||
processEdge := func(fromVertex route.Vertex,
|
processEdge := func(fromVertex route.Vertex,
|
||||||
fromFeatures *lnwire.FeatureVector,
|
fromFeatures *lnwire.FeatureVector,
|
||||||
edge *channeldb.CachedEdgePolicy, toNodeDist *nodeWithDist) {
|
edge *unifiedPolicyEdge, toNodeDist *nodeWithDist) {
|
||||||
|
|
||||||
edgesExpanded++
|
edgesExpanded++
|
||||||
|
|
||||||
@@ -666,8 +666,8 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
|||||||
var fee lnwire.MilliSatoshi
|
var fee lnwire.MilliSatoshi
|
||||||
var timeLockDelta uint16
|
var timeLockDelta uint16
|
||||||
if fromVertex != source {
|
if fromVertex != source {
|
||||||
fee = edge.ComputeFee(amountToSend)
|
fee = edge.policy.ComputeFee(amountToSend)
|
||||||
timeLockDelta = edge.TimeLockDelta
|
timeLockDelta = edge.policy.TimeLockDelta
|
||||||
}
|
}
|
||||||
|
|
||||||
incomingCltv := toNodeDist.incomingCltv + int32(timeLockDelta)
|
incomingCltv := toNodeDist.incomingCltv + int32(timeLockDelta)
|
||||||
@@ -744,9 +744,9 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
|||||||
|
|
||||||
// Every edge should have a positive time lock delta. If we
|
// Every edge should have a positive time lock delta. If we
|
||||||
// encounter a zero delta, log a warning line.
|
// encounter a zero delta, log a warning line.
|
||||||
if edge.TimeLockDelta == 0 {
|
if edge.policy.TimeLockDelta == 0 {
|
||||||
log.Warnf("Channel %v has zero cltv delta",
|
log.Warnf("Channel %v has zero cltv delta",
|
||||||
edge.ChannelID)
|
edge.policy.ChannelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the total routing info size if this hop were to be
|
// Calculate the total routing info size if this hop were to be
|
||||||
@@ -767,7 +767,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
|||||||
LegacyPayload: !supportsTlv,
|
LegacyPayload: !supportsTlv,
|
||||||
}
|
}
|
||||||
|
|
||||||
payloadSize = hop.PayloadSize(edge.ChannelID)
|
payloadSize = hop.PayloadSize(edge.policy.ChannelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
routingInfoSize := toNodeDist.routingInfoSize + payloadSize
|
routingInfoSize := toNodeDist.routingInfoSize + payloadSize
|
||||||
@@ -788,7 +788,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig,
|
|||||||
amountToReceive: amountToReceive,
|
amountToReceive: amountToReceive,
|
||||||
incomingCltv: incomingCltv,
|
incomingCltv: incomingCltv,
|
||||||
probability: probability,
|
probability: probability,
|
||||||
nextHop: edge,
|
nextHop: edge.policy,
|
||||||
routingInfoSize: routingInfoSize,
|
routingInfoSize: routingInfoSize,
|
||||||
}
|
}
|
||||||
distance[fromVertex] = withDist
|
distance[fromVertex] = withDist
|
||||||
|
|||||||
+5
-4
@@ -2837,10 +2837,11 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
|||||||
|
|
||||||
// Add fee for this hop.
|
// Add fee for this hop.
|
||||||
if !localChan {
|
if !localChan {
|
||||||
runningAmt += policy.ComputeFee(runningAmt)
|
runningAmt += policy.policy.ComputeFee(runningAmt)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Tracef("Select channel %v at position %v", policy.ChannelID, i)
|
log.Tracef("Select channel %v at position %v",
|
||||||
|
policy.policy.ChannelID, i)
|
||||||
|
|
||||||
edges[i] = unifiedPolicy
|
edges[i] = unifiedPolicy
|
||||||
}
|
}
|
||||||
@@ -2862,12 +2863,12 @@ func (r *ChannelRouter) BuildRoute(amt *lnwire.MilliSatoshi,
|
|||||||
|
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
// Decrease the amount to send while going forward.
|
// Decrease the amount to send while going forward.
|
||||||
receiverAmt -= policy.ComputeFeeFromIncoming(
|
receiverAmt -= policy.policy.ComputeFeeFromIncoming(
|
||||||
receiverAmt,
|
receiverAmt,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pathEdges = append(pathEdges, policy)
|
pathEdges = append(pathEdges, policy.policy)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build and return the final route.
|
// Build and return the final route.
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ type unifiedPolicy struct {
|
|||||||
// specific amount to send. It differentiates between local and network
|
// specific amount to send. It differentiates between local and network
|
||||||
// channels.
|
// channels.
|
||||||
func (u *unifiedPolicy) getPolicy(amt lnwire.MilliSatoshi,
|
func (u *unifiedPolicy) getPolicy(amt lnwire.MilliSatoshi,
|
||||||
bandwidthHints bandwidthHints) *channeldb.CachedEdgePolicy {
|
bandwidthHints bandwidthHints) *unifiedPolicyEdge {
|
||||||
|
|
||||||
if u.localChan {
|
if u.localChan {
|
||||||
return u.getPolicyLocal(amt, bandwidthHints)
|
return u.getPolicyLocal(amt, bandwidthHints)
|
||||||
@@ -145,10 +145,10 @@ func (u *unifiedPolicy) getPolicy(amt lnwire.MilliSatoshi,
|
|||||||
// getPolicyLocal returns the optimal policy to use for this local connection
|
// getPolicyLocal returns the optimal policy to use for this local connection
|
||||||
// given a specific amount to send.
|
// given a specific amount to send.
|
||||||
func (u *unifiedPolicy) getPolicyLocal(amt lnwire.MilliSatoshi,
|
func (u *unifiedPolicy) getPolicyLocal(amt lnwire.MilliSatoshi,
|
||||||
bandwidthHints bandwidthHints) *channeldb.CachedEdgePolicy {
|
bandwidthHints bandwidthHints) *unifiedPolicyEdge {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bestPolicy *channeldb.CachedEdgePolicy
|
bestPolicy *unifiedPolicyEdge
|
||||||
maxBandwidth lnwire.MilliSatoshi
|
maxBandwidth lnwire.MilliSatoshi
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -192,7 +192,7 @@ func (u *unifiedPolicy) getPolicyLocal(amt lnwire.MilliSatoshi,
|
|||||||
maxBandwidth = bandwidth
|
maxBandwidth = bandwidth
|
||||||
|
|
||||||
// Update best policy.
|
// Update best policy.
|
||||||
bestPolicy = edge.policy
|
bestPolicy = &unifiedPolicyEdge{policy: edge.policy}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bestPolicy
|
return bestPolicy
|
||||||
@@ -202,7 +202,7 @@ func (u *unifiedPolicy) getPolicyLocal(amt lnwire.MilliSatoshi,
|
|||||||
// a specific amount to send. The goal is to return a policy that maximizes the
|
// a specific amount to send. The goal is to return a policy that maximizes the
|
||||||
// probability of a successful forward in a non-strict forwarding context.
|
// probability of a successful forward in a non-strict forwarding context.
|
||||||
func (u *unifiedPolicy) getPolicyNetwork(
|
func (u *unifiedPolicy) getPolicyNetwork(
|
||||||
amt lnwire.MilliSatoshi) *channeldb.CachedEdgePolicy {
|
amt lnwire.MilliSatoshi) *unifiedPolicyEdge {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
bestPolicy *channeldb.CachedEdgePolicy
|
bestPolicy *channeldb.CachedEdgePolicy
|
||||||
@@ -255,8 +255,9 @@ func (u *unifiedPolicy) getPolicyNetwork(
|
|||||||
// get forwarded. Because we penalize pair-wise, there won't be a second
|
// get forwarded. Because we penalize pair-wise, there won't be a second
|
||||||
// chance for this node pair. But this is all only needed for nodes that
|
// chance for this node pair. But this is all only needed for nodes that
|
||||||
// have distinct policies for channels to the same peer.
|
// have distinct policies for channels to the same peer.
|
||||||
modifiedPolicy := *bestPolicy
|
policyCopy := *bestPolicy
|
||||||
modifiedPolicy.TimeLockDelta = maxTimelock
|
modifiedPolicy := unifiedPolicyEdge{policy: &policyCopy}
|
||||||
|
modifiedPolicy.policy.TimeLockDelta = maxTimelock
|
||||||
|
|
||||||
return &modifiedPolicy
|
return &modifiedPolicy
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,12 +39,14 @@ func TestUnifiedPolicies(t *testing.T) {
|
|||||||
u.addPolicy(fromNode, &p1, 7)
|
u.addPolicy(fromNode, &p1, 7)
|
||||||
u.addPolicy(fromNode, &p2, 7)
|
u.addPolicy(fromNode, &p2, 7)
|
||||||
|
|
||||||
checkPolicy := func(policy *channeldb.CachedEdgePolicy,
|
checkPolicy := func(unifiedPolicy *unifiedPolicyEdge,
|
||||||
feeBase lnwire.MilliSatoshi, feeRate lnwire.MilliSatoshi,
|
feeBase lnwire.MilliSatoshi, feeRate lnwire.MilliSatoshi,
|
||||||
timeLockDelta uint16) {
|
timeLockDelta uint16) {
|
||||||
|
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
policy := unifiedPolicy.policy
|
||||||
|
|
||||||
if policy.FeeBaseMSat != feeBase {
|
if policy.FeeBaseMSat != feeBase {
|
||||||
t.Fatalf("expected fee base %v, got %v",
|
t.Fatalf("expected fee base %v, got %v",
|
||||||
feeBase, policy.FeeBaseMSat)
|
feeBase, policy.FeeBaseMSat)
|
||||||
|
|||||||
Reference in new issue
Block a user