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.
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.
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.
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.
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.
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.
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.
This commit adds new getters: `GetGroupID` and `GetSessionIDs` to the
session store which can be used to query the newly added indexes to get
the associated group ID for a session ID or the associated set of
session IDs for a group ID.
Add the new `GroupID1` field to the `Session` struct and ensure that the
new fields are properly serialised and deserialised. The `GroupID` is
the ID of the first Session in a set of linked sessions.
This commit does a few things:
1. Instead of deriving IDs using the first 4 bytes of the session's
serialised local pub key, we instead use bytes [1:5] in order to skip
the first byte which is either 0x02 or 0x03. This results in a
greater entropy set.
2. We also add a new index from ID to key and we write to this index
each time a new session is added.
3. We add a `ReserveNewSessionID` method to the session store which will
grind through private keys until it finds one that does not clash
with the current ID set.
4. A migration is added to back-fill the ID-to-key index. If any old
sessions are found that _do_ have a colliding ID, they are sorted by
created time and all but the newest session is revoked. Only an entry
for the newest session will be added to the ID-to-key index.
In this commit, the Account session type is changed to be type 5 in
both the session proto and in the persisted Session. This is done so
that type 4 can be reserved for future use.
In this commit, we update the go mod to point to the version of LNC that
contains the logic for handshake version 2. This requires that we pass
in a call back that LNC can call to persist the remote static key once
it is received. This then needs to be provided each time we start up the
session again.