routing: enforce cltv limit in path finding

This commit is contained in:
Joost Jager committed 2019-03-19 10:36:45 +01:00
1 parent c5961d4904
commit 6006549ed5
3 files changed
+127

No files matched your search

+15
View File
@@ -393,6 +393,11 @@ type RestrictParams struct {
// OutgoingChannelID is the channel that needs to be taken to the first
// hop. If nil, any channel may be used.
OutgoingChannelID *uint64
// CltvLimit is the maximum time lock of the route excluding the final
// ctlv. After path finding is complete, the caller needs to increase
// all cltv expiry heights with the required final cltv delta.
CltvLimit *uint32
}
// findPath attempts to find a path from the source node within the
@@ -479,6 +484,7 @@ func findPath(g *graphParams, r *RestrictParams, source, target Vertex,
node: targetNode,
amountToReceive: amt,
fee: 0,
incomingCltv: 0,
}
// We'll use this map as a series of "next" hop pointers. So to get
@@ -575,6 +581,14 @@ func findPath(g *graphParams, r *RestrictParams, source, target Vertex,
timeLockDelta = edge.TimeLockDelta
}
incomingCltv := toNodeDist.incomingCltv +
uint32(timeLockDelta)
// Check that we have cltv limit and that we are within it.
if r.CltvLimit != nil && incomingCltv > *r.CltvLimit {
return
}
// amountToReceive is the amount that the node that is added to
// the distance map needs to receive from a (to be found)
// previous node in the route. That previous node will need to
@@ -622,6 +636,7 @@ func findPath(g *graphParams, r *RestrictParams, source, target Vertex,
node: fromNode,
amountToReceive: amountToReceive,
fee: fee,
incomingCltv: incomingCltv,
}
next[fromVertex] = edge