What changed, and why it matters
This commit adds a new database query helper that checks whether a Lightning node has any 'version 2' public channels. It is purely additive and does not change any existing behavior or fix a known bug. There is no indication in the commit that this is a security patch.
No security action required. Review the new query for correctness and consistency with the existing IsPublicV1Node logic during normal code review.
Security signals we found
No security-relevant signals observed in the diff or commit message.
Change is additive only and introduces no new attack surface by itself.
Evidence from the diff
The patch introduces IsPublicV2Node, a SQL-generated Go method that returns true if a node (identified by public key) appears as either endpoint of a graph_channels row where version = 2 and a channel signature is present. The logic mirrors the existing IsPublicV1Node helper but uses the single aggregated signature field for v2 channels instead of the four individual signatures required by v1. The change adds the SQL query, the generated Go code, and the method to the Querier interface. No call sites, business logic, or access controls are modified.
Changed components
sqldb/sqlc/graph.sql.gosqldb/sqlc/querier.gosqldb/sqlc/queries/graph.sqlInspect captured patch +53 / −0
diff --git a/sqldb/sqlc/graph.sql.go b/sqldb/sqlc/graph.sql.go
index c08ba96..135f00d 100644
--- a/sqldb/sqlc/graph.sql.go
+++ b/sqldb/sqlc/graph.sql.go
@@ -2751,6 +2751,36 @@ func (q *Queries) IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, erro
return exists, err
}
+const isPublicV2Node = `-- name: IsPublicV2Node :one
+SELECT EXISTS (
+ SELECT 1
+ FROM graph_channels c
+ JOIN graph_nodes n ON n.id = c.node_id_1
+ -- NOTE: we hard-code the version here since the clauses
+ -- here that determine if a node is public is specific
+ -- to the V2 gossip protocol.
+ WHERE c.version = 2
+ AND c.signature IS NOT NULL
+ AND n.pub_key = $1
+
+ UNION ALL
+
+ SELECT 1
+ FROM graph_channels c
+ JOIN graph_nodes n ON n.id = c.node_id_2
+ WHERE c.version = 2
+ AND COALESCE(length(c.signature), 0) > 0
+ AND n.pub_key = $1
+)
+`
+
+func (q *Queries) IsPublicV2Node(ctx context.Context, pubKey []byte) (bool, error) {
+ row := q.db.QueryRowContext(ctx, isPublicV2Node, pubKey)
+ var exists bool
+ err := row.Scan(&exists)
+ return exists, err
+}
+
const isZombieChannel = `-- name: IsZombieChannel :one
SELECT EXISTS (
SELECT 1
diff --git a/sqldb/sqlc/querier.go b/sqldb/sqlc/querier.go
index 05bf918..d26f845 100644
--- a/sqldb/sqlc/querier.go
+++ b/sqldb/sqlc/querier.go
@@ -117,6 +117,7 @@ type Querier interface {
InsertNodeMig(ctx context.Context, arg InsertNodeMigParams) (int64, error)
IsClosedChannel(ctx context.Context, scid []byte) (bool, error)
IsPublicV1Node(ctx context.Context, pubKey []byte) (bool, error)
+ IsPublicV2Node(ctx context.Context, pubKey []byte) (bool, error)
IsZombieChannel(ctx context.Context, arg IsZombieChannelParams) (bool, error)
ListChannelsByNodeID(ctx context.Context, arg ListChannelsByNodeIDParams) ([]ListChannelsByNodeIDRow, error)
ListChannelsForNodeIDs(ctx context.Context, arg ListChannelsForNodeIDsParams) ([]ListChannelsForNodeIDsRow, error)
diff --git a/sqldb/sqlc/queries/graph.sql b/sqldb/sqlc/queries/graph.sql
index 4f71fc8..1817fbf 100644
--- a/sqldb/sqlc/queries/graph.sql
+++ b/sqldb/sqlc/queries/graph.sql
@@ -112,6 +112,28 @@ SELECT EXISTS (
AND n.pub_key = $1
);
+-- name: IsPublicV2Node :one
+SELECT EXISTS (
+ SELECT 1
+ FROM graph_channels c
+ JOIN graph_nodes n ON n.id = c.node_id_1
+ -- NOTE: we hard-code the version here since the clauses
+ -- here that determine if a node is public is specific
+ -- to the V2 gossip protocol.
+ WHERE c.version = 2
+ AND c.signature IS NOT NULL
+ AND n.pub_key = $1
+
+ UNION ALL
+
+ SELECT 1
+ FROM graph_channels c
+ JOIN graph_nodes n ON n.id = c.node_id_2
+ WHERE c.version = 2
+ AND COALESCE(length(c.signature), 0) > 0
+ AND n.pub_key = $1
+);
+
-- name: DeleteUnconnectedNodes :many
DELETE FROM graph_nodes
WHERE
Why this scored 3/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.