From 3f2cf68a1320ca24aa92178ef72564a77a8e3f53 Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Mon, 19 Dec 2022 10:48:52 +0100 Subject: [PATCH] return 'pretend' amount from calc func --- itest/bob_offline_test.go | 6 ++---- itest/intercept_zero_conf_test.go | 12 ++++-------- itest/test_common.go | 21 +++++++++++++-------- itest/zero_reserve_test.go | 6 ++---- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/itest/bob_offline_test.go b/itest/bob_offline_test.go index c325f71..bd7d505 100644 --- a/itest/bob_offline_test.go +++ b/itest/bob_offline_test.go @@ -23,7 +23,7 @@ func testFailureBobOffline(p *testParams) { log.Printf("Adding bob's invoices") outerAmountMsat := uint64(2100000) - innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat) + innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat) description := "Please pay me" innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(), generateInvoicesRequest{ @@ -36,15 +36,13 @@ func testFailureBobOffline(p *testParams) { log.Print("Connecting bob to lspd") p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode()) - // NOTE: We pretend to be paying fees to the lsp, but actually we won't. log.Printf("Registering payment with lsp") - pretendAmount := outerAmountMsat - 2000000 RegisterPayment(p.lsp, &lspd.PaymentInformation{ PaymentHash: innerInvoice.paymentHash, PaymentSecret: innerInvoice.paymentSecret, Destination: p.BreezClient().Node().NodeId(), IncomingAmountMsat: int64(outerAmountMsat), - OutgoingAmountMsat: int64(pretendAmount), + OutgoingAmountMsat: int64(lspAmountMsat), }) // Kill the mobile client diff --git a/itest/intercept_zero_conf_test.go b/itest/intercept_zero_conf_test.go index 32435f3..45ba809 100644 --- a/itest/intercept_zero_conf_test.go +++ b/itest/intercept_zero_conf_test.go @@ -25,7 +25,7 @@ func testOpenZeroConfChannelOnReceive(p *testParams) { log.Printf("Adding bob's invoices") outerAmountMsat := uint64(2100000) - innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat) + innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat) description := "Please pay me" innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(), generateInvoicesRequest{ @@ -38,15 +38,13 @@ func testOpenZeroConfChannelOnReceive(p *testParams) { log.Print("Connecting bob to lspd") p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode()) - // NOTE: We pretend to be paying fees to the lsp, but actually we won't. log.Printf("Registering payment with lsp") - pretendAmount := outerAmountMsat - 2000000 RegisterPayment(p.lsp, &lspd.PaymentInformation{ PaymentHash: innerInvoice.paymentHash, PaymentSecret: innerInvoice.paymentSecret, Destination: p.BreezClient().Node().NodeId(), IncomingAmountMsat: int64(outerAmountMsat), - OutgoingAmountMsat: int64(pretendAmount), + OutgoingAmountMsat: int64(lspAmountMsat), }) // TODO: Fix race waiting for htlc interceptor. @@ -80,7 +78,7 @@ func testOpenZeroConfSingleHtlc(p *testParams) { log.Printf("Adding bob's invoices") outerAmountMsat := uint64(2100000) - innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat) + innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat) description := "Please pay me" innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(), generateInvoicesRequest{ @@ -93,15 +91,13 @@ func testOpenZeroConfSingleHtlc(p *testParams) { log.Print("Connecting bob to lspd") p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode()) - // NOTE: We pretend to be paying fees to the lsp, but actually we won't. log.Printf("Registering payment with lsp") - pretendAmount := outerAmountMsat - 2000000 RegisterPayment(p.lsp, &lspd.PaymentInformation{ PaymentHash: innerInvoice.paymentHash, PaymentSecret: innerInvoice.paymentSecret, Destination: p.BreezClient().Node().NodeId(), IncomingAmountMsat: int64(outerAmountMsat), - OutgoingAmountMsat: int64(pretendAmount), + OutgoingAmountMsat: int64(lspAmountMsat), }) // TODO: Fix race waiting for htlc interceptor. diff --git a/itest/test_common.go b/itest/test_common.go index c83b8fe..5f388df 100644 --- a/itest/test_common.go +++ b/itest/test_common.go @@ -26,16 +26,21 @@ func AssertChannelCapacity( assert.Equal(t, ((outerAmountMsat/1000)+100000)*1000, capacityMsat) } -func calculateInnerAmountMsat(lsp LspNode, outerAmountMsat uint64) uint64 { - if lsp.SupportsChargingFees() { - fee := outerAmountMsat * 40 / 10_000 / 1_000 * 1_000 - if fee < 2000000 { - fee = 2000000 - } +func calculateInnerAmountMsat(lsp LspNode, outerAmountMsat uint64) (uint64, uint64) { + fee := outerAmountMsat * 40 / 10_000 / 1_000 * 1_000 + if fee < 2000000 { + fee = 2000000 + } - return outerAmountMsat - fee + inner := outerAmountMsat - fee + + // NOTE: If the LSP does not support charging fees (the CLN version doesn't) + // We have to pretend in the registerpayment call that the LSP WILL charge + // fees. If we update the CLN lsp to charge fees, this check can be removed. + if lsp.SupportsChargingFees() { + return inner, inner } else { - return outerAmountMsat + return outerAmountMsat, inner } } diff --git a/itest/zero_reserve_test.go b/itest/zero_reserve_test.go index f9f7486..8dd4fdf 100644 --- a/itest/zero_reserve_test.go +++ b/itest/zero_reserve_test.go @@ -23,7 +23,7 @@ func testZeroReserve(p *testParams) { log.Printf("Adding bob's invoices") outerAmountMsat := uint64(2100000) - innerAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat) + innerAmountMsat, lspAmountMsat := calculateInnerAmountMsat(p.lsp, outerAmountMsat) description := "Please pay me" innerInvoice, outerInvoice := GenerateInvoices(p.BreezClient(), generateInvoicesRequest{ @@ -36,15 +36,13 @@ func testZeroReserve(p *testParams) { log.Print("Connecting bob to lspd") p.BreezClient().Node().ConnectPeer(p.lsp.LightningNode()) - // NOTE: We pretend to be paying fees to the lsp, but actually we won't. log.Printf("Registering payment with lsp") - pretendAmount := outerAmountMsat - 2000000 RegisterPayment(p.lsp, &lspd.PaymentInformation{ PaymentHash: innerInvoice.paymentHash, PaymentSecret: innerInvoice.paymentSecret, Destination: p.BreezClient().Node().NodeId(), IncomingAmountMsat: int64(outerAmountMsat), - OutgoingAmountMsat: int64(pretendAmount), + OutgoingAmountMsat: int64(lspAmountMsat), }) // TODO: Fix race waiting for htlc interceptor.