Commit graph

117 commits

Author SHA1 Message Date
Viktor Torstensson
bebe33b4ee
session: add database backend benchmark test 2026-03-05 13:04:16 +01:00
Viktor Tigerström
08b91b09ef
multi: introduce migration stream for unit tests
In upcoming commits, we will introduce a new migration stream package
that will need to reference the db package, as well as the accounts,
session and firewalldb package in future commits. To avoid circular
dependencies, we therefore introduce a new migration stream that unit
tests can use, in order to avoid having to import the new migration
stream package.
2026-02-16 10:28:57 +01:00
Viktor Tigerström
787c80cd02
session: use sqlcmig6 for kvdb to sql migration
This commit updates the session package to use the new `sqlcmig6`
package for kvdb to SQL migration.
2026-02-13 19:37:30 +01:00
Viktor Tigerström
f525a7f49d
mutli: rename db.NewTestPostgresV2DB function
As the legacy `NewTestPostgresDB` function is no longer used and has
been removed, it no longer makes sense to have a `V2` suffix on the
`NewTestPostgresV2DB` function. This commit renames it to
`NewTestPostgresDB`, to indicate that this function now replaces the
legacy function.
2026-02-06 20:14:35 +01:00
Viktor Tigerström
265ce94be1
multi: use sqldb/v2 in session package
Update the session package to use the `sqldb/v2` package instead of the
older version.
2026-02-06 20:14:34 +01:00
ffranr
a0e63124c0
multi: reformat long lines for readability
- Replace occurrences of `// nolint:lll` with `// nolint:ll` across
  files for consistency.
- Reformat multiline strings, comments, and function parameters to
  improve clarity and adhere to style guidelines.
- Add `// nolint:ll` comments where necessary to prevent linter
  warnings.
2025-12-09 16:12:03 +00:00
Viktor Torstensson
d14d7668f6
Merge pull request #1174 from bitromortac/2511-delete-session-after-fail
sessions: delete session after registration failure
2025-11-26 15:49:17 +01:00
bitromortac
a18c0b656f
session: implement DeleteReservedSession 2025-11-25 19:35:42 +01:00
Viktor Torstensson
3d10572280
session: fix empty config for features in sql mig
In the bbolt store, an empty config for a feature is represented as an
empty array, while in for the SQL store, the same config is represented
as nil. Therefore, in the scenario where a specific feature has an empty
config, we override the SQL FeatureConfig for that feature to also be
set to an empty array. This is needed to ensure that the deep equals
check in the migration validation does not fail in this scenario.
2025-11-10 13:40:51 +01:00
Viktor Torstensson
b4b36f653f
session: handle removed linked account
If a user creates a session linked to an account, but later deletes that
account using the `litcli accounts remove` command, the KVDB session
will still contain the account ID of the removed account.

During the KVDB to SQL migration, the accounts migration runs before the
sessions migration. Since the deleted account no longer exists, it
cannot be migrated. As a result, the migrated SQL session cannot link to
the now non-existent account in the SQL store.

In such cases, we will migrate the session and not link to any account
in the SQL session.
2025-09-26 20:46:50 +02:00
Elle
bce4c049a9
Merge pull request #1133 from ViktorTigerstrom/2025-08-session-migration-duplicate-id-fix
[sql-50] session migration duplicate ID fix
2025-09-02 16:20:37 +02:00
Viktor Tigerström
dfe0fa8b07
session: handle multiple sessions with the same ID
The logic to avoid duplicate session IDs was first added with the
session linking linking functionality. That means that there may be old
legacy sessions that were added prior to that which may have duplicate
IDs. Before this commit, such sessions would cause the kvdb to SQL
migration to error, as there is a uniqueness constraint on the legacy
session alias in the SQL sessions table.

We want to keep that constraint, so in such rare cases, we update the
kvdb to SQL migration logic to drop all but the session with the
latest CreatedAt time if for sessions that share the same ID.
That follows the logic in c8b78bd10d as
closely as possible, as that migration ensured that all sessions but the
latest one was revoked if multiple sessions shared the same ID.
2025-08-21 16:03:31 +02:00
Viktor Tigerström
2d3564b36b
session: add expected results to migration tests
In the upcoming commit, we will update the kvdb to sql migration to not
always include all sessions in the kvdb store. Therefore, we update the
kvdb to migration tests in order to be able to handle such cases by
including the expected results for each test case.
2025-08-19 23:22:15 +02:00
Viktor Tigerström
1af12f4fb9
session: sort MacaroonRecipe.Permissions in migration
Similar to the previous commit, we also sort the
`MacaroonRecipe.Permissions` slice to ensure it can be compared in a
deterministic manner during migrations.
2025-08-15 17:19:23 +02:00
Viktor Tigerström
d3eb3cd3fc
session: sort MacaroonRecipe.caveats in migration
In the kvdb to sql migration, if there have been caveats set for the
MacaroonRecipe, the order of the postgres db caveats will in very rare
cases differ from the kv store caveats. Therefore, we sort both the kv
and sql caveats by their ID, so that we can compare them in a
deterministic way.
2025-08-07 15:54:16 +02:00
Oliver Gugger
c417adf318
mod+accounts+session: update to latest lnd RC 2025-07-11 18:41:16 +02:00
Viktor Tigerström
2007d538ec
session: add randomized session migration test 2025-06-12 13:06:27 +02:00
Viktor Tigerström
8f1aa99ee5
session: add migration code from kvdb to SQL
This commit introduces the migration logic for transitioning the
sessions store from kvdb to SQL.

Note that as of this commit, the migration is not yet triggered by any
production code, i.e. only tests execute the migration logic.
2025-06-12 11:52:39 +02:00
Viktor Tigerström
6c4c6a4319
session: ensure that test SQL store is closed
We add a helper function to the functions that creates the test SQL
stores, in order to ensure that the store is properly closed when the
test is cleaned up.
2025-06-12 11:52:39 +02:00
Viktor Tigerström
b48e40f000
session: update NewTestDB funcs to return Store
In preparation for upcoming migration tests from a kvdb to an SQL store,
this commit updates the NewTestDB function to return the Store interface
rather than a concrete store implementation.

This change ensures that migration tests can call NewTestDB under any
build tag while receiving a consistent return type.
2025-06-12 11:52:38 +02:00
Elle Mouton
87bef069e3
session: add session ID to grpc metadata via context
Add grpc interceptors that inject an LNC session's ID into the context
as gRPC metadata. By injecting it as such, it will be transported over
the wire in any outgoing gRPC calls.

This lets us be sure that any session call sent to the RPCMiddleware
interceptor in LND will continue to be grouped along with the
appropriate session ID. This gives LND a way to send the metadata we
include back to LiT meaning that we will later on be able to extract the
session ID again.
2025-05-15 06:15:10 +02:00
Elle Mouton
4f8c3aec16
firewalldb+rpcserver: refactor ListActions
Here we move the filter logic behind the interface so that our sql
implementation can make use of indexes.
2025-05-09 13:57:10 +02:00
Elle Mouton
7cb22cead9
session: embed db.BaseDB in SQLStore
So that we can extract the same BaseDB in other packages and use it for
initialising other SQL stores during tests.
2025-04-15 11:24:49 +02:00
Elle Mouton
34a202f61e
session: fix and test some return values
GetGroupID is given a session ID as a param and so should return
ErrSessionNotFound if that session is not found. GetSessionIDs is given
a groupID as a param and so should return ErrUnknownGroup if that group
does not exist.

This commit updates the kvstore and sql implementations to return the
correct error values and also ensures that this is properly tested now.
2025-04-07 13:41:27 +02:00
George Tsagkarelis
443b5f4170
Merge pull request #998 from lightninglabs/lnd-19
multi: update LiT and all deps to use LND 0.19
2025-03-26 18:29:21 +01:00
Elle Mouton
dbec9da31b
multi: update LND and friends
This commit updates:
- LND
- pool
- loop
- taproot-assets
- faraday
- lighting-node-connect
- aperture
- lndclient
- btclog

We start using the new btclog v2 library and the associated breaking
changes in the lnd/build package.

With this commit, we deprecate the `--remote.lit-maxlogfiles` and
`--remote.lit-maxlogfilesize` options and introduce new logging options
under the `--remote.lit-logging` namespace.

Finally, the LND update introduced a new `MaxBlocksMinedPerTest`
variable in the `lntest` package that we now need to override in order
for our itests to pass.
2025-03-26 09:20:52 -05:00
Elle Mouton
60da67d50a
session: add SQL CRUD
This commit adds the SQL implementation of the session.Store interface.
This can be run against all session unit tests via `make unit
pkg=session tags=test_db_sqlite` and `make unit pkg=session
tags=test_db_postgres`.
2025-03-25 16:58:01 +02:00
Elle Mouton
b82e01edf4
session: update session remote pub by session ID
It's a better pattern to refer to sessions in the same way consistently.
So we update the UpdateSessionRemotePubKey method to use a session ID as
a reference to the session instead of local pub key.
2025-03-04 17:39:03 +02:00
Elle Mouton
190d3dc828
multi: rename GetSessionByID to GetSession
By default, we fetch records by an ID.
2025-03-04 17:34:31 +02:00
Elle Mouton
1ba381cead
session: rename GetSession method
Rename it to GetSessionByLocalPub so that it is more accurately named
and so that we free up the GetSession name for future use.
2025-03-04 17:30:43 +02:00
Elle Mouton
8a34189b45
session: assert account exists before linking a session to it
In this commit, we more tightly & explicitly link a session to an
account. At a persitance layer, we have always only linked a session to
an account by encoding the AccountID within the macaroon caveat that we
store with the session. We still keep this persistence the same but now
we first ensure that the account exists and we also add an AccountID
field to the Session struct.
2025-03-04 13:43:42 +02:00
Elle Mouton
2717aa0bc2
session+terminal: give session Store access to the accounts store
When we link a session to an account, we want to be able to validate
that the account actually does exist. So in preparation for that, we
first give the session store access to the accounts store.
2025-03-04 13:43:13 +02:00
Elle Mouton
b3bc6df4e4
session: fix test timestamp
Before we add the SQL implementation of the store, we fix this timestamp
to be a more realistic number. This is needed since in sqlite,
timestamps are serialised as strings and golang actually cant parse the
string for the current timestamp back into a time.Time. This is the
error that will be encountered:
`parsing time "99999-01-01 00:00:00 +0000 UTC" as "2006-01-02
15:04:05.999999999 -0700 MST": cannot parse "9-01-01 00:00:00 +0000 UTC"
as "-"`
2025-03-02 13:28:34 +02:00
Elle Mouton
306519fd6d
session: remove variadic State param from ListSessionsByState
We only really ever use it in one place and even then, only for a
session State that we no longer use anymore.

This is done to make the SQL queries we will need to implement the SQL
Store more simple.
2025-03-02 13:27:14 +02:00
Elle Mouton
01c19c5172
session: add context to UpdateSessionRemotePubKey 2025-02-28 09:26:02 +02:00
Elle Mouton
f93093e7c9
session: add context to ShiftState 2025-02-28 09:26:02 +02:00
Elle Mouton
aa7b1db207
session: pass contexts through to all IDToGroupIndex methods 2025-02-28 09:26:02 +02:00
Elle Mouton
9642ce1656
session+firewall: pass context to GetSessionByID 2025-02-28 09:26:02 +02:00
Elle Mouton
aa5674cabd
session: add context to DeleteReservedSessions 2025-02-28 09:24:42 +02:00
Elle Mouton
7c30c510a1
session: add context to various session List methods 2025-02-28 09:24:42 +02:00
Elle Mouton
310f11acda
session: add context to GetSession 2025-02-28 09:24:41 +02:00
Elle Mouton
2dda9308b6
session: pass context to NewSession 2025-02-28 09:24:10 +02:00
Elle
bc4439f0c2
Merge pull request #988 from ellemouton/sql17Sessions9
[sql-17] sessions: test preparation
2025-02-28 09:22:53 +02:00
Elle Mouton
b81742fe9d
session: functional options for NewSession
For a cleaner interface, adjust the NewSession method of the Session
store such that all optional arguments are functional options.
2025-02-27 15:00:02 +02:00
Elle Mouton
44625c32e1
session: add DB constructor helpers for tests
In preparation for adding helpers with the same names but that will
compile under different build flags, we add the helper DB constructors
to use when testing the session store logic against a KVDB backend.
2025-02-27 08:10:35 +02:00
Elle Mouton
5ed5fd25fa
session: use error variables
In preparation for having the unit tests pass against a different Store
implementation, we standardize some of the errors that get returned.
2025-02-27 08:07:51 +02:00
Elle Mouton
32a34d1245
session: remove Session Group Predicate method
This was used to check that all linked sessions are no longer
active before attempting to register an autopilot session. But this is
no longer needed since this is done within NewSession.
2025-02-26 18:32:13 +02:00
Elle Mouton
013e7c081c
session: introduce Reserve->Create pattern
In this commit, we let StateReserved be the new initial state of a
session for when NewSession is called. We then do predicate checks for
linked sessions along with unique session alias (ID) and priv key
derivations all under the same DB transaction in NewSession.

ShiftState then moves a session to StateCreated. Only in StateCreated
does a session become usable.

With this change, we no longer need to ensure atomic session creation by
acquiring the `sessRegMu` mutex in the session RPC server.
2025-02-26 18:32:12 +02:00
Elle Mouton
1ed4907097
session: replace RevokeSession with ShiftState 2025-02-25 16:23:07 +02:00
Elle Mouton
8f22fc98a0
session: add ShiftState method to session Store
And only allow legal state shifts.
2025-02-25 16:23:06 +02:00