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

fix: enforce order of payments #2313

Merged
merged 2 commits into from
Mar 12, 2024
Merged

fix: enforce order of payments #2313

merged 2 commits into from
Mar 12, 2024

Conversation

motorina0
Copy link
Collaborator

@motorina0 motorina0 commented Mar 8, 2024

Summary

The comment (now removed) explains the problem:

    # we have to specify the wallet id here, because postgres and sqlite return
    # internal payments in different order and get_standalone_payment otherwise
    # just fetches the first one, causing unpredictable results

The problem is that by specifying the wallet id the order is not enforced if the same wallet is the sender and the receiver.
An explicit ORDER BY has been added to the SQL statement.

@motorina0 motorina0 added this to the 0.12.3 milestone Mar 8, 2024
@motorina0 motorina0 marked this pull request as ready for review March 8, 2024 10:57
Copy link

codecov bot commented Mar 8, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.86%. Comparing base (3e341a3) to head (18a3527).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #2313      +/-   ##
==========================================
- Coverage   58.54%   57.86%   -0.68%     
==========================================
  Files          61       61              
  Lines        9185     9184       -1     
==========================================
- Hits         5377     5314      -63     
- Misses       3808     3870      +62     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -602,6 +602,7 @@ async def get_standalone_payment(
SELECT *
FROM apipayments
WHERE {clause}
ORDER BY amount
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand the logic why sorting by amount is desired and not by some other field (e.g. time comes to my mind).

Copy link
Member

Choose a reason for hiding this comment

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

i think its for internal payments, the one sending is negative the one receiving positive

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The original issue was that the extra field was sometimes not correctly fetched for get payment (/api/v1/payments/${paymenHash}). The extra field contains (among others the webhook status).

The extra field is updated like so on core and withdraw extension:

            await update_payment_extra(
                payment_hash=payment_hash,
                extra={
                    "wh_success": r.is_success,
                    "wh_message": r.reason_phrase,
                    "wh_response": r.text,
                },
                outgoing=True,
            )

Having outgoing=True makes the update on the outgoing (negative) payment.
telegram-cloud-photo-size-4-6006064172485427192-y

However, now I have just noticed that the call from lnurlp extension does not specify outgoing=True.
This is indeed inconsistent (and fragile).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

However, now I have just noticed that the call from lnurlp extension does not specify outgoing=True.
This is indeed inconsistent (and fragile).

  • nvm, lnurlp is not an outgoing payment. Its fine as it is.

Copy link
Member

@dni dni left a comment

Choose a reason for hiding this comment

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

lgtm

@motorina0 motorina0 merged commit 65b8868 into dev Mar 12, 2024
44 checks passed
@motorina0 motorina0 deleted the fix_order_of_payments branch March 12, 2024 13:31
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.

None yet

4 participants