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

Check quote expiry in outgoing payment worker #3141

Open
1 task
mkurapov opened this issue Nov 28, 2024 · 6 comments
Open
1 task

Check quote expiry in outgoing payment worker #3141

mkurapov opened this issue Nov 28, 2024 · 6 comments
Labels
pkg: backend Changes in the backend package. type: bug Something isn't working

Comments

@mkurapov
Copy link
Contributor

mkurapov commented Nov 28, 2024

Context

Currently, we check the expiresAt of the quote during outgoing payment creation. If it is valid, we create the outgoing payment, store it in the DB.

Once the payment is funded, the outgoing payments worker starts processing the payment, whether that is local or over ILP. If the payment fails, it will stay in the SENDING state and the worker will keep retrying it (up to some maximum number of times).

In the worker, however, we do not check the expiry of the quote. The quote could expire between the time when we created the payment, and when it is being processed (or retried) in the worker. We should prevent processing an outgoing payment for an expired quote. (good spot would be in lifecycle.ts > handleSending)

Todos

  • Prevent outgoing payment being processed for expired quotes (mark it as FAILED). Make sure the outgoing_payment.failed webhook is correctly sent.
@mkurapov mkurapov added type: bug Something isn't working pkg: backend Changes in the backend package. labels Nov 28, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Rafiki Nov 28, 2024
@CollinsMunene
Copy link

CollinsMunene commented Dec 3, 2024

Hi @mkurapov , I have made a change where if the quote expiresAt time is the same as the current time, then it handles the payment failure. Is this the desired effect?

@mkurapov
Copy link
Contributor Author

mkurapov commented Dec 4, 2024

@CollinsMunene yes 👍

and to confirm, outgoing payment should not be retried.

@CollinsMunene
Copy link

CollinsMunene commented Dec 4, 2024

@mkurapov that's noted, so here is the implementation attached,
The payment is only retried if the payment state is "SENDING", so by throwing the PaymentFailed event, it changes the payment state to FAILED as well as sends the outgoing_payment.failed webhook.

Kindly confirm if this is okay.
The implementation on(lifecycle.ts > handleSending function):
implementation

The Webhook:
payment_state

The outgoing payment body after:
webhook

@CollinsMunene
Copy link

CollinsMunene commented Dec 5, 2024

Hi @mkurapov, I also noticed on the webhooks, can we also add an error description. For example, when the outgoing_payment.failed is raised when the quote expiry time has reached. The webhook does not really say why it has failed. It would be nice to see a reason like "quote has expired"

or even in any other instance of failure, makes it easy to debug. So same thing as the payment, we can have metadata for webhooks

@mkurapov
Copy link
Contributor Author

Hi @CollinsMunene,

The webhook does not really say why it has failed. It would be nice to see a reason like "quote has expired"

Yes, agreed with this, would be much more helpful. I think by adding a new enum value to LifecycleError (something like QuoteExpired), and throw that when the quote expiry check happens, we should be able to see that in the webhook event data.

@CollinsMunene
Copy link

Hi @mkurapov , exactly my point. I have pushed this changes under PR (#3173)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. type: bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants