Commit graph

39 commits

Author SHA1 Message Date
Viktor Torstensson
9016bbb3d2
multi: confirm kvdb migration at startup
Prompt before automatically migrating legacy kvdb state to SQL when
litd starts with a SQL backend and active bbolt data is still present.

Detect prior migrations by checking for the SQL tombstone marker so
already-migrated stores can start without prompting. Add unit coverage
for the prompt flow and wire stdin through the itest harness so the
migration restart path can acknowledge the prompt automatically.
2026-06-08 21:11:51 +02:00
Viktor Torstensson
000d28a4fb
multi: deprecate kvdb stores after SQL migration
Mark the legacy kvdb stores as deprecated once the kvdb -> SQL
migration commits successfully. This prevents normal bbolt startup
from reopening accounts.db, session.db, or rules.db after their data
has already been migrated.

Add explicit deprecation checks to the three kvdb store open paths and
provide migration-only constructors that can still reopen deprecated
files when the SQL database is deleted or downgraded and the migration
must be rerun.

Use store-specific tombstones for the deprecation markers and add
tests that verify deprecated stores are rejected while migration
reruns continue to work.
2026-05-14 11:39:14 +02: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
bitromortac
a18c0b656f
session: implement DeleteReservedSession 2025-11-25 19:35:42 +01: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
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
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
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
Elle Mouton
aafeacd18c
session: add session get and put helpers 2025-02-19 12:09:27 -03:00
Elle Mouton
6717d9d54b
session+lnrpc: add StateReserved and delete these on start up 2025-02-19 12:09:27 -03:00
Elle Mouton
d2b077b9d5
session: add ListSessionsByState method 2025-02-13 15:28:23 +02:00
Elle Mouton
01410f7950
session: remove the filter fn in ListSessions
And replace with ListAllSessions since no callers of ListSessions
currently make use of the filter function.
2025-02-13 15:22:28 +02:00
Elle Mouton
6c36b01fd8
session: add ListSessionsByType method
And use it to replace one call to ListSessions which uses a filter
function which would be inefficient in SQL land.
2025-02-13 15:13:00 +02:00
Elle Mouton
00230029f3
session: ensure listed sessions are sorted
Sorted by creation time. Also add a test to cover this.
2025-02-13 15:12:55 +02:00
Elle Mouton
64f79617e4
session: use clock for times
And be consistent with UTC conversions.
2025-02-11 19:22:08 +02:00
Elle Mouton
8c4d17c6d8
session: add a clock to the DB 2025-02-11 19:22:07 +02:00
Elle Mouton
e923fff46c
session: add NewSession to Store interface
For now, it makes no DB calls. But this is in prepartion for letting
this call persist a new session. This will also let us use a shared
`clock` for the time fields in a Session.
2025-02-11 19:19:11 +02:00
Elle Mouton
03d03eabfc
session: create errors.go file
And move an error here which we plan to use across DB types.
2025-02-09 07:02:42 +02:00
Elle Mouton
88e4f2e5ed
session: rename DB to BoltStore
To better reflect the DB backing the CRUD and to prepare for a new
`SQLStore` type.
2025-02-09 07:01:11 +02:00
Elle Mouton
0652e7cdab
session: move all Bolt DB code to kvdb_store.go
Keep all KVDB logic contained within the same file.
2025-02-09 06:58:02 +02:00
Elle Mouton
63a7bf9756
session: rename store.go to kvdb_store.go
In preparation for adding a new `sql_store.go` file later on.
2025-02-09 06:56:26 +02:00
Renamed from session/store.go (Browse further)