mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-11 01:11:02 +02:00
routing+refactor: add a constructor for unifiedEdge
Add a constructor for unified edge. In upcoming commits, we will add a new member to unifiedEdge and a constructor forces us to not forget to populate a required member.
This commit is contained in:
parent
28d1227c04
commit
1ec2a1be11
@ -86,12 +86,9 @@ func (u *nodeEdgeUnifier) addPolicy(fromNode route.Vertex,
|
|||||||
inboundFee = models.InboundFee{}
|
inboundFee = models.InboundFee{}
|
||||||
}
|
}
|
||||||
|
|
||||||
unifier.edges = append(unifier.edges, &unifiedEdge{
|
unifier.edges = append(unifier.edges, newUnifiedEdge(
|
||||||
policy: edge,
|
edge, capacity, inboundFee, hopPayloadSizeFn,
|
||||||
capacity: capacity,
|
))
|
||||||
hopPayloadSizeFn: hopPayloadSizeFn,
|
|
||||||
inboundFees: inboundFee,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// addGraphPolicies adds all policies that are known for the toNode in the
|
// addGraphPolicies adds all policies that are known for the toNode in the
|
||||||
@ -139,6 +136,19 @@ type unifiedEdge struct {
|
|||||||
hopPayloadSizeFn PayloadSizeFunc
|
hopPayloadSizeFn PayloadSizeFunc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// newUnifiedEdge constructs a new unifiedEdge.
|
||||||
|
func newUnifiedEdge(policy *models.CachedEdgePolicy, capacity btcutil.Amount,
|
||||||
|
inboundFees models.InboundFee,
|
||||||
|
hopPayloadSizeFn PayloadSizeFunc) *unifiedEdge {
|
||||||
|
|
||||||
|
return &unifiedEdge{
|
||||||
|
policy: policy,
|
||||||
|
capacity: capacity,
|
||||||
|
inboundFees: inboundFees,
|
||||||
|
hopPayloadSizeFn: hopPayloadSizeFn,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// amtInRange checks whether an amount falls within the valid range for a
|
// amtInRange checks whether an amount falls within the valid range for a
|
||||||
// channel.
|
// channel.
|
||||||
func (u *unifiedEdge) amtInRange(amt lnwire.MilliSatoshi) bool {
|
func (u *unifiedEdge) amtInRange(amt lnwire.MilliSatoshi) bool {
|
||||||
@ -292,12 +302,10 @@ func (u *edgeUnifier) getEdgeLocal(netAmtReceived lnwire.MilliSatoshi,
|
|||||||
maxBandwidth = bandwidth
|
maxBandwidth = bandwidth
|
||||||
|
|
||||||
// Update best edge.
|
// Update best edge.
|
||||||
bestEdge = &unifiedEdge{
|
bestEdge = newUnifiedEdge(
|
||||||
policy: edge.policy,
|
edge.policy, edge.capacity, edge.inboundFees,
|
||||||
capacity: edge.capacity,
|
edge.hopPayloadSizeFn,
|
||||||
hopPayloadSizeFn: edge.hopPayloadSizeFn,
|
)
|
||||||
inboundFees: edge.inboundFees,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return bestEdge
|
return bestEdge
|
||||||
@ -376,10 +384,9 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,
|
|||||||
}
|
}
|
||||||
maxFee = fee
|
maxFee = fee
|
||||||
|
|
||||||
bestPolicy = &unifiedEdge{
|
bestPolicy = newUnifiedEdge(
|
||||||
policy: edge.policy,
|
edge.policy, 0, edge.inboundFees, nil,
|
||||||
inboundFees: edge.inboundFees,
|
)
|
||||||
}
|
|
||||||
|
|
||||||
// The payload size function for edges to a connected peer is
|
// The payload size function for edges to a connected peer is
|
||||||
// always the same hence there is not need to find the maximum.
|
// always the same hence there is not need to find the maximum.
|
||||||
@ -404,15 +411,13 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi,
|
|||||||
// 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.
|
||||||
policyCopy := *bestPolicy.policy
|
policyCopy := *bestPolicy.policy
|
||||||
modifiedEdge := unifiedEdge{
|
policyCopy.TimeLockDelta = maxTimelock
|
||||||
policy: &policyCopy,
|
modifiedEdge := newUnifiedEdge(
|
||||||
inboundFees: bestPolicy.inboundFees,
|
&policyCopy, maxCapMsat.ToSatoshis(), bestPolicy.inboundFees,
|
||||||
}
|
hopPayloadSizeFn,
|
||||||
modifiedEdge.policy.TimeLockDelta = maxTimelock
|
)
|
||||||
modifiedEdge.capacity = maxCapMsat.ToSatoshis()
|
|
||||||
modifiedEdge.hopPayloadSizeFn = hopPayloadSizeFn
|
|
||||||
|
|
||||||
return &modifiedEdge
|
return modifiedEdge
|
||||||
}
|
}
|
||||||
|
|
||||||
// minAmt returns the minimum amount that can be forwarded on this connection.
|
// minAmt returns the minimum amount that can be forwarded on this connection.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user