- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.2k
[Part 2|*] Implement First Part for SQL Backend functions #10287
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 2|*] Implement First Part for SQL Backend functions #10287
Conversation
fe51267    to
    63aa866      
    Compare
  
    938443e    to
    b0361a2      
    Compare
  
    b0361a2    to
    ed283fa      
    Compare
  
    ed283fa    to
    aa560da      
    Compare
  
    aa560da    to
    08464ea      
    Compare
  
    08464ea    to
    da3603e      
    Compare
  
    da3603e    to
    069f7c6      
    Compare
  
    1f7d395    to
    ef6ef5c      
    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 QueryPayments and FetchPayment functions for the new SQL backend of the payments database. The changes include new SQL queries, Go functions to execute them, and converters to transform database results into application-level types.
The implementation is well-structured, making good use of batching for efficient data fetching. I have a few suggestions to improve code clarity and adhere to best practices:
- Simplify time value handling in sql_converters.goby using direct type assertions where the type is guaranteed.
- Consider updating the DBinterface to accept acontext.ContextinFetchPaymentto avoid usingcontext.TODO().
- I also found a minor typo in a comment.
Overall, this is a solid contribution towards the SQL backend migration.
ef6ef5c    to
    0849296      
    Compare
  
    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.
lgtm!
| }, func() { | ||
| }) | 
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.
sqldb.NoOpReset
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.
Not addressed
|  | ||
| // fetchHTLCAttemptsForPayment fetches all HTLC attempts for a payment and | ||
| // uses ExecuteBatchQuery to efficiently fetch hops and custom records. | ||
| func (s *SQLStore) fetchHTLCAttemptsForPayment(ctx context.Context, | 
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.
ah, you can probably come back to this at the performance improvement stage like i did for graph stuff, but i think you can improve performance here quite a bit still: currently it is still only doing payment by payment. So it isnt taking full advantage of the batch query helper. You could instead batch fetch the components for a whole range of payment IDs in one go
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.
@ziggie1984 will this be addressed in the later PRs?
| @ziggie1984, remember to re-request review from reviewers when ready | 
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.
I think it's expected that two itests will be failing correct? If so we can merge this one and address the issues here in the next PR.
| -- name: FetchAllInflightAttempts :many | ||
| -- Fetch all inflight attempts across all payments | ||
| SELECT | ||
| ha.id, | 
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.
should we use sqlc.embed(ha) instead?
| attempt := &HTLCAttempt{ | ||
| HTLCAttemptInfo: info, | ||
| } | ||
|  | 
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.
nit: can exit early when if !dbAttempt.ResolutionType.Valid
|  | ||
| // fetchHTLCAttemptsForPayment fetches all HTLC attempts for a payment and | ||
| // uses ExecuteBatchQuery to efficiently fetch hops and custom records. | ||
| func (s *SQLStore) fetchHTLCAttemptsForPayment(ctx context.Context, | 
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.
@ziggie1984 will this be addressed in the later PRs?
| }, func() { | ||
| }) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to fetch payment: %w", err) | 
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.
This wrapping is redundant
| }, func() { | ||
| }) | 
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.
Not addressed
Depends on #9147
This PR implements the QueryPayments and FetchPayment SQL Payments DB backend functions.
It does not yet add testing for these functions which will be added in followup PRs once we have the ability to add payments and attempts to the database which we then can fetch.