-
Notifications
You must be signed in to change notification settings - Fork 99
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-2] accounts: start replacing calls to UpdateAccount #938
Conversation
b0eb915
to
6cc5854
Compare
6cc5854
to
b499498
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.
Changes LGTM, the itest failure seems unrelated, not sure if this has been seen before.
thanks @bitromortac , yeah this one has popped up a few times. I've made an issue for it now: #940 i'll still re-kick the job though (after next review) so that we can have a green here before merge |
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.
Looks good 🚀!
Agree with Tobias on idea of converting optional types one layer higher, so great to hear that there'll be a new PR for that :)
Also for clarification I've tested just for sanity sake that the update to use btcutil.Amount
in the accounts UpdateAccount
method doesn't affect the current cli method
behaviour (as the actual rpc servers functions aren't covered by tests).
accounts/service.go
Outdated
s.invoiceToAccount[hash] = id | ||
|
||
return s.store.UpdateAccount(ctx, account) | ||
return s.store.AddAccountInvoice(ctx, id, hash) |
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.
Just noting that this changes the behaviour from the previous code, where we will now assign s.invoiceToAccount[hash]
the id
even if an account for that id
doesn't exist in the db.
So if users are were to manipulate the account id with the context to an unknown id, that would occur.
I do think this should be fine even if that would somehow happen, despite the "memory leak" with the added entry to the map, as it must represent a real invoice which has added a lot of memory allocation either way, and the user wouldn't get credited if it was paid.
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.
good catch! I've updated it to only assign to the in-mem map if the DB call succeeded. lemme know what you think
|
||
// Now, update just the balance of the account. | ||
newBalance := lnwire.MilliSatoshi(123) | ||
err = store.UpdateAccountBalanceAndExpiry( |
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 applies to all tests:
I think we should also test how these db functions behave if an unknown id is passed into the functions.
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.
added
In this commit, we remove one call to the UpdateAccount store method and replace it with a call to a new UpdateAccountBalanceAndExpiry method which updates an accounts balance and/or expiry fields and finds the account via the given ID. This method signature is more appropriate for a SQL backend than the UpdateAccount method.
And use it instead of UpdateAccount for the InterceptorService's AssociateInvoice method.
And use it instead of UpdateAccount in the InterceptorService's invoiceUpdate method.
... to take a more strict btcutil.Amount type for the account balance parameter.
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.
thanks @ViktorTigerstrom 🙏
accounts/service.go
Outdated
s.invoiceToAccount[hash] = id | ||
|
||
return s.store.UpdateAccount(ctx, account) | ||
return s.store.AddAccountInvoice(ctx, id, hash) |
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.
good catch! I've updated it to only assign to the in-mem map if the DB call succeeded. lemme know what you think
08b1ca9
to
34d1f67
Compare
To prepare the
accounts.Store
to be more SQL compatible, we will want to replace the currentUpdateAccount
method. Today it takes a fullOffChainAccount
struct, serialises it and replacesany 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 outof 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 just replacing the simple ones:
UpdateAccountBalanceAndExpiry
AddAccountInvoice
IncreaseAccountBalance