From 23b6d844931d922b6509c7c3f0b4897714e310b5 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 18 Oct 2017 21:43:53 -0700 Subject: [PATCH] routing: modify newPath to take the preferred final CLTV delta of last hop In this commit, rather than reading the final CLTV delta from the channel graph itself (which would require _both_ edges to be advertised in order to route over), we now instead have moved to allowing the receiving node to choose their own final CLTV delta. --- routing/pathfind.go | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index b7afa7296..9425b62b0 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -211,7 +211,8 @@ func (r *Route) ToHopPayloads() []sphinx.HopData { // NOTE: The passed slice of ChannelHops MUST be sorted in forward order: from // the source to the target node of the path finding attempt. func newRoute(amtToSend lnwire.MilliSatoshi, sourceVertex vertex, - pathEdges []*ChannelHop, currentHeight uint32) (*Route, error) { + pathEdges []*ChannelHop, currentHeight uint32, + finalCLTVDelta uint16) (*Route, error) { // First, we'll create a new empty route with enough hops to match the // amount of path edges. We set the TotalTimeLock to the current block @@ -298,17 +299,23 @@ func newRoute(amtToSend lnwire.MilliSatoshi, sourceVertex vertex, nextHop.Fee = 0 } - // Next, increment the total timelock of the entire route such - // that each hops time lock increases as we walk backwards in - // the route, using the delta of the previous hop. - route.TotalTimeLock += uint32(edge.TimeLockDelta) - // If this is the last hop, then for verification purposes, the // value of the outgoing time-lock should be _exactly_ the // absolute time out they'd expect in the HTLC. if i == len(pathEdges)-1 { - nextHop.OutgoingTimeLock = currentHeight + uint32(edge.TimeLockDelta) + // As this is the last hop, we'll use the specified + // final CLTV delta value instead of the value from the + // last link in the route. + route.TotalTimeLock += uint32(finalCLTVDelta) + + nextHop.OutgoingTimeLock = currentHeight + uint32(finalCLTVDelta) } else { + // Next, increment the total timelock of the entire + // route such that each hops time lock increases as we + // walk backwards in the route, using the delta of the + // previous hop. + route.TotalTimeLock += uint32(edge.TimeLockDelta) + // Otherwise, the value of the outgoing time-lock will // be the value of the time-lock for the _outgoing_ // HTLC, so we factor in their specified grace period