From 6e051a80ffb1534ef883b32025bbcdc975e4ad0f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 25 Jun 2018 20:12:07 -0700 Subject: [PATCH] htlcswitch: fix bug in generateHops, use CLTV delta of prior hop to compute payload In this commit, we fix a bug in the generateHops helper function. Before this commit, it erroneously used the CLTV delta of the current hop, rather than that of the prior hop when computing the payload. This was incorrect, as when computing the timelock for the incoming hop, we need to factor in the CTLV delta of the outgoing lock, not the incoming lock. --- htlcswitch/test_utils.go | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/htlcswitch/test_utils.go b/htlcswitch/test_utils.go index 505b87c7e..8da96ece5 100644 --- a/htlcswitch/test_utils.go +++ b/htlcswitch/test_utils.go @@ -601,15 +601,17 @@ func generateHops(payAmt lnwire.MilliSatoshi, startingHeight uint32, nextHop = path[i+1].channel.ShortChanID() } + var timeLock uint32 // If this is the last, hop, then the time lock will be their // specified delta policy plus our starting height. - totalTimelock += lastHop.cfg.FwrdingPolicy.TimeLockDelta - timeLock := totalTimelock - - // Otherwise, the outgoing time lock should be the incoming - // timelock minus their specified delta. - if i != len(path)-1 { - delta := path[i].cfg.FwrdingPolicy.TimeLockDelta + if i == len(path)-1 { + totalTimelock += lastHop.cfg.FwrdingPolicy.TimeLockDelta + timeLock = totalTimelock + } else { + // Otherwise, the outgoing time lock should be the + // incoming timelock minus their specified delta. + delta := path[i+1].cfg.FwrdingPolicy.TimeLockDelta + totalTimelock += delta timeLock = totalTimelock - delta }