Commit graph

60 commits

Author SHA1 Message Date
Oliver Gugger
396b898acf
Merge pull request #951 from lightninglabs/compilation-fix
GitHub+accounts: fix i386 compilation issue
2025-01-23 05:18:19 -06:00
Oliver Gugger
1657584eb9
accounts: fix compilation issue for i386 systems
Apparently the %d formatting directive implicitly uses `int` as its data
type, which on i386 systems is int32. So the value math.MaxInt64
overflows that value, which causes the compilation to fail.
2025-01-23 10:07:10 +01:00
Elle Mouton
ef78bc4d9d
accounts: assert no startup error in tests
In the case where no startup error is expected, we should assert that no
error is returned from Start.
2025-01-23 09:20:09 +02:00
Elle Mouton
957c9a3a52
accounts: remove UpdateAccount and last usages
We remove the last few calls to UpdateAccount from the
TestAccountService test. Previously, the UpdateAccount call was used in
this test to also _insert_ new accounts and to force the account ID to
be set to specific values. So here we need to instead call the store's
NewAccount method to insert a new account, then we get the AccountID
from the returned value and we need to then use this returned ID (which
is no longer forceable) in the remainder of the tests.
2025-01-23 09:20:09 +02:00
Elle Mouton
e965f4f6af
accounts: remove UpdateAccount calls from store_test
Remove the call to UpdateAccount from the TestAccountStore test and
instead replace it with all the other calls we have added.
2025-01-23 09:20:09 +02:00
Elle Mouton
8b1c9a2893
accounts: revert UpdateAccountBalanceAndExpiry balance type to be int64
In our mission to replace UpdateAccount, we need
UpdatAccountBalanceAndExpiry to take a negative balance so that we can
use it to replace the behaviour of UpdateAccount as it stands today.
2025-01-23 09:00:49 +02:00
Elle Mouton
42a4c826cf
accounts: use clock.Clock
In this commit, we use the clock.Clock type instead of directly calling
time.Now().
2025-01-23 08:24:21 +02:00
Elle Mouton
a4506c9e1f
accounts: safe check of pendingPayments in tests
In this commit, we avoid race conditions that can happen for tests that
directly access the service's `pendingPayment` map.
2025-01-21 12:20:33 +02:00
Elle Mouton
4d8d4e1fa3
accounts: use UpsertAccountPayment in removePayment
Instead of UpdateAccount.
2025-01-21 12:20:33 +02:00
Elle Mouton
7fb7faa124
accounts: add DeleteAccountPayment method to Store
And use it instead of UpdateAccount.
2025-01-21 12:02:29 +02:00
Elle Mouton
c386008fe6
accounts: use UpsertAccountPayment for TrackPayment
Instead of useing UpdateAccount.
2025-01-21 12:02:19 +02:00
Elle Mouton
340dc5d5b0
accounts: add new UpsertAccountPayment Store method
And use it in the InterceptorService's paymentUpdate method.
2025-01-21 12:01:33 +02:00
Elle Mouton
34d1f67dd0
accounts: update the service's UpdateAccount method
... to take a more strict btcutil.Amount type for the account balance
parameter.
2025-01-17 14:17:53 +02:00
Elle Mouton
0580d9acf0
accounts: add new IncreaseAccountBalance Store method
And use it instead of UpdateAccount in the InterceptorService's
invoiceUpdate method.
2025-01-17 14:17:53 +02:00
Elle Mouton
5a4b22f6e7
accounts: add new AddAccountInvoice Store method
And use it instead of UpdateAccount for the InterceptorService's
AssociateInvoice method.
2025-01-17 14:17:53 +02:00
Elle Mouton
64606f0132
accounts: add new UpdateAccountBalanceAndExpiry Store method
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.
2025-01-17 14:11:38 +02:00
Elle Mouton
6f131a14a4
accounts+refactor: improve test readability 2025-01-16 09:19:05 +02:00
Elle Mouton
7fa370ebc7
accounts: return consistent error for duplicate label
In preparation for when we have a SQL DB implementation, we want our
unit tests to run smoothly against all DB backends and have the same
results. To achieve this, we need to turn some errors into global error
variables that can be matched against instead.

In this commit, we do this for the unique constraint violation of the
account label.
2025-01-16 09:19:05 +02:00
Elle Mouton
9f08daf948
accounts: let storeAccount set the LastUpdate timestamp
In later commits, we will use this `storeAccount` helper quite often.
Instead of needing to remember to update the timestamp outside the call,
it make sense to instead update the timestamp within the function. Yes
this does mean that sometimes we make no overall changes but do update
the timestamp but this is a pretty standard pattern that a "last
updated" timestamp is updated at any point that we re-write a record
(even if it does not have a net change).
2025-01-16 09:19:05 +02:00
Elle Mouton
2012fbaa41
accounts: update comments for the BoltStore Store impl 2025-01-16 09:19:05 +02:00
Elle Mouton
51d864a24c
accounts: DB constructors for tests
This commit adds two new test helpers, NewTestDB and NewTestDBFromPath
in a file that is only built when the test_db_postgres and
test_db_sqlite build flags are not set. When we add sql backends, we
will add helpers with the same names for each new backend. We will then
use the appropriate build flags to run our unit tests against all
backends.
2025-01-16 09:19:04 +02:00
Elle Mouton
82eeadd819
accounts: pass Store impl to NewService
We want to be able to pass different DB implementations to NewService.
In preparation for this, we make it implementation agnostic by letting
it take a `Store` instead of constructing one itself.

This this change, we also let LiT handle the closing of the accounts
Store instead of the accounts service
2025-01-16 09:19:04 +02:00
Elle Mouton
86fc2ccf79
accounts: let interface methods take a context
Update the accounts `Store` and `Service` interfaces take a context.
This is in preparation for when the backend DB of the accounts service
is a SQL store which will have methods that take a context.
2025-01-16 09:19:04 +02:00
Elle Mouton
62e1a7eb61
accounts: rename store file
We rename the `store.go` file to `store_kvdb.go` to indicate that this
file contains the kvdb implementation of the accounts DB. This is in
preparation for adding a sql-backed implementation later on.

We do this early on in the PR so that any changes that need to be made
during the review process can be easily addressed with fix-up commits
that edit the newly named file.
2025-01-14 18:26:08 +02:00
Elle Mouton
1a30bdb83a
accounts: thread context through to accounts 2025-01-13 09:29:29 +02:00
Oliver Gugger
9370c91286
accounts: split mocks
This is a preparation for bumping the lndclient dependency.
Because each lndclient service mock now needs to implement the
RawClientWithMacAuth method but with a different type, we can't
implement two lndclient service mocks within a single struct, as
that would require us to have two methods with the same name but
different types.
So we split the lnd and rounter mocks into two separate structs.
2024-10-30 09:37:20 +01:00
Viktor Tigerström
33d717a624
accounts: remove uninitiated payments
If an unknown payment turns out to be a not initiated payment, we should
remove it so that the pending balance is freed up for the user.
2024-06-06 12:48:51 -04:00
Viktor Tigerström
fe333cb8f4
accounts: deduct in-flight balance by account ID
This commit ensures that a pending payment is associated with the
specific account ID before deducting the in-flight balance from the
available balance.
2024-06-06 12:43:56 -04:00
Viktor Tigerström
9d9d6585ab
accounts: refactor in-flight check
This commit refactors the in-flight check in the accounts service to
its own function. The in-flight check is also inverted to only check
the states that are not considered as in-flight. This makes the check
forward-compatible with lnd `v0.18.0-beta` which introduces a new
`lnrpc.Payment_INITIATED` state.
2024-06-06 12:43:56 -04:00
Elle Mouton
61f32f68fb
accounts: start logging errored request info 2024-06-06 12:43:56 -04:00
Elle Mouton
fde86d3136
accounts+mid: support for error handlers in accounts
We also want to be able to see via the trace logs if a request has
errored. So first we need to update the framework to be ready for this.
2024-06-06 12:43:56 -04:00
Elle Mouton
0bac0aacba
accounts: start logging useful info from payment response handlers 2024-06-06 12:43:56 -04:00
Elle Mouton
8b5a01f909
accounts: start logging useful info from payment request handlers
This commit adds a prefixed logger that is then used to log trace
information about a payment. This will make it easy to see from the logs
which account ID is making the request, what the request ID is and what
the relavant payment hash is.
2024-06-06 12:43:56 -04:00
Elle Mouton
9ffd05a597
accounts: start writing to the new request ID scoped cache
For all payment request handlers, start using the new ReqIDToPaymentHash
store to store some state (just payment hash for now).
2024-06-06 12:43:56 -04:00
Elle Mouton
18c819b442
accounts: add ReqIDToPaymentHashStore and implement
In preparation for implementing trace logging that makes it easy to link
state across requests and responses for more informative logs, we add a
new ReqIDToPaymentHashStore interface along with an in-memory
implementation. This can be expanded in future to contain other state
but for now let's just go with the payment hash since that is useful to
have and will provide the user useful information about the payment
corresponding to a log.
2024-06-06 12:43:56 -04:00
Elle Mouton
e807639f82
accounts: start adding request ID to context
In preperation for the trace logging we want to implement in an upcoming
commit (where logs for requests & responsescan be linked via their
request ID), we start adding the request ID to an intercepted account
request/response in this commit.
2024-06-06 12:43:56 -04:00
Viktor Tigerström
e5737436cd
accounts + main: allow new accounts with 0 balance 2024-02-01 11:22:08 +02:00
Oliver Gugger
d3413ae637
accounts+cmd/litcli: fix formatting 2024-01-03 11:14:51 +01:00
George Tsagkarelis
89a494da16
accounts: fix service check in UpdateAccounts call 2023-10-11 20:03:43 +03:00
Oliver Gugger
322a96133d
multi: fix linter issues 2023-10-03 19:52:02 +02:00
Viktor Tigerström
20fa2c0915
terminal: add disable accounts service cfg option 2023-09-28 13:09:33 +02:00
Viktor Tigerström
ec2a7a39b4
multi: add accounts service to status manager
Add the accounts service to status manager. This will allow us to query
the status of the accounts service and see if it is running or not.
For incoming gRPC requests to the accounts service, we also use the
status manager to check if the accounts service is running or not to
determine if we should let the request through or not.
2023-09-28 13:09:33 +02:00
Viktor Tigerström
6f9f3244fb
accounts: process requests before stopping service
Ensure that we don't stop the service while we're processing a request.
This is especially important to ensure that we don't stop the service
exactly after a user has made an rpc call to send a payment we can't
know the payment hash for prior to the actual payment being sent
(i.e. Keysend or SendToRoute). This is because if we stop the service
after the send request has been sent to lnd, but before TrackPayment
has been called, we won't be able to track the payment and debit the
account.
2023-09-28 12:58:37 +02:00
Viktor Tigerström
666f19cee8
accounts: associate payments before sending them 2023-09-28 12:58:37 +02:00
Viktor Tigerström
32b2a5885f
terminal: don't stop litd on account system error 2023-09-28 12:58:37 +02:00
Viktor Tigerström
4696c47f59
accounts: add service disabled unit tests 2023-09-28 12:58:36 +02:00
Viktor Tigerström
a49422f36f
accounts: disallow requests after critical errors 2023-09-28 12:58:36 +02:00
Oliver Gugger
fd6c9063cf
accounts: don't error out on payment not initiated
It can happen that we see the payment request for a payment coming in,
register it, but then it is failed on the lnd level and basically never
exists in the DB.
In that case we can just stop tracking the payment.
2023-09-06 17:47:54 +02:00
Oliver Gugger
568d7ad508
accounts+itest: fix linter and code style issues 2023-07-26 18:37:49 +02:00
Oliver Gugger
27b04eb374
multi: add AccountInfo RPC 2023-07-26 16:41:20 +02:00