graphdb: add benchmark for isPublicNode query
What changed, and why it matters
This commit only adds a new performance benchmark test for an existing database query. It does not change any production code, fix any bug, or alter any behavior that users or attackers could interact with.
No security action needed. This is a test-only change and can be reviewed as ordinary code quality / performance testing work.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a single benchmark function, BenchmarkIsPublicNode, to graph/db/graph_test.go. It creates a test graph, fills it with synthetic nodes and channels, and repeatedly calls graph.IsPublicNode to measure performance. No implementation code is modified, no APIs are changed, and no security-sensitive logic is introduced.
Changed components
graph/db/graph_test.goInspect captured patch +24 / −0
diff --git a/graph/db/graph_test.go b/graph/db/graph_test.go
index 590c077..3e5c931 100644
--- a/graph/db/graph_test.go
+++ b/graph/db/graph_test.go
@@ -1640,6 +1640,8 @@ func TestGraphCacheTraversal(t *testing.T) {
require.Equal(t, numChannels*2*(numNodes-1), numNodeChans)
}
+// fillTestGraph fills the graph with a given number of nodes and create a given
+// number of channels between each node.
func fillTestGraph(t testing.TB, graph *ChannelGraph, numNodes,
numChannels int) (map[uint64]struct{}, []*models.Node) {
@@ -4042,6 +4044,28 @@ func TestNodeIsPublic(t *testing.T) {
)
}
+// BenchmarkIsPublicNode measures the performance of IsPublicNode when checking
+// a large number of nodes.
+func BenchmarkIsPublicNode(b *testing.B) {
+ graph := MakeTestGraph(b)
+
+ // Create a graph with a reasonable number of nodes and channels.
+ numNodes := 100
+ numChans := 4
+ _, nodes := fillTestGraph(b, graph, numNodes, numChans)
+
+ // Use deterministic random number generator for reproducible results.
+ rng := prand.New(prand.NewSource(42))
+
+ for b.Loop() {
+ // Query random nodes to avoid query caching and better
+ // represent real-world query patterns.
+ nodePub := nodes[rng.Intn(len(nodes))].PubKeyBytes
+ _, err := graph.IsPublicNode(nodePub)
+ require.NoError(b, err)
+ }
+}
+
// TestDisabledChannelIDs ensures that the disabled channels within the
// disabledEdgePolicyBucket are managed properly and the list returned from
// DisabledChannelIDs is correct.
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.