-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[Part 3b|*] Implement Third Part for SQL Backend functions #10368
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
base: elle-payment-sql-series-new
Are you sure you want to change the base?
[Part 3b|*] Implement Third Part for SQL Backend functions #10368
Conversation
Previously a one(intent)-to-many(payment) relationship it is now changed to a one-to-one relationship because a payment request only can have 1 payment related to it. Looking into the future with BOLT12 offers, the fetched invoice from the offer could be stored here as well and the relationship would still hold.
In this commit we add all queries which we will need to insert payment related data into the db.
cb9cde9 to
072544e
Compare
We wrap the fetchPayment db call and catch the case where no errors are found in the db, where we now return the ErrPaymentNotInitiated error.
072544e to
31e548f
Compare
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request implements the third and final part of the payments SQL backend functions, focusing on payment control and write operations. The changes are extensive and well-executed, including the implementation of functions for initializing, registering, settling, failing, and deleting payments. The database schema has been improved to better model the relationship between payments and payment intents, and performance is enhanced through efficient batching and lightweight queries.
I have two minor suggestions: one to fix a broken link and improve wording in the release notes, and another to address a style guide violation regarding spacing in a switch statement. Overall, this is a solid contribution to the SQL backend migration.
| * Implement third(final) Part of SQL backend [payment functions] | ||
| (https://github.com/lightningnetwork/lnd/pull/10368) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The release note entry has a broken link due to a newline, and the wording could be more descriptive and consistent with other entries in this section.
| * Implement third(final) Part of SQL backend [payment functions] | |
| (https://github.com/lightningnetwork/lnd/pull/10368) | |
| * Implement payment control functions for the [payments db SQL Backend](https://github.com/lightningnetwork/lnd/pull/10368) |
| switch { | ||
| case err == nil: | ||
| paymentStatus, err := s.computePaymentStatusFromDB( | ||
| ctx, db, existingPayment, | ||
| ) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to compute payment "+ | ||
| "status: %w", err) | ||
| } | ||
|
|
||
| // Check if the payment is initializable otherwise | ||
| // we'll return early. | ||
| if err := paymentStatus.initializable(); err != nil { | ||
| return fmt.Errorf("payment is not "+ | ||
| "initializable: %w", err) | ||
| } | ||
|
|
||
| // If the initializable check above passes, then the | ||
| // existing payment has failed. So we delete it and | ||
| // all of its previous artifacts. We rely on | ||
| // cascading deletes to clean up the rest. | ||
| err = db.DeletePayment(ctx, existingPayment.Payment.ID) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to delete "+ | ||
| "payment: %w", err) | ||
| } | ||
|
|
||
| case !errors.Is(err, sql.ErrNoRows): | ||
| // Some other error occurred | ||
| return fmt.Errorf("failed to check existing "+ | ||
| "payment: %w", err) | ||
|
|
||
| // The payment does not yet exist. | ||
| default: | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The switch statement in the InitPayment function is missing blank lines between case blocks, which is required by the repository style guide for code spacing. Adding blank lines and descriptive comments for each case will improve readability and adhere to the style guide.1
switch {
// A payment with this hash already exists. We need to check its
// status to see if we can re-initialize.
case err == nil:
paymentStatus, err := s.computePaymentStatusFromDB(
ctx, db, existingPayment,
)
if err != nil {
return fmt.Errorf("failed to compute payment "+
"status: %w", err)
}
// Check if the payment is initializable otherwise
// we'll return early.
if err := paymentStatus.initializable(); err != nil {
return fmt.Errorf("payment is not "+
"initializable: %w", err)
}
// If the initializable check above passes, then the
// existing payment has failed. So we delete it and
// all of its previous artifacts. We rely on
// cascading deletes to clean up the rest.
err = db.DeletePayment(ctx, existingPayment.Payment.ID)
if err != nil {
return fmt.Errorf("failed to delete "+
"payment: %w", err)
}
// An unexpected error occurred while fetching the payment.
case !errors.Is(err, sql.ErrNoRows):
return fmt.Errorf("failed to check existing "+
"payment: %w", err)
// The payment does not yet exist, so we can proceed.
default:
}Style Guide References
Footnotes
-
The style guide requires spacing between
casestanzas in aswitchstatement for better readability. ↩
Implements the Third and Final Part of Payments SQL backend functions. Follows after
#10291