diff --git a/routing/unified_edges.go b/routing/unified_edges.go index 232c92e1c..61c756ff3 100644 --- a/routing/unified_edges.go +++ b/routing/unified_edges.go @@ -86,12 +86,9 @@ func (u *nodeEdgeUnifier) addPolicy(fromNode route.Vertex, inboundFee = models.InboundFee{} } - unifier.edges = append(unifier.edges, &unifiedEdge{ - policy: edge, - capacity: capacity, - hopPayloadSizeFn: hopPayloadSizeFn, - inboundFees: inboundFee, - }) + unifier.edges = append(unifier.edges, newUnifiedEdge( + edge, capacity, inboundFee, hopPayloadSizeFn, + )) } // addGraphPolicies adds all policies that are known for the toNode in the @@ -139,6 +136,19 @@ type unifiedEdge struct { 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 // channel. func (u *unifiedEdge) amtInRange(amt lnwire.MilliSatoshi) bool { @@ -292,12 +302,10 @@ func (u *edgeUnifier) getEdgeLocal(netAmtReceived lnwire.MilliSatoshi, maxBandwidth = bandwidth // Update best edge. - bestEdge = &unifiedEdge{ - policy: edge.policy, - capacity: edge.capacity, - hopPayloadSizeFn: edge.hopPayloadSizeFn, - inboundFees: edge.inboundFees, - } + bestEdge = newUnifiedEdge( + edge.policy, edge.capacity, edge.inboundFees, + edge.hopPayloadSizeFn, + ) } return bestEdge @@ -376,10 +384,9 @@ func (u *edgeUnifier) getEdgeNetwork(netAmtReceived lnwire.MilliSatoshi, } maxFee = fee - bestPolicy = &unifiedEdge{ - policy: edge.policy, - inboundFees: edge.inboundFees, - } + bestPolicy = newUnifiedEdge( + edge.policy, 0, edge.inboundFees, nil, + ) // The payload size function for edges to a connected peer is // 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 // have distinct policies for channels to the same peer. policyCopy := *bestPolicy.policy - modifiedEdge := unifiedEdge{ - policy: &policyCopy, - inboundFees: bestPolicy.inboundFees, - } - modifiedEdge.policy.TimeLockDelta = maxTimelock - modifiedEdge.capacity = maxCapMsat.ToSatoshis() - modifiedEdge.hopPayloadSizeFn = hopPayloadSizeFn + policyCopy.TimeLockDelta = maxTimelock + modifiedEdge := newUnifiedEdge( + &policyCopy, maxCapMsat.ToSatoshis(), bestPolicy.inboundFees, + hopPayloadSizeFn, + ) - return &modifiedEdge + return modifiedEdge } // minAmt returns the minimum amount that can be forwarded on this connection.