-
Notifications
You must be signed in to change notification settings - Fork 102
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
subscribeToInvoice() call forget invoices after nodejs restarts #132
Comments
I've been trying to figure this out. There are some things that I couldn't understand:
|
This is the order workflow order type=buy Order published (PENDING) -> taken (WAITING_PAYMENT) -> bot ask buyer invoice (WAITING_BUYER_INVOICE) -> ACTIVE -> /fiatsent (FIAT_SENT) -> /release (PAID_HOLD_INVOICE) -> after buyer's invoice paid (SUCCESS) order type=sell Order published (PENDING) -> taken (WAITING_BUYER_INVOICE) -> bot ask seller to pay invoice (WAITING_PAYMENT) -> ACTIVE -> /fiatsent (FIAT_SENT) -> /release (PAID_HOLD_INVOICE) -> after buyer's invoice paid (SUCCESS) On The issue is that I don't know how to persist that event if nodejs crash for any reason, we can save it on database and delete it after the seller release the payment but that implies that we need to change our logic on |
I was thinking that the we-can re subscribe to the invoice when executing the On WDYT? |
That's sounds great! I think we should check that re-subscribe and tie again the process doesn't get some unexpected errors, but the idea is simple and what I was looking for, great idea 🥇 |
Good! I will start testing by my own. |
I thought about this, the key is re-subscribe, I think the easiest way of doing it is:
Before push this to production we need to test we can test it each separately. |
I've reproduced the behavior detailed above in this branch. I had to create a new function for lightning service and change some things in the files related to the server main process to make it work properly. I've tested it in the following cases:
Info: In both cases the path followed by the code is: Drawback: The messages re sent didn't give any clue to the user about what was happening or if something gone wrong with their orders. A message explaining the situation could be helpful. Caveat: The parameter const unconfirmedInvoices = (await getInvoices({ lnd, is_unconfirmed: true })).invoices;
const confirmedInvoices = (await getInvoices({ lnd, is_unconfirmed: false })).invoices;
console.log(JSON.stringify(confirmedInvoices)==JSON.stringify(unconfirmedInvoices)); |
Great job!! I just tested and made some small fixes, here is the patch, apply it and try again
|
I've just tested it. It works perfectly. For the sake of completeness I updated my test cases results:
I will open a PR with the changes. |
If nodejs restarts at the time an invoice is held
Node loses tracking of this event and when releasing, if the invoice is paid, but the subscribeToInvoice does not follow the normal workflow, the status is not changed to
PAID_HOLD_INVOICE
and as a consequence the buyer is not paid.We need to think a way of avoid this situation, one is never restart nodejs if at least one invoice is held, but we need to have a procedure to follow if the server crashes.
The text was updated successfully, but these errors were encountered: