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

[sql-3] accounts: replace calls to UpdateAccount #939

Merged
merged 5 commits into from
Jan 21, 2025

Conversation

ellemouton
Copy link
Member

@ellemouton ellemouton commented Jan 16, 2025

(similar PR description to #938 but they are not dependent on each other)

To prepare the accounts.Store to be more SQL compatible, we will want to replace the current
UpdateAccount method. Today it takes a full OffChainAccount struct, serialises it and replaces
any existing in the DB. This method is not very SQL appropriate as the better pattern is to instead
have specific update methods that read: "Update field X and account with ID Y".

So this PR starts this process of adding more SQL friendly methods to the interface and thereby
phasing out the use of UpdateAccount. By doing so, we also move very kvdb specific logic out
of the accounts.InterceptorService.

I'm splitting this up over about 3 or 4 PRs since some of the replacements are more complicated than
others.

This PR focuses on the calls that edit/add account payments:

  • UpsertAccountPayment
  • DeleteAccountPayment

@ellemouton ellemouton added no-changelog This PR is does not require a release notes entry sql-ize labels Jan 16, 2025
@ellemouton ellemouton self-assigned this Jan 16, 2025
Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

Generally looks good! I've left a few comments below, where there's mainly one that needs to be fixed.

As also communicated offline, I do think the added options to the API UpsertAccountPayment makes this updated version harder to read and reason about than the current implementation. I think it's worth considering if it could be designed a bit differently as I feel there's a high risk of introducing bugs when the API is a bit complicated.

accounts/service.go Show resolved Hide resolved
accounts/service.go Outdated Show resolved Hide resolved
accounts/store_kvdb.go Show resolved Hide resolved
accounts/store_test.go Outdated Show resolved Hide resolved
Copy link
Member Author

@ellemouton ellemouton left a comment

Choose a reason for hiding this comment

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

I do think the added options to the API UpsertAccountPayment makes this updated version

Agreed. I do, however, want to keep this series of PRs focused on just switching out the backends without changing the existing behaviour. If we want to make behaviour better, i think it should be done separately (ideas/PRs welcome!) to keep us from scope creeping on this project.

accounts/service.go Show resolved Hide resolved
accounts/service.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

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

LGMT after this fix #939 (comment) 🚀!

Just as a small note, since the latest push contained both merge changes + fixes for the PR, I think that would have been a great scenario to either push PR changes separately from merge changes, or include the changes as fixups :).

Comment on lines 621 to 604
// There is a case where the passed in fullAmt is zero but the pending
// amount is not. In that case, we should not overwrite the pending
// amount.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't recall when this can happen. If anyone of you knows, could we update that comment to explain it?

Copy link
Member Author

Choose a reason for hiding this comment

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

i think viktor added this comment, so will leave this as a follow up for him

cc @ViktorTigerstrom

Copy link
Contributor

Choose a reason for hiding this comment

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

@ViktorTigerstrom, do you recall how when that can happen?

accounts/store_kvdb.go Show resolved Hide resolved
accounts/store_kvdb.go Outdated Show resolved Hide resolved
accounts/service.go Outdated Show resolved Hide resolved
accounts/store_test.go Outdated Show resolved Hide resolved
@ellemouton ellemouton force-pushed the sql3Accounts3 branch 2 times, most recently from 95dd10e to f2459eb Compare January 21, 2025 05:21
@ellemouton
Copy link
Member Author

oops - fixing race now

Copy link
Contributor

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

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

Nice, looks almost good, have two non-blocking comments

accounts/errors.go Outdated Show resolved Hide resolved
accounts/store_test.go Outdated Show resolved Hide resolved
accounts/service.go Show resolved Hide resolved
And use it in the InterceptorService's paymentUpdate method.
And use it instead of UpdateAccount.
In this commit, we avoid race conditions that can happen for tests that
directly access the service's `pendingPayment` map.
Copy link
Contributor

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

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

LGTM ⚡

@ellemouton ellemouton merged commit 76c63db into lightninglabs:master Jan 21, 2025
13 checks passed
@ellemouton ellemouton deleted the sql3Accounts3 branch January 21, 2025 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog This PR is does not require a release notes entry sql-ize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants