Skip to content

sessions: strict state shifts #985

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

Merged
merged 4 commits into from
Feb 25, 2025
Merged

Conversation

ellemouton
Copy link
Member

@ellemouton ellemouton commented Feb 25, 2025

Addresses this comment.

In this PR, we ensure all session state shifts are legal via a strict transition map. We then replace the
RevokeSession method with a new ShiftState method. Finally, for expired sessions, we use the Expired state
instead of the Revoked state.

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.

Niiiiiiiice, thanks for this 🙏!!

uTACK LGTM 🚀!

Leaving some docs and test coverage comments.

Comment on lines +436 to +443
// Trying to shift the state from a terminal state back to StateCreated
// should also fail since this is not a legal state transition.
err = db.ShiftState(s1.ID, StateCreated)
require.ErrorContains(t, err, "illegal session state transition")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:
Would also be value in testing that shifting a StateReserved session to StateRevoked is not legal, as that's the concern in the comment that this PR is addressing :). Potentially also add coverage to show that StateInUse -> StateRevoked is legal.

Copy link
Member Author

Choose a reason for hiding this comment

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

personally, i think we only need to test illegal state transitions once and not for every possible iteration

Copy link
Contributor

@bitromortac bitromortac left a comment

Choose a reason for hiding this comment

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

Nice, LGTM 🎉

@@ -360,7 +360,7 @@ func (s *sessionRpcServer) resumeSession(ctx context.Context,
log.Debugf("Not resuming session %x with expiry %s",
pubKeyBytes, sess.Expiry)

err := s.cfg.db.ShiftState(sess.ID, session.StateRevoked)
err := s.cfg.db.ShiftState(sess.ID, session.StateExpired)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@ellemouton ellemouton merged commit 88a2bf0 into lightninglabs:master Feb 25, 2025
21 checks passed
@ellemouton ellemouton deleted the stateShift branch February 25, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants