Skip to content

Comments

add DeletePayment that allows to delete a specific payment or its failed HTLCs#5660

Merged
guggero merged 4 commits intolightningnetwork:masterfrom
LN-Zap:upstream/feat/delete-payment
Sep 13, 2021
Merged

add DeletePayment that allows to delete a specific payment or its failed HTLCs#5660
guggero merged 4 commits intolightningnetwork:masterfrom
LN-Zap:upstream/feat/delete-payment

Conversation

@bjarnemagnussen
Copy link
Contributor

Description

This PR adds a RPC DeletePayment that allows to delete a payment by specifying its payment hash. It also has the option to only delete failed HTLCs of a payment by setting the failed_htlcs_only option.

Similar to DeleteAllPayments payments that have status InFlight are not touched as they cannot be removed safely. Instead an error is returned.

@guggero guggero self-requested a review August 24, 2021 12:10
@guggero guggero added payments Related to invoices/payments rpc Related to the RPC interface labels Aug 24, 2021
@bjarnemagnussen bjarnemagnussen force-pushed the upstream/feat/delete-payment branch 2 times, most recently from e85a7f5 to 83f2162 Compare August 24, 2021 12:28
@bjarnemagnussen
Copy link
Contributor Author

I am not sure of the linting error. It seems to make a wrong suggestion?

@guggero
Copy link
Collaborator

guggero commented Aug 24, 2021

I am not sure of the linting error. It seems to make a wrong suggestion?

Yeah, that's a bit annoying. You need to add the // nolint:interfacer comment to get rid of the suggestion.

@bjarnemagnussen bjarnemagnussen force-pushed the upstream/feat/delete-payment branch from 83f2162 to 1ffeaba Compare August 24, 2021 13:12
@Roasbeef Roasbeef added the P3 might get fixed, nice to have label Aug 31, 2021
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Great PR and very useful feature, thank you very much!
Looks pretty good to me, mostly nits or test related suggestions.

Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: use require library for new code, here and below.

@carlaKC carlaKC self-requested a review September 7, 2021 09:13
@bjarnemagnussen bjarnemagnussen force-pushed the upstream/feat/delete-payment branch from 1ffeaba to 561d868 Compare September 7, 2021 09:14
@orijbot
Copy link

orijbot commented Sep 7, 2021

@bjarnemagnussen
Copy link
Contributor Author

Thanks @guggero for your review! I have squashed in the requested changes. Please let me know if there is anything else, or if I didn't fully address your issues.

@bjarnemagnussen bjarnemagnussen force-pushed the upstream/feat/delete-payment branch from 561d868 to ac78beb Compare September 7, 2021 09:18
Copy link
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

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

tACK, LGTM 🎉

Copy link
Collaborator

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! Really useful feature :)

Just some nits from me.

Copy link
Collaborator

Choose a reason for hiding this comment

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

s/attmpet/attempt

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could this be a helper function rather than a closure? It could also just return a bool indicating whether the payment was found then we require.True(t, found)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to be sure, do you prefer the function assertPayments to live outside together with some of the other assert helper function, and take the payments structure directly as argument instead of the indices (which could be of type []*MPPayment instead)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, was thinking a separate function rather than inlining it, can still use indexes:

func assertPaymentsPresent(t * testing.T, [] payment) {
    dbPayments, err := db.FetchPayments()
    ...
}

Just cuts the need for the Outer loop, and can potentially be reused one day.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have refactored the testing by creating a helper function assertPayments and also a helper function createTestPayments that registers those payments and populates the data into the payments slice: 1e613b6bbcf9d8b19c0a5a8d7e3a725486296242

Since these function can also directly be used the the test case for DeleteAllPayments (from which I took a lot of inspiration for the testing code!), I also refactored it to make use of the helper functions.

I did create its own commit without squashing for easier code review. Please let me know if there is something you feel is missing or you have another idea for. Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

very nice! Thanks for taking the time on this :D Makes for very nice, readable tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool! I will then squash it and also address your nits!

Copy link
Collaborator

Choose a reason for hiding this comment

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

extra-credit: make a note that you can't delete in-flight payments?

@bjarnemagnussen bjarnemagnussen force-pushed the upstream/feat/delete-payment branch from 1e613b6 to aa1392b Compare September 13, 2021 09:34
@bjarnemagnussen
Copy link
Contributor Author

I have force-pushed the new changes and hope to have addressed all issues.

@guggero
Copy link
Collaborator

guggero commented Sep 13, 2021

Thanks for the updates, @bjarnemagnussen! The unit tests seem to fail now. But everything else looks good, so we can merge once that's fixed.

Adds `DeletePayment` to the channeldb, which allows to delete a single payment. If only failed HTLCs for this payment should be deleted it can be specified by the bool `failedHtlcsOnly`.
The RPC DeletePayment allows deleteing  single payment from its ID. When calling with `FailedHtlcsOnly` set in the request only failed HTLCs of this payment will be deleted.
@bjarnemagnussen bjarnemagnussen force-pushed the upstream/feat/delete-payment branch from aa1392b to 91c3fb5 Compare September 13, 2021 10:51
@bjarnemagnussen
Copy link
Contributor Author

Oh, I see what happened! PR #5635 changed the DB structure and I didn't rebase when running the unit tests locally. I have made the changes with the new db structure and it passes now.

@guggero
Copy link
Collaborator

guggero commented Sep 13, 2021

Thanks for the fix. The remaining kvdb unit test seems to have been introduced by another recently merged PR, going to fix asap.

@guggero guggero merged commit 45343e4 into lightningnetwork:master Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 might get fixed, nice to have payments Related to invoices/payments rpc Related to the RPC interface

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants