routing: populate the OutgoingTimeLock field within route hops

This commit inches towards fully validation+adherance of the per-hop
payloads within an HTLC’s route by properly calculating the outgoing
time lock value for each hop according to the current draft
specification.
This commit is contained in:
Olaoluwa Osuntokun 2017-06-16 22:33:50 +02:00
parent 4b8d052afc
commit 62cd6ee046
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -51,9 +51,9 @@ type Hop struct {
// along. // along.
Channel *ChannelHop Channel *ChannelHop
// TimeLockDelta is the delta that this hop will subtract from the HTLC // OutgoingTimeLock is the timelock value that should be used when
// before extending it to the next hop in the route. // crafting the _outgoing_ HTLC from this hop.
TimeLockDelta uint16 OutgoingTimeLock uint32
// AmtToForward is the amount that this hop will forward to the next // AmtToForward is the amount that this hop will forward to the next
// hop. This value is less than the value that the incoming HTLC // hop. This value is less than the value that the incoming HTLC
@ -187,7 +187,6 @@ func newRoute(amtToSend btcutil.Amount, pathEdges []*ChannelHop) (*Route, error)
Channel: edge, Channel: edge,
AmtToForward: runningAmt, AmtToForward: runningAmt,
Fee: computeFee(runningAmt, edge), Fee: computeFee(runningAmt, edge),
TimeLockDelta: edge.TimeLockDelta,
} }
edge.Node.PubKey.Curve = nil edge.Node.PubKey.Curve = nil
@ -220,7 +219,23 @@ func newRoute(amtToSend btcutil.Amount, pathEdges []*ChannelHop) (*Route, error)
nextHop.Fee = 0 nextHop.Fee = 0
} }
route.TotalTimeLock += uint32(nextHop.TimeLockDelta) // 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 time
// lock delta specified within the routing information.
if i == len(pathEdges)-1 {
nextHop.OutgoingTimeLock = uint32(edge.TimeLockDelta)
} else {
// Otherwise, the value of the outgoing time-lock will
// be the value of the time-lock for the _outgoing_
// HTLC.
nextHop.OutgoingTimeLock = route.TotalTimeLock -
uint32(edge.TimeLockDelta)
}
route.Hops[i] = nextHop route.Hops[i] = nextHop
} }
@ -357,6 +372,9 @@ func findPath(graph *channeldb.ChannelGraph, sourceNode *channeldb.LightningNode
if tempDist < distance[v].dist && if tempDist < distance[v].dist &&
edgeInfo.Capacity >= amt { edgeInfo.Capacity >= amt {
// TODO(roasbeef): need to also account
// for min HTLC
distance[v] = nodeWithDist{ distance[v] = nodeWithDist{
dist: tempDist, dist: tempDist,
node: edge.Node, node: edge.Node,