From e71151f56a2e1749557f5cab908eeda1c577ceb6 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Mon, 17 Dec 2018 15:23:36 -0500 Subject: [PATCH] htlcswitch/link: return FinalFailExpiryTooSoon for last htlc In this commit, we fix a minor discrepancy with the spec. We should return a FinalFailExpiryTooSoon error, rather than a FinalFailIncorrectCltvExpiry error, when the last HTLC of a route (exit hop) has an expiration height that is deemed too soon by the final destination of the HTLC. --- htlcswitch/link.go | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 9bda1e65..ba62cc0f 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -2398,19 +2398,16 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg, // computed correctly. expectedHeight := heightNow + minCltvDelta switch { + case !l.cfg.DebugHTLC && pd.Timeout < expectedHeight: + log.Errorf("Incoming htlc(%x) has an "+ + "expiration that is too soon: "+ + "expected at least %v, got %v", + pd.RHash[:], expectedHeight, pd.Timeout) - case !l.cfg.DebugHTLC && fwdInfo.OutgoingCTLV < expectedHeight: - log.Errorf("Onion payload of incoming "+ - "htlc(%x) has incorrect time-lock: "+ - "expected %v, got %v", - pd.RHash[:], expectedHeight, - fwdInfo.OutgoingCTLV) - - failure := lnwire.NewFinalIncorrectCltvExpiry( - fwdInfo.OutgoingCTLV, - ) + failure := lnwire.FailFinalExpiryTooSoon{} l.sendHTLCError( - pd.HtlcIndex, failure, obfuscator, pd.SourceRef, + pd.HtlcIndex, failure, obfuscator, + pd.SourceRef, ) needUpdate = true