Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sql-12] sessions: make ListSession methods SQL ready #970

Merged
merged 6 commits into from
Feb 13, 2025

Conversation

ellemouton
Copy link
Member

@ellemouton ellemouton commented Feb 9, 2025

In this PR, we make various changes to the ListSessions method of the Store interface such that it
can better be implemented by a SQL backend. See commit messages for more details.

Part of #966

@ellemouton ellemouton added no-changelog This PR is does not require a release notes entry sql-ize labels Feb 9, 2025
@ellemouton ellemouton self-assigned this Feb 9, 2025
@ellemouton ellemouton changed the title [sql12] sessions: make ListSession methods SQL ready [sql-12] sessions: make ListSession methods SQL ready Feb 9, 2025
@ellemouton ellemouton force-pushed the sql12Sessions4 branch 2 times, most recently from 6cc7863 to a067bce Compare February 12, 2025 10:23
Copy link
Member

@jamaljsr jamaljsr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tACK LGTM. I'm loving this micro PRs 🙌

I ran the TW e2e tests against a litd node running this branch to confirm that everything still works and it's all green. Great work 💪

I just have one questions, but otherwise approved.

Comment on lines -356 to -364
// We only start non-revoked, non-expired LiT sessions. Everything else
// we just skip.
if sess.State != session.StateInUse &&
sess.State != session.StateCreated {

log.Debugf("Not resuming session %x with state %d", pubKeyBytes,
sess.State)
return nil
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safe to assume that the passed in session will not have an revoked/expired state? I see that all current calls to resumeSession ensure that the sesion is in a valid state, but I'm thinking about future code that may not have these safeguards in place.

If you think it's best to still remove this, then the function comment should be updated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool yeah currently all the session passed to this method will already be in the Created/InUse state since it is either called from start which now only fetches sessions in these states or it is called on session creation which will defs have the CreatedState.

GOod call - will update the comment 👍

Copy link
Contributor

@ViktorTigerstrom ViktorTigerstrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Niiiiice 🚀! Very clean PR 🔥

Laaving a few non-blocking suggestions that I'll let you decide if you think they're worth implementing or not.


// listSessions returns all sessions currently known to the store that pass the
// given filter function.
func (db *BoltStore) listSessions(filterFn func(s *Session) bool) ([]*Session, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
line length

Comment on lines +30 to +34
s1 := newSession(t, db, clock, "session 1")
clock.SetTime(testTime.Add(time.Second))
s2 := newSession(t, db, clock, "session 2")
clock.SetTime(testTime.Add(2 * time.Second))
s3 := newSession(t, db, clock, "session 3", withType(TypeAutopilot))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this really tests that the sessions are sorted by creation time, as one could argue they're just sorted by the order they were added here. So I would ensure that one of the latter sessions we add, say s3, has a creation time prior to s2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the main reason for incrementing the timestamps is to have deterministic results from ListSessions. We are just testing ListSessions as a whole, not that the results are ordered.

//
// NOTE: this is part of the Store interface.
func (db *BoltStore) ListSessions(filterFn func(s *Session) bool) ([]*Session, error) {
func (db *BoltStore) ListSessions(states ...State) ([]*Session, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Given that we have a separate ListSessionsByType function, maybe it'd make sense to have a
ListSessionsByState function separately that takes the states ...State arg, and then let the ListSessions itself take no args an have no filtering?
IMO it just feels a bit weird that the plain ListSessions func does take filtering State(s) args, while we have another separate function ListSessionsByType function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure yeah can do 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated as per suggestion

So that we can add more modifiers for future tests.
Sorted by creation time. Also add a test to cover this.
And use it to replace one call to ListSessions which uses a filter
function which would be inefficient in SQL land.
And replace with ListAllSessions since no callers of ListSessions
currently make use of the filter function.
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.
@ellemouton ellemouton merged commit c749126 into lightninglabs:master Feb 13, 2025
16 of 17 checks passed
@ellemouton ellemouton deleted the sql12Sessions4 branch February 13, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog This PR is does not require a release notes entry sql-ize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants