routing: hop-payload for last hop should be the absolute timeout, not delta
This commit fixes an oversight in the path finding code when converting a path into a route. Currently, for the last hop, we’d emplace the expiry delta of the last hop within the per-hop payload. This was left over from a prior version of the specification. To fix this, we’ll now emplace the _absolute_ final HTLC expiry with the payload, such that, the final hop that verify that the HTLC has not been tampered with in flight.
This commit is contained in:
parent
f32a7a28ab
commit
b07e7fb7cc
@ -274,10 +274,10 @@ func newRoute(amtToSend lnwire.MilliSatoshi, pathEdges []*ChannelHop,
|
|||||||
route.TotalTimeLock += uint32(edge.TimeLockDelta)
|
route.TotalTimeLock += uint32(edge.TimeLockDelta)
|
||||||
|
|
||||||
// If this is the last hop, then for verification purposes, the
|
// If this is the last hop, then for verification purposes, the
|
||||||
// value of the outgoing time-lock should be _exactly_ the time
|
// value of the outgoing time-lock should be _exactly_ the
|
||||||
// lock delta specified within the routing information.
|
// absolute time out they'd expect in the HTLC.
|
||||||
if i == len(pathEdges)-1 {
|
if i == len(pathEdges)-1 {
|
||||||
nextHop.OutgoingTimeLock = uint32(edge.TimeLockDelta)
|
nextHop.OutgoingTimeLock = currentHeight + uint32(edge.TimeLockDelta)
|
||||||
} else {
|
} else {
|
||||||
// Otherwise, the value of the outgoing time-lock will
|
// Otherwise, the value of the outgoing time-lock will
|
||||||
// be the value of the time-lock for the _outgoing_
|
// be the value of the time-lock for the _outgoing_
|
||||||
|
@ -382,7 +382,7 @@ func TestBasicGraphPathFinding(t *testing.T) {
|
|||||||
t.Fatalf("expected outgoing time-lock of %v, instead have %v",
|
t.Fatalf("expected outgoing time-lock of %v, instead have %v",
|
||||||
1, route.Hops[0].OutgoingTimeLock)
|
1, route.Hops[0].OutgoingTimeLock)
|
||||||
}
|
}
|
||||||
if route.Hops[1].OutgoingTimeLock != 1 {
|
if route.Hops[1].OutgoingTimeLock != 101 {
|
||||||
t.Fatalf("outgoing time-lock for final hop is incorrect: "+
|
t.Fatalf("outgoing time-lock for final hop is incorrect: "+
|
||||||
"expected %v, got %v", 1, route.Hops[1].OutgoingTimeLock)
|
"expected %v, got %v", 1, route.Hops[1].OutgoingTimeLock)
|
||||||
}
|
}
|
||||||
|
@ -1002,6 +1002,7 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte, *Route
|
|||||||
// payment amount. If no such routes can be found then an error will be
|
// payment amount. If no such routes can be found then an error will be
|
||||||
// returned.
|
// returned.
|
||||||
if !ok {
|
if !ok {
|
||||||
|
// TODO(roasbeef): put cache handling into FindRoutes
|
||||||
freshRoutes, err := r.FindRoutes(payment.Target, payment.Amount)
|
freshRoutes, err := r.FindRoutes(payment.Target, payment.Amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return preImage, nil, err
|
return preImage, nil, err
|
||||||
|
Loading…
Reference in New Issue
Block a user