Skip to content

[sql-28] firewall+sessions: clean up in preparation for SQL backend #1029

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
Apr 8, 2025

Conversation

ellemouton
Copy link
Member

In this PR, we do the last bit of clean up of the bbolt kvstores impl along with the tests of the kvstores.

The main thing this PR does is to assert strong coupling between kvstores and the session it is referencing. We do this in the bbolt implementation so that our unit tests can assert the correct errors. After this, we should be able to just plug in the SQL impl without making any further changes to the kvstore unit tests.

See commit messages for more details.

Part of #917

GetGroupID is given a session ID as a param and so should return
ErrSessionNotFound if that session is not found. GetSessionIDs is given
a groupID as a param and so should return ErrUnknownGroup if that group
does not exist.

This commit updates the kvstore and sql implementations to return the
correct error values and also ensures that this is properly tested now.
In preparation for it clashing with a transaction tx variable in an
upcoming commit.
Convert some helpers to be methods on `kvStoreTx` in preparation for
some of these helpers needing access to other variables within
`kvStoreTx`.
If the is writing to a kvstore that is namespaced by a session's ID, we
first assert that the session exists in the session store. We add a test
for this accordingly. We do this in preparation for adding a sql backend
which will error out if we try to link a kvstore to a session that does
not yet exist.
@ellemouton ellemouton added no-changelog This PR is does not require a release notes entry sql-ize labels Apr 7, 2025
@ellemouton ellemouton self-assigned this Apr 7, 2025

// Get a kvstore namespaced by a session ID for a session that does
// not exist.
store := db.GetKVStores("AutoFees", [4]byte{1, 1, 1, 1}, "auto-fees")
Copy link
Contributor

Choose a reason for hiding this comment

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

would it make sense to already error here in case the session is not found, or does this prevent some functionality?

Copy link
Member Author

Choose a reason for hiding this comment

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

just cause of how this works under the hood on db types, it makes more sense to have this check at DB access time. THis call doesnt currently make a DB call. Also i think we want Get/Delete to not necessarily error out if the session does not exist yet - those should just return nil, nil

@ellemouton ellemouton requested a review from bitromortac April 8, 2025 09:05
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.

Niiiice uTACK LGTM 🔥!

@@ -376,6 +392,81 @@ func TestKVStoreNameSpaces(t *testing.T) {
require.True(t, bytes.Equal(v, []byte("thing 3")))
}

// TestKVStoreSessionCoupling tests if we attempt to write to a kvstore that
// is namespaced by a session that does not exist, then we should get an error.
func TestKVStoreSessionCoupling(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🔥

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.

LGTM ⚡

@ellemouton ellemouton merged commit 1e257d1 into lightninglabs:master Apr 8, 2025
18 of 21 checks passed
@ellemouton ellemouton deleted the sql28 branch April 8, 2025 10:42
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