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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

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
And use it in the InterceptorService's paymentUpdate method.
And use it instead of UpdateAccount.
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.

// succeeded. We can then match on the ErrAlreadySucceeded error and
// exit early if it is returned.
opts := []UpsertPaymentOption{
WithErrIfAlreadySucceeded(),
Copy link
Contributor

Choose a reason for hiding this comment

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

We're not matching on ErrAlreadySucceeded below. This function should return nil if it is an ErrAlreadySucceeded error.

Comment on lines 848 to 849
pendingPayment.cancel()
delete(s.pendingPayments, hash)
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that similar to the other PR, this will now run before we've checked if there's an account id for the pendingPayment. I do that should be unreachable though, and probably actually correct behaviour, so don't really think this needs to change.

Comment on lines +240 to +242
if opts.usePendingAmount {
fullAmount = entry.FullAmount
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that this is a difference from the current behaviour, where this was set regardless of if an entry existed or not, as long as fullAmount was zero. That feels pretty dangerous 😅, so good fix 🚀!

@@ -105,6 +105,188 @@ func assertEqualAccounts(t *testing.T, expected,
actual.LastUpdate = actualUpdate
}

// TestAccountUpdateMethods tests that all the Store methods that update an
// account work correctly.
func TestAccountUpdateMethods(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the other PR, we should test the behaviour for an unknown account id :).

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.

2 participants