sqldb/sqlc: add IsPublicV2Node query

Add SQL query to determine if a node has public v2 channels. Unlike
v1 which requires all four individual signatures, v2 channels are
considered public when the single aggregated signature is present.
This commit is contained in:
Elle Mouton committed 2026-02-13 07:21:23 +02:00
1 parent b3cf9a806f
commit a99604c7d7
3 files changed
+53

No files matched your search

+30
View File
@@ -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
+1
View File
@@ -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)
+22
View File
@@ -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