graph/db: don't let tests write to graphCache
What changed, and why it matters
This commit only changes test code in LND's channel graph database tests. It replaces a hack where tests manually set an internal graphCache field to nil with a proper helper option, WithUseGraphCache(false). There is no change to production code, no security fix, and no vulnerability being addressed.
No security action needed. This is a test-only refactor. Reviewers may optionally verify that the new WithUseGraphCache helper is already covered by existing tests.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff modifies graph/db/graph_test.go only. It updates two test functions (TestGraphTraversal and testGraphCacheForEachNodeChannel) to pass WithUseGraphCache(false) when constructing the test graph, instead of directly mutating graph.graphCache = nil afterward. A comment is also corrected. This is a code-quality/test-cleanup change with no runtime behavior change in production.
Changed components
graph/db/graph_test.goInspect captured patch +12 / −10
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index 501ff10..1c38b3e 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -1739,11 +1739,16 @@ func testForEachSourceNodeChannel(t *testing.T, v lnwire.GossipVersion) {
require.Empty(t, expectedSrcChans)
}
+// TestGraphTraversal tests that we can traverse the graph and find all
+// nodes and channels that we expect to find.
func TestGraphTraversal(t *testing.T) {
t.Parallel()
ctx := t.Context()
- graph := MakeTestGraph(t)
+ // If we turn the channel graph cache _off_, then iterate through the
+ // set of channels (to force the fall back), we should find all the
+ // channel as well as the nodes included.
+ graph := MakeTestGraph(t, WithUseGraphCache(false))
// We'd like to test some of the graph traversal capabilities within
// the DB, so we'll create a series of fake nodes to insert into the
@@ -1760,10 +1765,6 @@ func TestGraphTraversal(t *testing.T) {
nodeIndex[node.PubKeyBytes] = struct{}{}
}
- // If we turn the channel graph cache _off_, then iterate through the
- // set of channels (to force the fall back), we should find all the
- // channel as well as the nodes included.
- graph.graphCache = nil
err := graph.ForEachNodeCached(ctx, lnwire.GossipVersion1, false,
func(_ context.Context, node route.Vertex, _ []net.Addr,
chans map[uint64]*DirectedChannel) error {
@@ -5022,7 +5023,7 @@ func BenchmarkForEachChannel(b *testing.B) {
}
}
-// TestGraphCacheForEachNodeChannel tests that the forEachNodeDirectedChannel
+// TestForEachNodeDirectedChannel tests that the ForEachNodeDirectedChannel
// method works as expected, and is able to handle nil self edges.
func testGraphCacheForEachNodeChannel(t *testing.T,
v lnwire.GossipVersion) {
@@ -5030,11 +5031,12 @@ func testGraphCacheForEachNodeChannel(t *testing.T,
t.Parallel()
ctx := t.Context()
- graph := NewVersionedGraph(MakeTestGraph(t), v)
-
// Unset the channel graph cache to simulate the user running with the
- // option turned off.
- graph.graphCache = nil
+ // option turned off. This forces the V1Store ForEachNodeDirectedChannel
+ // to be queried instead of the graph cache's ForEachChannel method.
+ graph := NewVersionedGraph(
+ MakeTestGraph(t, WithUseGraphCache(false)), v,
+ )
node1 := createTestVertex(t, v)
require.NoError(t, graph.AddNode(ctx, node1))
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.