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-11] sessions: interface massage #969

Merged
merged 5 commits into from
Feb 12, 2025

Conversation

ellemouton
Copy link
Member

This is a tiny refactor PR that does various things to the session DB/Store
in preparation for making the interface ready for a SQL implementation.

Part of #966

@ellemouton ellemouton added the no-changelog This PR is does not require a release notes entry label Feb 9, 2025
@ellemouton ellemouton self-assigned this Feb 9, 2025
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.

Looks good 🚀! uTACK LGTM 🔥.

Leaving one questions regarding current sessions.

Comment on lines +240 to +241
session.Expiry = time.Unix(int64(expiry), 0).UTC()
session.CreatedAt = time.Unix(int64(createdAt), 0).UTC()
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm can this somehow lead to some discrepancy between current sessions that were created without UTC, which are now deserialised with UTC?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah def - but i think it's ok. worst case the expiry/created_at times now differ by a couple of hours.

I think it's an ok tradeoff and i dont think it is worth the added complexity to make sure we read everything exactly as it was/add a migration etc.

thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

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

did some testing just to make sure no issues.

Copy link
Contributor

Choose a reason for hiding this comment

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

So I guess the worst case scenario would be that a user after upgrading has a very recently created session that's now deserialized with a timestamp that's a few hours in the future. Alternatively the same could occur for recently revoked sessions, that's seen as having been revoked in the future.

Other than that such scenarios would be pretty confusing (which I think would be fine), there's one edge case where that could lead to a recently created session being automatically revoked:

deadline := sess.CreatedAt.Add(s.cfg.firstConnectionDeadline)
if deadline.Before(time.Now()) {
log.Debugf("Deadline for session %x has already "+
"passed. Revoking session", pubKeyBytes)
return s.cfg.db.RevokeSession(pubKey)
}

But given that it's such an edge case where the worst case scenario would jsut be that a session gets revoked, we deemed this to be an ok tradeoff offline.

Make sure to compare the full expected and actual Session struct during
tests.
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.
And be consistent with UTC conversions.
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 🚀

The commits are very well structured. It's so easy to review the small diffs.

@@ -77,13 +80,15 @@ const (
// BoltStore is a bolt-backed persistent store.
type BoltStore struct {
*bbolt.DB

clock clock.Clock
Copy link
Member

Choose a reason for hiding this comment

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

Can you shed a little bit of light on the benefits of injecting a shared clock with the DB? My assumption is it's primarily used to add stability for tests, but not sure if there's more to it than that.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah it is mainly for deterministic tests so that we can guarantee stable (and incrementing) timestamps

@ellemouton ellemouton merged commit 54fe5ef into lightninglabs:master Feb 12, 2025
17 checks passed
@ellemouton ellemouton deleted the sql11Sessions3 branch February 12, 2025 10:23
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants