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:
parent
4b8d052afc
commit
62cd6ee046
@ -51,9 +51,9 @@ type Hop struct {
|
||||
// along.
|
||||
Channel *ChannelHop
|
||||
|
||||
// TimeLockDelta is the delta that this hop will subtract from the HTLC
|
||||
// before extending it to the next hop in the route.
|
||||
TimeLockDelta uint16
|
||||
// OutgoingTimeLock is the timelock value that should be used when
|
||||
// crafting the _outgoing_ HTLC from this hop.
|
||||
OutgoingTimeLock uint32
|
||||
|
||||
// AmtToForward is the amount that this hop will forward to the next
|
||||
// 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,
|
||||
AmtToForward: runningAmt,
|
||||
Fee: computeFee(runningAmt, edge),
|
||||
TimeLockDelta: edge.TimeLockDelta,
|
||||
}
|
||||
edge.Node.PubKey.Curve = nil
|
||||
|
||||
@ -220,7 +219,23 @@ func newRoute(amtToSend btcutil.Amount, pathEdges []*ChannelHop) (*Route, error)
|
||||
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
|
||||
}
|
||||
@ -357,6 +372,9 @@ func findPath(graph *channeldb.ChannelGraph, sourceNode *channeldb.LightningNode
|
||||
if tempDist < distance[v].dist &&
|
||||
edgeInfo.Capacity >= amt {
|
||||
|
||||
// TODO(roasbeef): need to also account
|
||||
// for min HTLC
|
||||
|
||||
distance[v] = nodeWithDist{
|
||||
dist: tempDist,
|
||||
node: edge.Node,
|
||||
|
Loading…
Reference in New Issue
Block a user