-
Notifications
You must be signed in to change notification settings - Fork 2.2k
graphdb: add caching for isPublicNode query #10363
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
Open
Abdulkbk
wants to merge
5
commits into
lightningnetwork:master
Choose a base branch
from
Abdulkbk:ispub-cache
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
37d87e7
graphdb: add cachedPublicNode struct
Abdulkbk 2d51667
graphdb: plug in the cache to sqlstore
Abdulkbk 1b6bba4
graphdb: check for cached data before query
Abdulkbk cab6e89
graphdb: invalidate node cache
Abdulkbk 85b45d5
graphdb: add test for cache invalidation
Abdulkbk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| //go:build test_db_postgres || test_db_sqlite | ||
|
|
||
| package graphdb | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TestNodeIsPublicCacheInvalidation ensures that we invalidate correctly our | ||
| // cache we use when determing if a node is public or not. | ||
| func TestNodeIsPublicCacheInvalidation(t *testing.T) { | ||
| t.Parallel() | ||
| ctx := t.Context() | ||
|
|
||
| graph := MakeTestGraph(t) | ||
|
|
||
| node1 := createTestVertex(t) | ||
| node2 := createTestVertex(t) | ||
|
|
||
| require.NoError(t, graph.AddNode(ctx, node1)) | ||
| require.NoError(t, graph.AddNode(ctx, node2)) | ||
|
|
||
| edge, _ := createEdge(10, 0, 0, 0, node1, node2) | ||
| require.NoError(t, graph.AddChannelEdge(ctx, &edge)) | ||
|
|
||
| // First IsPublic call should populate cache. | ||
| isPublic1, err := graph.IsPublicNode(node1.PubKeyBytes) | ||
| require.NoError(t, err) | ||
| require.True(t, isPublic1) | ||
|
|
||
| // Test invalidation scenarios: | ||
|
|
||
| // 1. DeleteChannelEdges: | ||
| // Above, the channel being public should be cached, but we expect that | ||
| // DeleteChannelEdge will invalidate the cache for both nodes else when | ||
| // we call IsPublic, we will hit the cache. | ||
| err = graph.DeleteChannelEdges(false, true, edge.ChannelID) | ||
| require.NoError(t, err) | ||
| isPublic1, err = graph.IsPublicNode(node1.PubKeyBytes) | ||
| require.NoError(t, err) | ||
| require.False(t, isPublic1) | ||
|
|
||
| isPublic2, err := graph.IsPublicNode(node2.PubKeyBytes) | ||
| require.NoError(t, err) | ||
| require.False(t, isPublic2) | ||
|
|
||
| // 2. AddChannelEdge: | ||
| // Now we know that the last `IsPublicNode` call above will cache our | ||
| // nodes with `isPublic` = false. But add a new channel edge should | ||
| // invalidate the cache such that when we call `IsPublic` it should | ||
| // return `True`. | ||
| edge2, _ := createEdge(10, 1, 0, 1, node1, node2) | ||
| require.NoError(t, graph.AddChannelEdge(ctx, &edge2)) | ||
| isPublic1, err = graph.IsPublicNode(node1.PubKeyBytes) | ||
| require.NoError(t, err) | ||
| require.True(t, isPublic1) | ||
|
|
||
| isPublic2, err = graph.IsPublicNode(node2.PubKeyBytes) | ||
| require.NoError(t, err) | ||
| require.True(t, isPublic2) | ||
|
|
||
| // 3. DeleteNode: | ||
| // Again, the last two sets of `IsPublic` should have cached our nodes | ||
| // as `True`. Now we can delete a node and expect the next call to be | ||
| // False. | ||
| // | ||
| // NOTE: We don't get an error calling `IsPublicNode` because of how the | ||
| // SQL query is implemented to check for the existence of public nodes. | ||
| require.NoError(t, graph.DeleteNode(ctx, node1.PubKeyBytes)) | ||
| isPublic1, err = graph.IsPublicNode(node1.PubKeyBytes) | ||
| require.NoError(t, err) | ||
| require.False(t, isPublic1) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.