From d331ddd2f4d1b9cdf2c7fe563cd6e3557ad8f3a1 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 2 Aug 2017 21:01:49 -0700 Subject: [PATCH] routing: when creating a route, base time locks off current height MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit implements some missing functionality, namely before all time locks were calculated off of a base height of 0 essentially. That’s incorrect as all time locks within HTLC’s would then be already expired. We remedy this requesting the latest height when creating a route to ensure that our time locks are set properly. --- routing/pathfind.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/routing/pathfind.go b/routing/pathfind.go index 7a0818f8..2571278f 100644 --- a/routing/pathfind.go +++ b/routing/pathfind.go @@ -199,9 +199,16 @@ func (s sortableRoutes) Swap(i, j int) { // // 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 btcutil.Amount, pathEdges []*ChannelHop) (*Route, error) { +func newRoute(amtToSend btcutil.Amount, pathEdges []*ChannelHop, + currentHeight uint32) (*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 + // height, as this is the basis that all of the time locks will be + // calculated from. route := &Route{ - Hops: make([]*Hop, len(pathEdges)), + Hops: make([]*Hop, len(pathEdges)), + TotalTimeLock: currentHeight, } // TODO(roasbeef): need to do sanity check to ensure we don't make a @@ -268,7 +275,8 @@ func newRoute(amtToSend btcutil.Amount, pathEdges []*ChannelHop) (*Route, error) } else { // Otherwise, the value of the outgoing time-lock will // be the value of the time-lock for the _outgoing_ - // HTLC. + // HTLC, so we factor in their specified grace period + // (time lock delta). nextHop.OutgoingTimeLock = route.TotalTimeLock - uint32(edge.TimeLockDelta) }