Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for service fees #474

Merged
merged 22 commits into from
Jan 13, 2024
Merged

Add support for service fees #474

merged 22 commits into from
Jan 13, 2024

Conversation

bumi
Copy link
Contributor

@bumi bumi commented Dec 29, 2023

This introduces a new transaction type "service_fee".
Each outgoing payment is charged a service fee of x/1000. The service fee entries is added with the routing fee reserve entry. For failed payments the service fee is reversed.

A threshold up to which transactions are free can be configured (NO_SERVICE_FEE_UP_TO_AMOUNT)

This introduces a new transaction type "service_fee"
Each outgoing payment is charged a service fee of x/1000.
The service fee entries is added with the routing fee reserve entry.
For failed payments the service fee is reversed.
@bumi bumi marked this pull request as draft December 29, 2023 08:14
@bumi bumi marked this pull request as ready for review December 29, 2023 18:27
@bumi bumi requested a review from reneaaron December 29, 2023 18:28
@bumi bumi changed the title [WIP] Add support for service fees Add support for service fees Dec 29, 2023
Copy link
Contributor

@reneaaron reneaaron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great progress! 💯

Left some feedback and added a fix / test.

db/models/invoice.go Show resolved Hide resolved
integration_tests/keysend_test.go Show resolved Hide resolved
integration_tests/payment_failure_test.go Show resolved Hide resolved
integration_tests/util.go Show resolved Hide resolved
lib/service/invoices.go Show resolved Hide resolved
lib/service/invoices.go Outdated Show resolved Hide resolved
lib/service/invoices.go Outdated Show resolved Hide resolved
lib/service/invoices_test.go Show resolved Hide resolved
@bumi
Copy link
Contributor Author

bumi commented Dec 30, 2023 via email

we already do exactly that when in the normal PayInvoice flow.
Normally the RHash is already set here, but I guess it does not hurt to have
it consistent everywhere.
…harged

It feels a bit indirect to check if we have set a FeeReserve.
We save the routing fee on the invoice thus we should be able to use that information
@@ -359,22 +385,35 @@ func (svc *LndhubService) RevertFeeReserve(ctx context.Context, entry *models.Tr
return nil
}

func (svc *LndhubService) AddFeeEntry(ctx context.Context, entry *models.TransactionEntry, invoice *models.Invoice, tx bun.Tx) (err error) {
if entry.FeeReserve != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kiwiidb why did we check for entry.FeeReserve here? can't we check for invoice.Fee (new name invoice.RoutingFee) here?
If the invoice has a not zero routing fee we have to add a fee transaction entry.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it can also work but the way how it used to be it's more explicit in avoiding the nil pointer exception.

@reneaaron reneaaron merged commit 8deabc5 into main Jan 13, 2024
3 checks passed
@reneaaron reneaaron deleted the service-fees branch January 13, 2024 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants