return 'pretend' amount from calc func

This commit is contained in:
Jesse de Wit
2022-12-19 10:48:52 +01:00
parent 1730f04110
commit 3f2cf68a13
4 changed files with 21 additions and 24 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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
}
}

View File

@@ -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.