From 833c79e27ffbde2e7fe787f078600a67b9f3f583 Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Fri, 19 Jan 2024 16:19:04 +0100 Subject: [PATCH] fix the lsps2 cltv delta check It was wrongly assumed that the lsp had to enforce a cltv delta +2. It is actually the recipient creating invoices with a cltv delta +2, but the LSP does not have anything to do with that. --- .github/workflows/integration_tests.yaml | 1 - itest/lspd_test.go | 5 -- itest/lsps2_cltv_test.go | 66 ------------------------ lsps2/intercept_handler.go | 4 +- lsps2/intercept_test.go | 8 +-- 5 files changed, 6 insertions(+), 78 deletions(-) delete mode 100644 itest/lsps2_cltv_test.go diff --git a/.github/workflows/integration_tests.yaml b/.github/workflows/integration_tests.yaml index 999e43a1..5dc73531 100644 --- a/.github/workflows/integration_tests.yaml +++ b/.github/workflows/integration_tests.yaml @@ -153,7 +153,6 @@ jobs: testLsps2GetInfo, testLsps2Buy, testLsps2HappyFlow, - testLsps2Cltv, testLsps2NoBalance, testLsps2ZeroConfUtxo ] diff --git a/itest/lspd_test.go b/itest/lspd_test.go index 87bf0040..34517dc2 100644 --- a/itest/lspd_test.go +++ b/itest/lspd_test.go @@ -210,11 +210,6 @@ var allTestCases = []*testCase{ test: testLsps2HappyFlow, isLsps2: true, }, - { - name: "testLsps2Cltv", - test: testLsps2Cltv, - isLsps2: true, - }, { name: "testLsps2NoBalance", test: testLsps2NoBalance, diff --git a/itest/lsps2_cltv_test.go b/itest/lsps2_cltv_test.go deleted file mode 100644 index 03ab5b85..00000000 --- a/itest/lsps2_cltv_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package itest - -import ( - "log" - "time" - - "github.com/breez/lntest" - "github.com/breez/lspd/lsps2" - "github.com/stretchr/testify/assert" -) - -func testLsps2Cltv(p *testParams) { - alice := lntest.NewClnNode(p.h, p.m, "Alice") - alice.Start() - alice.Fund(10000000) - p.lsp.LightningNode().Fund(10000000) - - log.Print("Opening channel between Alice and the lsp") - channel := alice.OpenChannel(p.lsp.LightningNode(), &lntest.OpenChannelOptions{ - AmountSat: publicChanAmount, - }) - aliceLspScid := alice.WaitForChannelReady(channel) - - log.Print("Connecting bob to lspd") - p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode()) - - // Make sure everything is activated. - <-time.After(htlcInterceptorDelay) - - log.Printf("Calling lsps2.get_info") - info := Lsps2GetInfo(p.BreezClient(), p.Lsp(), lsps2.GetInfoRequest{ - Token: &WorkingToken, - }) - - outerAmountMsat := uint64(2100000) - innerAmountMsat := lsps2CalculateInnerAmountMsat(p.lsp, outerAmountMsat, info.OpeningFeeParamsMenu[0]) - p.BreezClient().SetHtlcAcceptor(innerAmountMsat) - - log.Printf("Calling lsps2.buy") - buyResp := Lsps2Buy(p.BreezClient(), p.Lsp(), lsps2.BuyRequest{ - OpeningFeeParams: *info.OpeningFeeParamsMenu[0], - PaymentSizeMsat: &outerAmountMsat, - }) - - log.Printf("Adding bob's invoices") - description := "Please pay me" - _, outerInvoice := GenerateLsps2Invoices(p.BreezClient(), - generateInvoicesRequest{ - innerAmountMsat: innerAmountMsat, - outerAmountMsat: outerAmountMsat, - description: description, - lsp: p.lsp, - }, - buyResp.JitChannelScid) - - // TODO: Fix race waiting for htlc interceptor. - log.Printf("Waiting %v to allow htlc interceptor to activate.", htlcInterceptorDelay) - <-time.After(htlcInterceptorDelay) - log.Printf("Alice paying") - route := constructRoute(p.Lsp().LightningNode(), p.BreezClient().Node(), aliceLspScid, lntest.NewShortChanIDFromString(buyResp.JitChannelScid), outerAmountMsat) - - // Increment the delay by one (should be incremented by 2), so the cltv delta is too little. - route.Hops[0].Delay++ - _, err := alice.PayViaRoute(outerAmountMsat, outerInvoice.paymentHash, outerInvoice.paymentSecret, route) - assert.Contains(p.t, err.Error(), "WIRE_INCORRECT_CLTV_EXPIRY") -} diff --git a/lsps2/intercept_handler.go b/lsps2/intercept_handler.go index 4a83cf5e..68433978 100644 --- a/lsps2/intercept_handler.go +++ b/lsps2/intercept_handler.go @@ -278,9 +278,9 @@ func (i *Interceptor) processPart(payment *paymentState, part *partState) { } } - // Make sure the cltv delta is enough (actual cltv delta + 2). + // Make sure the cltv delta is enough. if int64(part.req.IncomingExpiry)-int64(part.req.OutgoingExpiry) < - int64(i.config.TimeLockDelta)+2 { + int64(i.config.TimeLockDelta) { i.failPart(payment, part, common.FAILURE_INCORRECT_CLTV_EXPIRY) return } diff --git a/lsps2/intercept_test.go b/lsps2/intercept_test.go index 4f136193..85ad694c 100644 --- a/lsps2/intercept_test.go +++ b/lsps2/intercept_test.go @@ -314,13 +314,13 @@ func Test_NoMpp_AmtAboveMaximum(t *testing.T) { } // Asserts that a no-MPP+var-invoice mode payment fails when the cltv delta is -// less than cltv delta + 2. +// less than cltv delta. func Test_NoMpp_CltvDeltaBelowMinimum(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() i := setupInterceptor(ctx, nil) - res := i.Intercept(createPart(&part{cltvDelta: 145})) + res := i.Intercept(createPart(&part{cltvDelta: 143})) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.FAILURE_INCORRECT_CLTV_EXPIRY, res.FailureCode) assertEmpty(t, i) @@ -533,13 +533,13 @@ func Test_Mpp_BadSecondPart_ThirdPartCompletes(t *testing.T) { } // Asserts that a MPP+fixed-invoice mode payment fails when the cltv delta is -// less than cltv delta + 2. +// less than cltv delta. func Test_Mpp_CltvDeltaBelowMinimum(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) defer cancel() i := setupInterceptor(ctx, &interceptP{store: mppStore()}) - res := i.Intercept(createPart(&part{cltvDelta: 145})) + res := i.Intercept(createPart(&part{cltvDelta: 143})) assert.Equal(t, common.INTERCEPT_FAIL_HTLC_WITH_CODE, res.Action) assert.Equal(t, common.FAILURE_INCORRECT_CLTV_EXPIRY, res.FailureCode) assertEmpty(t, i)