Commit graph

111 commits

Author SHA1 Message Date
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
1b10afdc8d
rpcserver: remove session after registration error 2025-11-26 14:34:27 +01:00
Viktor Torstensson
bd59605516
multi: add AddActionReq MacaroonId helper func
Add helper method to `AddActionReq` returns the 4 byte macaroon ID that
is derived from the MacaroonRootKeyID. Using the helper removes some
code repetition at call sites, and makes the intended usage clearer.
2025-10-03 11:44:05 +02:00
Viktor Torstensson
01bc36ca41
multi: remove AddActionReq MacaroonIdentifier
As the `MacaroonRootKeyID` field of the `AddActionReq` struct also
contains the 4 bytes of the `MacaroonIdentifier`, we change all
call sites to instead use the last 4 bytes of the `MacaroonRootKeyID`
field. As the `MacaroonIdentifier` field therefore becomes redundant,
we also remove it.
2025-10-03 11:44:05 +02:00
Viktor Tigerström
9e9140e197
terminal: separate session RPC server init & start
Similar to how the previous commit separated the initialization and
starting of the account RPC server, this commit separates the
initialization and starting of the sessions RPC server.
2025-09-01 10:30:19 +02:00
Elle Mouton
b99a4f8fa2
firewall+firewalldb: move mac ID serialisation to kvdb impl
For our kvdb firewalldb, we use an empty 4 byte array as the macaroon
identifier even if no macaroon was used to create the action. This is so
that we have some sort of "session ID" bucket to store these set of
actions under. For our SQL impl, however, this is not needed and we will
likely just use a nullable field for the macaroon ID. So in preparation
for this, we move the kvdb specific logic to the kvdb impl.
2025-05-27 15:22:24 +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
f6e66db7ab
litrpc: add macaroon_identifier to Action message
We add a new macaroon_identifier field to the Action proto message an
populate it in the rpc server.
2025-05-13 09:20:24 +02:00
Elle Mouton
3e963c04b4
multi: rename Action.SessionID to MacaroonIdentifier
To make it very clear what the data is actually derived from. Then also
add an optional Session.ID. Our bbolt db wont store this real session ID
and will populate it in a best effort manner by casting the persisted
MacaroonIdentifier.
2025-05-13 09:05:12 +02:00
Elle Mouton
ec3b38f607
firewalldb: put Action DB methods behind an interface
So that we can easily add a different implementation and swop them out
later.
2025-05-09 16:16:33 +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
b9ad66471d
multi+refactor: remove unnecessary type alias
Remove the `NewPrivacyMapDB` type alias. It is not needed.
2025-04-22 06:10:48 +02:00
Elle Mouton
5026e66e7c
firewalldb: rename DB to BoltDB
In preparation for a db-backend agnostic DB struct along with a SQL
implementation of the various stores in the package which will be housed
under a struct named `SQLDB`.
2025-04-03 09:02:47 +02:00
Elle Mouton
ef93611489
firewalldb: thread contexts to FetchAllPairs
Update the FetchAllPairs method of the PrivacyMapTx interface to take a
context.
2025-03-25 18:10:52 +02:00
Elle Mouton
5b31f16446
firewalldb: thread context to RealToPseudo
Update the RealToPseudo method of the PrivacyMapTx interface to take a
context.
2025-03-25 18:10:52 +02:00
Elle Mouton
7e8e4a9920
firewalldb: thread context to PseudoToReal
Update the PseudoToReal method of the PrivacyMapTx interface to take a
context.
2025-03-25 18:10:52 +02:00
Elle Mouton
197ee3b5ba
firewalldb: thread context to PrivMap NewPair
Update the NewPair method of the PrivacyMapTx interface to take a
context.
2025-03-25 18:10:52 +02:00
Elle Mouton
7ce36d7e7d
multi: thread contexts through privacy map interfaces
Update the PrivacyMapDB interface methods to take contexts (both the
methods themselves and the call-back params) and then ensure all
implementations are updated and all call-sites pass contexts through
correctly.
2025-03-25 18:10:52 +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
bfb3c7bc13
session_rpcserver: include account ID in Session proto 2025-03-04 13:43:44 +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
03712e6067
accounts: add an IDFromCaveates helper
And use that from the existing accountFromMacaroon helper (which will
then test the new helper by proxy).

We add this helper so that we can use it later on from the sessions
package where we want to extract an account ID from a caveat (we wont
have a full macaroon available).
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
0d6eefad9d
firewalldb: let ListGroupActions take a context
In preparation for it needing to pass one to GetSessionIDs.
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 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
889cdfea71
session_rpcserver: priv flags only to be set if privacy map active
Error out if an AddAutopilotSession call has privacy map flags specified
but does not activate the privacy mapper.
2025-02-27 07:23:28 +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
3272dda2a1
session_rpcserver: use the Expired state for expired sessions 2025-02-25 16:23:07 +02:00
Elle Mouton
1ed4907097
session: replace RevokeSession with ShiftState 2025-02-25 16:23:07 +02:00
Elle Mouton
6717d9d54b
session+lnrpc: add StateReserved and delete these on start up 2025-02-19 12:09:27 -03:00
Elle Mouton
14cb0be3bc
lit: only fetch active sessions on startup
Using the new ListSessions by type method, we no longer need to fetch
and iterate through all our sessions on start up to figure out which
ones to spin up.
2025-02-13 15:29:17 +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
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
c0e85e0f24
Merge pull request #968 from ellemouton/sql10Sessions2
[sql-10] sessions: decouple super macaroon helpers from `sessions` package
2025-02-11 19:10:32 +02:00
Elle Mouton
29f6db7de6
lit: use db.Store interface instead of raw DB pointer
Give the sessionRpcServer access to the session store via the
session.Store interface instead of the raw DB pointer. This will make it
possible to swop out the implementation (which is currently bbolt) with
something else such as a SQL implementation. We move the responsibility
of closing the DB to the main LiT server.
2025-02-11 13:11:55 +02:00
Elle Mouton
402373cfca
session: move MacaroonBaker to macaroons package
Move the MacaroonBaker type to the new macaroons package to avoid import
cycles in future.
2025-02-09 10:56:23 +02:00
Elle Mouton
4d22dfb7e9
multi: refactor to not use session.MacaroonRecipe outside the package
In this commit, we refactor various uses of the session.MacaroonRecipe
type outside of the session package. This is to decouple the baking of a
super macaroon from the sessions package and will help avoid import
cycles in future.
2025-02-09 10:45:10 +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