From 982a09ac60e1451ff91496e509124f6a4bc3eab2 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 27 Jul 2018 15:49:30 -0700 Subject: [PATCH 1/2] htlcswitch/link_test: check for FailFinalExpiryTooSoon --- htlcswitch/link_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/htlcswitch/link_test.go b/htlcswitch/link_test.go index c7f1d3ae..c518e78c 100644 --- a/htlcswitch/link_test.go +++ b/htlcswitch/link_test.go @@ -15,6 +15,10 @@ import ( "testing" "time" + "github.com/btcsuite/btcd/btcec" + "github.com/btcsuite/btcd/chaincfg/chainhash" + "github.com/btcsuite/btcd/wire" + "github.com/btcsuite/btcutil" "github.com/coreos/bbolt" "github.com/davecgh/go-spew/spew" "github.com/go-errors/errors" @@ -24,10 +28,6 @@ import ( "github.com/lightningnetwork/lnd/lnpeer" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" - "github.com/btcsuite/btcd/btcec" - "github.com/btcsuite/btcd/chaincfg/chainhash" - "github.com/btcsuite/btcd/wire" - "github.com/btcsuite/btcutil" ) const ( @@ -1247,7 +1247,7 @@ func TestChannelLinkExpiryTooSoonExitNode(t *testing.T) { } switch ferr.FailureMessage.(type) { - case *lnwire.FailFinalIncorrectCltvExpiry: + case *lnwire.FailFinalExpiryTooSoon: default: t.Fatalf("incorrect error, expected final time lock too "+ "early, instead have: %v", err) From d76bacee0e99ef58b57871310e278ff4049b47a8 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Fri, 27 Jul 2018 15:46:54 -0700 Subject: [PATCH 2/2] htlcswitch/link: send FailFinalExpiryTooSoon from exit hop This commit corrects our exit hop logic to return FailFinalExpiryTooSoon if the following check is true: pd.Timeout-expiryGraceDelta <= heightNow Previously we returned FailFinalIncorrectCltvExpiry, which should only be returned if the packet was misconstructed. --- htlcswitch/link.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index 8c487bfb..22de510e 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -9,6 +9,7 @@ import ( "sync/atomic" "time" + "github.com/btcsuite/btcd/chaincfg/chainhash" "github.com/davecgh/go-spew/spew" "github.com/go-errors/errors" "github.com/lightningnetwork/lnd/channeldb" @@ -17,7 +18,6 @@ import ( "github.com/lightningnetwork/lnd/lnpeer" "github.com/lightningnetwork/lnd/lnwallet" "github.com/lightningnetwork/lnd/lnwire" - "github.com/btcsuite/btcd/chaincfg/chainhash" ) func init() { @@ -2155,7 +2155,7 @@ func (l *channelLink) processRemoteAdds(fwdPkg *channeldb.FwdPkg, "soon: expiry=%v, best_height=%v", pd.RHash[:], pd.Timeout, heightNow) - failure := lnwire.FailFinalIncorrectCltvExpiry{} + failure := lnwire.FailFinalExpiryTooSoon{} l.sendHTLCError( pd.HtlcIndex, &failure, obfuscator, pd.SourceRef, )