diff --git a/channeldb/graph.go b/channeldb/graph.go index 571ab31f..3a8f6c56 100644 --- a/channeldb/graph.go +++ b/channeldb/graph.go @@ -155,6 +155,9 @@ const ( // would be possible for a node to create a ton of updates and slowly // fill our disk, and also waste bandwidth due to relaying. MaxAllowedExtraOpaqueBytes = 10000 + + // feeRateParts is the total number of parts used to express fee rates. + feeRateParts = 1e6 ) // ChannelGraph is a persistent, on-disk graph representation of the Lightning @@ -2820,6 +2823,15 @@ func (c *ChannelEdgePolicy) IsDisabled() bool { lnwire.ChanUpdateDisabled } +// ComputeFee computes the fee to forward an HTLC of `amt` milli-satoshis over +// the passed active payment channel. This value is currently computed as +// specified in BOLT07, but will likely change in the near future. +func (c *ChannelEdgePolicy) ComputeFee( + amt lnwire.MilliSatoshi) lnwire.MilliSatoshi { + + return c.FeeBaseMSat + (amt*c.FeeProportionalMillionths)/feeRateParts +} + // FetchChannelEdgesByOutpoint attempts to lookup the two directed edges for // the channel identified by the funding outpoint. If the channel can't be // found, then ErrEdgeNotFound is returned. A struct which houses the general diff --git a/routing/pathfind.go b/routing/pathfind.go index a38267ff..9f415c84 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -66,15 +66,6 @@ type edgePolicyWithSource struct { edge *channeldb.ChannelEdgePolicy } -// computeFee computes the fee to forward an HTLC of `amt` milli-satoshis over -// the passed active payment channel. This value is currently computed as -// specified in BOLT07, but will likely change in the near future. -func computeFee(amt lnwire.MilliSatoshi, - edge *channeldb.ChannelEdgePolicy) lnwire.MilliSatoshi { - - return edge.FeeBaseMSat + (amt*edge.FeeProportionalMillionths)/1000000 -} - // newRoute returns a fully valid route between the source and target that's // capable of supporting a payment of `amtToSend` after fees are fully // computed. If the route is too long, or the selected path cannot support the @@ -129,7 +120,7 @@ func newRoute(amtToSend lnwire.MilliSatoshi, sourceVertex route.Vertex, // and its policy for the outgoing channel. This policy // is stored as part of the incoming channel of // the next hop. - fee = computeFee(amtToForward, pathEdges[i+1]) + fee = pathEdges[i+1].ComputeFee(amtToForward) } // If this is the last hop, then for verification purposes, the @@ -482,7 +473,7 @@ func findPath(g *graphParams, r *RestrictParams, cfg *PathFindingConfig, var fee lnwire.MilliSatoshi var timeLockDelta uint16 if fromVertex != source { - fee = computeFee(amountToSend, edge) + fee = edge.ComputeFee(amountToSend) timeLockDelta = edge.TimeLockDelta }