2025-05-19 11:13:23 +02:00
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_nodes table queries
|
|
|
|
|
|
───────────────────────────<EFBFBD><EFBFBD>─────────────────
|
2025-05-19 11:13:23 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: UpsertNode :one
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_nodes (
|
2025-05-19 11:13:23 +02:00
|
|
|
|
version, pub_key, alias, last_update, color, signature
|
|
|
|
|
|
) VALUES (
|
|
|
|
|
|
$1, $2, $3, $4, $5, $6
|
|
|
|
|
|
)
|
|
|
|
|
|
ON CONFLICT (pub_key, version)
|
|
|
|
|
|
-- Update the following fields if a conflict occurs on pub_key
|
|
|
|
|
|
-- and version.
|
|
|
|
|
|
DO UPDATE SET
|
|
|
|
|
|
alias = EXCLUDED.alias,
|
|
|
|
|
|
last_update = EXCLUDED.last_update,
|
|
|
|
|
|
color = EXCLUDED.color,
|
|
|
|
|
|
signature = EXCLUDED.signature
|
2025-07-15 17:44:23 +02:00
|
|
|
|
WHERE graph_nodes.last_update IS NULL
|
|
|
|
|
|
OR EXCLUDED.last_update > graph_nodes.last_update
|
2025-05-19 11:13:23 +02:00
|
|
|
|
RETURNING id;
|
|
|
|
|
|
|
|
|
|
|
|
-- name: GetNodeByPubKey :one
|
|
|
|
|
|
SELECT *
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_nodes
|
2025-05-19 11:13:23 +02:00
|
|
|
|
WHERE pub_key = $1
|
|
|
|
|
|
AND version = $2;
|
|
|
|
|
|
|
2025-06-11 16:12:08 +02:00
|
|
|
|
-- name: GetNodeIDByPubKey :one
|
|
|
|
|
|
SELECT id
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_nodes
|
2025-06-11 16:12:08 +02:00
|
|
|
|
WHERE pub_key = $1
|
|
|
|
|
|
AND version = $2;
|
|
|
|
|
|
|
2025-06-11 15:59:43 +02:00
|
|
|
|
-- name: ListNodesPaginated :many
|
|
|
|
|
|
SELECT *
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_nodes
|
2025-06-11 15:59:43 +02:00
|
|
|
|
WHERE version = $1 AND id > $2
|
|
|
|
|
|
ORDER BY id
|
|
|
|
|
|
LIMIT $3;
|
|
|
|
|
|
|
2025-06-11 16:12:08 +02:00
|
|
|
|
-- name: ListNodeIDsAndPubKeys :many
|
|
|
|
|
|
SELECT id, pub_key
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_nodes
|
2025-06-11 16:12:08 +02:00
|
|
|
|
WHERE version = $1 AND id > $2
|
|
|
|
|
|
ORDER BY id
|
|
|
|
|
|
LIMIT $3;
|
|
|
|
|
|
|
2025-06-11 17:29:47 +02:00
|
|
|
|
-- name: IsPublicV1Node :one
|
|
|
|
|
|
SELECT EXISTS (
|
|
|
|
|
|
SELECT 1
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
|
2025-06-11 17:29:47 +02:00
|
|
|
|
-- NOTE: we hard-code the version here since the clauses
|
|
|
|
|
|
-- here that determine if a node is public is specific
|
|
|
|
|
|
-- to the V1 gossip protocol. In V1, a node is public
|
|
|
|
|
|
-- if it has a public channel and a public channel is one
|
|
|
|
|
|
-- where we have the set of signatures of the channel
|
|
|
|
|
|
-- announcement. It is enough to just check that we have
|
|
|
|
|
|
-- one of the signatures since we only ever set them
|
|
|
|
|
|
-- together.
|
|
|
|
|
|
WHERE c.version = 1
|
|
|
|
|
|
AND c.bitcoin_1_signature IS NOT NULL
|
|
|
|
|
|
AND n.pub_key = $1
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2025-06-26 10:10:10 +02:00
|
|
|
|
-- name: DeleteUnconnectedNodes :many
|
2025-07-15 17:44:23 +02:00
|
|
|
|
DELETE FROM graph_nodes
|
2025-06-26 10:10:10 +02:00
|
|
|
|
WHERE
|
|
|
|
|
|
-- Ignore any of our source nodes.
|
|
|
|
|
|
NOT EXISTS (
|
|
|
|
|
|
SELECT 1
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_source_nodes sn
|
|
|
|
|
|
WHERE sn.node_id = graph_nodes.id
|
2025-06-26 10:10:10 +02:00
|
|
|
|
)
|
|
|
|
|
|
-- Select all nodes that do not have any channels.
|
|
|
|
|
|
AND NOT EXISTS (
|
|
|
|
|
|
SELECT 1
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
WHERE c.node_id_1 = graph_nodes.id OR c.node_id_2 = graph_nodes.id
|
2025-06-26 10:10:10 +02:00
|
|
|
|
) RETURNING pub_key;
|
2025-06-11 17:41:27 +02:00
|
|
|
|
|
2025-05-19 11:13:23 +02:00
|
|
|
|
-- name: DeleteNodeByPubKey :execresult
|
2025-07-15 17:44:23 +02:00
|
|
|
|
DELETE FROM graph_nodes
|
2025-05-19 11:13:23 +02:00
|
|
|
|
WHERE pub_key = $1
|
|
|
|
|
|
AND version = $2;
|
|
|
|
|
|
|
2025-06-11 17:41:27 +02:00
|
|
|
|
-- name: DeleteNode :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
DELETE FROM graph_nodes
|
2025-06-11 17:41:27 +02:00
|
|
|
|
WHERE id = $1;
|
|
|
|
|
|
|
2025-05-19 11:13:23 +02:00
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_node_features table queries
|
2025-05-19 11:13:23 +02:00
|
|
|
|
─────────────────────────────────────────────
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: InsertNodeFeature :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_node_features (
|
2025-05-19 11:13:23 +02:00
|
|
|
|
node_id, feature_bit
|
|
|
|
|
|
) VALUES (
|
|
|
|
|
|
$1, $2
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
-- name: GetNodeFeatures :many
|
|
|
|
|
|
SELECT *
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_node_features
|
2025-05-19 11:13:23 +02:00
|
|
|
|
WHERE node_id = $1;
|
|
|
|
|
|
|
|
|
|
|
|
-- name: GetNodeFeaturesByPubKey :many
|
|
|
|
|
|
SELECT f.feature_bit
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_nodes n
|
|
|
|
|
|
JOIN graph_node_features f ON f.node_id = n.id
|
2025-05-19 11:13:23 +02:00
|
|
|
|
WHERE n.pub_key = $1
|
|
|
|
|
|
AND n.version = $2;
|
|
|
|
|
|
|
2025-07-29 07:45:49 +02:00
|
|
|
|
-- name: GetNodeFeaturesBatch :many
|
|
|
|
|
|
SELECT node_id, feature_bit
|
|
|
|
|
|
FROM graph_node_features
|
|
|
|
|
|
WHERE node_id IN (sqlc.slice('ids')/*SLICE:ids*/)
|
|
|
|
|
|
ORDER BY node_id, feature_bit;
|
|
|
|
|
|
|
2025-05-19 11:13:23 +02:00
|
|
|
|
-- name: DeleteNodeFeature :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
DELETE FROM graph_node_features
|
2025-05-19 11:13:23 +02:00
|
|
|
|
WHERE node_id = $1
|
|
|
|
|
|
AND feature_bit = $2;
|
|
|
|
|
|
|
|
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_node_addresses table queries
|
|
|
|
|
|
───────────────────────────────────<EFBFBD><EFBFBD>─────────
|
2025-05-19 11:13:23 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: InsertNodeAddress :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_node_addresses (
|
2025-05-19 11:13:23 +02:00
|
|
|
|
node_id,
|
|
|
|
|
|
type,
|
|
|
|
|
|
address,
|
|
|
|
|
|
position
|
|
|
|
|
|
) VALUES (
|
|
|
|
|
|
$1, $2, $3, $4
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2025-07-28 10:17:56 +02:00
|
|
|
|
-- name: GetNodeAddresses :many
|
|
|
|
|
|
SELECT type, address
|
|
|
|
|
|
FROM graph_node_addresses
|
|
|
|
|
|
WHERE node_id = $1
|
|
|
|
|
|
ORDER BY type ASC, position ASC;
|
2025-05-19 11:13:23 +02:00
|
|
|
|
|
2025-07-29 07:45:49 +02:00
|
|
|
|
-- name: GetNodeAddressesBatch :many
|
|
|
|
|
|
SELECT node_id, type, position, address
|
|
|
|
|
|
FROM graph_node_addresses
|
|
|
|
|
|
WHERE node_id IN (sqlc.slice('ids')/*SLICE:ids*/)
|
|
|
|
|
|
ORDER BY node_id, type, position;
|
|
|
|
|
|
|
2025-05-19 11:38:06 +02:00
|
|
|
|
-- name: GetNodesByLastUpdateRange :many
|
|
|
|
|
|
SELECT *
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_nodes
|
2025-05-19 11:38:06 +02:00
|
|
|
|
WHERE last_update >= @start_time
|
|
|
|
|
|
AND last_update < @end_time;
|
|
|
|
|
|
|
2025-05-19 11:13:23 +02:00
|
|
|
|
-- name: DeleteNodeAddresses :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
DELETE FROM graph_node_addresses
|
2025-05-19 11:13:23 +02:00
|
|
|
|
WHERE node_id = $1;
|
|
|
|
|
|
|
|
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_node_extra_types table queries
|
2025-05-19 11:13:23 +02:00
|
|
|
|
─────────────────────────────────────────────
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: UpsertNodeExtraType :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_node_extra_types (
|
2025-05-19 11:13:23 +02:00
|
|
|
|
node_id, type, value
|
|
|
|
|
|
)
|
|
|
|
|
|
VALUES ($1, $2, $3)
|
|
|
|
|
|
ON CONFLICT (type, node_id)
|
|
|
|
|
|
-- Update the value if a conflict occurs on type
|
|
|
|
|
|
-- and node_id.
|
|
|
|
|
|
DO UPDATE SET value = EXCLUDED.value;
|
|
|
|
|
|
|
|
|
|
|
|
-- name: GetExtraNodeTypes :many
|
|
|
|
|
|
SELECT *
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_node_extra_types
|
2025-05-19 11:13:23 +02:00
|
|
|
|
WHERE node_id = $1;
|
|
|
|
|
|
|
2025-07-29 07:45:49 +02:00
|
|
|
|
-- name: GetNodeExtraTypesBatch :many
|
|
|
|
|
|
SELECT node_id, type, value
|
|
|
|
|
|
FROM graph_node_extra_types
|
|
|
|
|
|
WHERE node_id IN (sqlc.slice('ids')/*SLICE:ids*/)
|
|
|
|
|
|
ORDER BY node_id, type;
|
|
|
|
|
|
|
2025-05-19 11:13:23 +02:00
|
|
|
|
-- name: DeleteExtraNodeType :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
DELETE FROM graph_node_extra_types
|
2025-05-19 11:13:23 +02:00
|
|
|
|
WHERE node_id = $1
|
|
|
|
|
|
AND type = $2;
|
2025-05-19 12:11:15 +02:00
|
|
|
|
|
|
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_source_nodes table queries
|
2025-05-19 12:11:15 +02:00
|
|
|
|
─────────────────────────────────────────────
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: AddSourceNode :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_source_nodes (node_id)
|
2025-05-19 12:11:15 +02:00
|
|
|
|
VALUES ($1)
|
|
|
|
|
|
ON CONFLICT (node_id) DO NOTHING;
|
|
|
|
|
|
|
|
|
|
|
|
-- name: GetSourceNodesByVersion :many
|
|
|
|
|
|
SELECT sn.node_id, n.pub_key
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_source_nodes sn
|
|
|
|
|
|
JOIN graph_nodes n ON sn.node_id = n.id
|
2025-05-19 12:11:15 +02:00
|
|
|
|
WHERE n.version = $1;
|
2025-05-24 15:09:37 +02:00
|
|
|
|
|
|
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_channels table queries
|
2025-05-24 15:09:37 +02:00
|
|
|
|
─────────────────────────────────────────────
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: CreateChannel :one
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_channels (
|
2025-05-24 15:09:37 +02:00
|
|
|
|
version, scid, node_id_1, node_id_2,
|
|
|
|
|
|
outpoint, capacity, bitcoin_key_1, bitcoin_key_2,
|
|
|
|
|
|
node_1_signature, node_2_signature, bitcoin_1_signature,
|
|
|
|
|
|
bitcoin_2_signature
|
|
|
|
|
|
) VALUES (
|
|
|
|
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12
|
|
|
|
|
|
)
|
|
|
|
|
|
RETURNING id;
|
|
|
|
|
|
|
2025-06-11 17:52:20 +02:00
|
|
|
|
-- name: AddV1ChannelProof :execresult
|
2025-07-15 17:44:23 +02:00
|
|
|
|
UPDATE graph_channels
|
2025-06-11 17:52:20 +02:00
|
|
|
|
SET node_1_signature = $2,
|
|
|
|
|
|
node_2_signature = $3,
|
|
|
|
|
|
bitcoin_1_signature = $4,
|
|
|
|
|
|
bitcoin_2_signature = $5
|
|
|
|
|
|
WHERE scid = $1
|
|
|
|
|
|
AND version = 1;
|
|
|
|
|
|
|
2025-06-11 17:50:26 +02:00
|
|
|
|
-- name: GetChannelsBySCIDRange :many
|
|
|
|
|
|
SELECT sqlc.embed(c),
|
|
|
|
|
|
n1.pub_key AS node1_pub_key,
|
|
|
|
|
|
n2.pub_key AS node2_pub_key
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
2025-06-11 17:50:26 +02:00
|
|
|
|
WHERE scid >= @start_scid
|
|
|
|
|
|
AND scid < @end_scid;
|
|
|
|
|
|
|
2025-05-24 15:09:37 +02:00
|
|
|
|
-- name: GetChannelBySCID :one
|
2025-07-15 17:44:23 +02:00
|
|
|
|
SELECT * FROM graph_channels
|
2025-05-24 15:09:37 +02:00
|
|
|
|
WHERE scid = $1 AND version = $2;
|
|
|
|
|
|
|
2025-07-15 15:30:45 +02:00
|
|
|
|
-- name: GetChannelsBySCIDs :many
|
|
|
|
|
|
SELECT * FROM graph_channels
|
|
|
|
|
|
WHERE version = @version
|
|
|
|
|
|
AND scid IN (sqlc.slice('scids')/*SLICE:scids*/);
|
|
|
|
|
|
|
2025-07-16 08:29:40 +02:00
|
|
|
|
-- name: GetChannelsByOutpoints :many
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
sqlc.embed(c),
|
|
|
|
|
|
n1.pub_key AS node1_pubkey,
|
|
|
|
|
|
n2.pub_key AS node2_pubkey
|
|
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
|
|
|
|
|
WHERE c.outpoint IN
|
|
|
|
|
|
(sqlc.slice('outpoints')/*SLICE:outpoints*/);
|
|
|
|
|
|
|
2025-06-11 14:25:39 +02:00
|
|
|
|
-- name: GetChannelAndNodesBySCID :one
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
c.*,
|
|
|
|
|
|
n1.pub_key AS node1_pub_key,
|
|
|
|
|
|
n2.pub_key AS node2_pub_key
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
2025-06-11 14:25:39 +02:00
|
|
|
|
WHERE c.scid = $1
|
|
|
|
|
|
AND c.version = $2;
|
|
|
|
|
|
|
2025-06-11 17:20:44 +02:00
|
|
|
|
-- name: GetSCIDByOutpoint :one
|
2025-07-15 17:44:23 +02:00
|
|
|
|
SELECT scid from graph_channels
|
2025-06-11 17:20:44 +02:00
|
|
|
|
WHERE outpoint = $1 AND version = $2;
|
|
|
|
|
|
|
2025-07-15 16:17:53 +02:00
|
|
|
|
-- name: GetChannelsBySCIDWithPolicies :many
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
sqlc.embed(c),
|
|
|
|
|
|
sqlc.embed(n1),
|
|
|
|
|
|
sqlc.embed(n2),
|
|
|
|
|
|
|
|
|
|
|
|
-- Policy 1
|
|
|
|
|
|
cp1.id AS policy1_id,
|
|
|
|
|
|
cp1.node_id AS policy1_node_id,
|
|
|
|
|
|
cp1.version AS policy1_version,
|
|
|
|
|
|
cp1.timelock AS policy1_timelock,
|
|
|
|
|
|
cp1.fee_ppm AS policy1_fee_ppm,
|
|
|
|
|
|
cp1.base_fee_msat AS policy1_base_fee_msat,
|
|
|
|
|
|
cp1.min_htlc_msat AS policy1_min_htlc_msat,
|
|
|
|
|
|
cp1.max_htlc_msat AS policy1_max_htlc_msat,
|
|
|
|
|
|
cp1.last_update AS policy1_last_update,
|
|
|
|
|
|
cp1.disabled AS policy1_disabled,
|
|
|
|
|
|
cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
|
|
|
|
|
|
cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
|
|
|
|
|
|
cp1.message_flags AS policy1_message_flags,
|
|
|
|
|
|
cp1.channel_flags AS policy1_channel_flags,
|
|
|
|
|
|
cp1.signature AS policy1_signature,
|
|
|
|
|
|
|
|
|
|
|
|
-- Policy 2
|
|
|
|
|
|
cp2.id AS policy2_id,
|
|
|
|
|
|
cp2.node_id AS policy2_node_id,
|
|
|
|
|
|
cp2.version AS policy2_version,
|
|
|
|
|
|
cp2.timelock AS policy2_timelock,
|
|
|
|
|
|
cp2.fee_ppm AS policy2_fee_ppm,
|
|
|
|
|
|
cp2.base_fee_msat AS policy2_base_fee_msat,
|
|
|
|
|
|
cp2.min_htlc_msat AS policy2_min_htlc_msat,
|
|
|
|
|
|
cp2.max_htlc_msat AS policy2_max_htlc_msat,
|
|
|
|
|
|
cp2.last_update AS policy2_last_update,
|
|
|
|
|
|
cp2.disabled AS policy2_disabled,
|
|
|
|
|
|
cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
|
|
|
|
|
|
cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
|
|
|
|
|
|
cp2.message_flags AS policy_2_message_flags,
|
|
|
|
|
|
cp2.channel_flags AS policy_2_channel_flags,
|
|
|
|
|
|
cp2.signature AS policy2_signature
|
|
|
|
|
|
|
|
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp1
|
|
|
|
|
|
ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp2
|
|
|
|
|
|
ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
|
|
|
|
|
|
WHERE
|
|
|
|
|
|
c.version = @version
|
|
|
|
|
|
AND c.scid IN (sqlc.slice('scids')/*SLICE:scids*/);
|
|
|
|
|
|
|
2025-06-11 16:23:36 +02:00
|
|
|
|
-- name: GetChannelsByPolicyLastUpdateRange :many
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
sqlc.embed(c),
|
|
|
|
|
|
sqlc.embed(n1),
|
|
|
|
|
|
sqlc.embed(n2),
|
|
|
|
|
|
|
|
|
|
|
|
-- Policy 1 (node_id_1)
|
|
|
|
|
|
cp1.id AS policy1_id,
|
|
|
|
|
|
cp1.node_id AS policy1_node_id,
|
|
|
|
|
|
cp1.version AS policy1_version,
|
|
|
|
|
|
cp1.timelock AS policy1_timelock,
|
|
|
|
|
|
cp1.fee_ppm AS policy1_fee_ppm,
|
|
|
|
|
|
cp1.base_fee_msat AS policy1_base_fee_msat,
|
|
|
|
|
|
cp1.min_htlc_msat AS policy1_min_htlc_msat,
|
|
|
|
|
|
cp1.max_htlc_msat AS policy1_max_htlc_msat,
|
|
|
|
|
|
cp1.last_update AS policy1_last_update,
|
|
|
|
|
|
cp1.disabled AS policy1_disabled,
|
|
|
|
|
|
cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
|
|
|
|
|
|
cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
cp1.message_flags AS policy1_message_flags,
|
|
|
|
|
|
cp1.channel_flags AS policy1_channel_flags,
|
2025-06-11 16:23:36 +02:00
|
|
|
|
cp1.signature AS policy1_signature,
|
|
|
|
|
|
|
|
|
|
|
|
-- Policy 2 (node_id_2)
|
|
|
|
|
|
cp2.id AS policy2_id,
|
|
|
|
|
|
cp2.node_id AS policy2_node_id,
|
|
|
|
|
|
cp2.version AS policy2_version,
|
|
|
|
|
|
cp2.timelock AS policy2_timelock,
|
|
|
|
|
|
cp2.fee_ppm AS policy2_fee_ppm,
|
|
|
|
|
|
cp2.base_fee_msat AS policy2_base_fee_msat,
|
|
|
|
|
|
cp2.min_htlc_msat AS policy2_min_htlc_msat,
|
|
|
|
|
|
cp2.max_htlc_msat AS policy2_max_htlc_msat,
|
|
|
|
|
|
cp2.last_update AS policy2_last_update,
|
|
|
|
|
|
cp2.disabled AS policy2_disabled,
|
|
|
|
|
|
cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
|
|
|
|
|
|
cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
cp2.message_flags AS policy2_message_flags,
|
|
|
|
|
|
cp2.channel_flags AS policy2_channel_flags,
|
2025-06-11 16:23:36 +02:00
|
|
|
|
cp2.signature AS policy2_signature
|
|
|
|
|
|
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp1
|
2025-06-11 16:23:36 +02:00
|
|
|
|
ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
|
2025-07-15 17:44:23 +02:00
|
|
|
|
LEFT JOIN graph_channel_policies cp2
|
2025-06-11 16:23:36 +02:00
|
|
|
|
ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
|
|
|
|
|
|
WHERE c.version = @version
|
|
|
|
|
|
AND (
|
|
|
|
|
|
(cp1.last_update >= @start_time AND cp1.last_update < @end_time)
|
|
|
|
|
|
OR
|
|
|
|
|
|
(cp2.last_update >= @start_time AND cp2.last_update < @end_time)
|
|
|
|
|
|
)
|
|
|
|
|
|
ORDER BY
|
|
|
|
|
|
CASE
|
|
|
|
|
|
WHEN COALESCE(cp1.last_update, 0) >= COALESCE(cp2.last_update, 0)
|
|
|
|
|
|
THEN COALESCE(cp1.last_update, 0)
|
|
|
|
|
|
ELSE COALESCE(cp2.last_update, 0)
|
|
|
|
|
|
END ASC;
|
|
|
|
|
|
|
2025-06-11 17:14:41 +02:00
|
|
|
|
-- name: GetChannelByOutpointWithPolicies :one
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
sqlc.embed(c),
|
|
|
|
|
|
|
|
|
|
|
|
n1.pub_key AS node1_pubkey,
|
|
|
|
|
|
n2.pub_key AS node2_pubkey,
|
|
|
|
|
|
|
|
|
|
|
|
-- Node 1 policy
|
|
|
|
|
|
cp1.id AS policy_1_id,
|
|
|
|
|
|
cp1.node_id AS policy_1_node_id,
|
|
|
|
|
|
cp1.version AS policy_1_version,
|
|
|
|
|
|
cp1.timelock AS policy_1_timelock,
|
|
|
|
|
|
cp1.fee_ppm AS policy_1_fee_ppm,
|
|
|
|
|
|
cp1.base_fee_msat AS policy_1_base_fee_msat,
|
|
|
|
|
|
cp1.min_htlc_msat AS policy_1_min_htlc_msat,
|
|
|
|
|
|
cp1.max_htlc_msat AS policy_1_max_htlc_msat,
|
|
|
|
|
|
cp1.last_update AS policy_1_last_update,
|
|
|
|
|
|
cp1.disabled AS policy_1_disabled,
|
|
|
|
|
|
cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
|
|
|
|
|
|
cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
cp1.message_flags AS policy_1_message_flags,
|
|
|
|
|
|
cp1.channel_flags AS policy_1_channel_flags,
|
2025-06-11 17:14:41 +02:00
|
|
|
|
cp1.signature AS policy_1_signature,
|
|
|
|
|
|
|
|
|
|
|
|
-- Node 2 policy
|
|
|
|
|
|
cp2.id AS policy_2_id,
|
|
|
|
|
|
cp2.node_id AS policy_2_node_id,
|
|
|
|
|
|
cp2.version AS policy_2_version,
|
|
|
|
|
|
cp2.timelock AS policy_2_timelock,
|
|
|
|
|
|
cp2.fee_ppm AS policy_2_fee_ppm,
|
|
|
|
|
|
cp2.base_fee_msat AS policy_2_base_fee_msat,
|
|
|
|
|
|
cp2.min_htlc_msat AS policy_2_min_htlc_msat,
|
|
|
|
|
|
cp2.max_htlc_msat AS policy_2_max_htlc_msat,
|
|
|
|
|
|
cp2.last_update AS policy_2_last_update,
|
|
|
|
|
|
cp2.disabled AS policy_2_disabled,
|
|
|
|
|
|
cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
|
|
|
|
|
|
cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
cp2.message_flags AS policy_2_message_flags,
|
|
|
|
|
|
cp2.channel_flags AS policy_2_channel_flags,
|
2025-06-11 17:14:41 +02:00
|
|
|
|
cp2.signature AS policy_2_signature
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp1
|
2025-06-11 17:14:41 +02:00
|
|
|
|
ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
|
2025-07-15 17:44:23 +02:00
|
|
|
|
LEFT JOIN graph_channel_policies cp2
|
2025-06-11 17:14:41 +02:00
|
|
|
|
ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
|
|
|
|
|
|
WHERE c.outpoint = $1 AND c.version = $2;
|
|
|
|
|
|
|
2025-05-24 15:21:56 +02:00
|
|
|
|
-- name: HighestSCID :one
|
|
|
|
|
|
SELECT scid
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels
|
2025-05-24 15:21:56 +02:00
|
|
|
|
WHERE version = $1
|
|
|
|
|
|
ORDER BY scid DESC
|
|
|
|
|
|
LIMIT 1;
|
|
|
|
|
|
|
2025-08-01 14:48:32 +02:00
|
|
|
|
-- name: ListChannelsForNodeIDs :many
|
|
|
|
|
|
SELECT sqlc.embed(c),
|
|
|
|
|
|
n1.pub_key AS node1_pubkey,
|
|
|
|
|
|
n2.pub_key AS node2_pubkey,
|
|
|
|
|
|
|
|
|
|
|
|
-- Policy 1
|
|
|
|
|
|
-- TODO(elle): use sqlc.embed to embed policy structs
|
|
|
|
|
|
-- once this issue is resolved:
|
|
|
|
|
|
-- https://github.com/sqlc-dev/sqlc/issues/2997
|
|
|
|
|
|
cp1.id AS policy1_id,
|
|
|
|
|
|
cp1.node_id AS policy1_node_id,
|
|
|
|
|
|
cp1.version AS policy1_version,
|
|
|
|
|
|
cp1.timelock AS policy1_timelock,
|
|
|
|
|
|
cp1.fee_ppm AS policy1_fee_ppm,
|
|
|
|
|
|
cp1.base_fee_msat AS policy1_base_fee_msat,
|
|
|
|
|
|
cp1.min_htlc_msat AS policy1_min_htlc_msat,
|
|
|
|
|
|
cp1.max_htlc_msat AS policy1_max_htlc_msat,
|
|
|
|
|
|
cp1.last_update AS policy1_last_update,
|
|
|
|
|
|
cp1.disabled AS policy1_disabled,
|
|
|
|
|
|
cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
|
|
|
|
|
|
cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
|
|
|
|
|
|
cp1.message_flags AS policy1_message_flags,
|
|
|
|
|
|
cp1.channel_flags AS policy1_channel_flags,
|
|
|
|
|
|
cp1.signature AS policy1_signature,
|
|
|
|
|
|
|
|
|
|
|
|
-- Policy 2
|
|
|
|
|
|
cp2.id AS policy2_id,
|
|
|
|
|
|
cp2.node_id AS policy2_node_id,
|
|
|
|
|
|
cp2.version AS policy2_version,
|
|
|
|
|
|
cp2.timelock AS policy2_timelock,
|
|
|
|
|
|
cp2.fee_ppm AS policy2_fee_ppm,
|
|
|
|
|
|
cp2.base_fee_msat AS policy2_base_fee_msat,
|
|
|
|
|
|
cp2.min_htlc_msat AS policy2_min_htlc_msat,
|
|
|
|
|
|
cp2.max_htlc_msat AS policy2_max_htlc_msat,
|
|
|
|
|
|
cp2.last_update AS policy2_last_update,
|
|
|
|
|
|
cp2.disabled AS policy2_disabled,
|
|
|
|
|
|
cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
|
|
|
|
|
|
cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
|
|
|
|
|
|
cp2.message_flags AS policy2_message_flags,
|
|
|
|
|
|
cp2.channel_flags AS policy2_channel_flags,
|
|
|
|
|
|
cp2.signature AS policy2_signature
|
|
|
|
|
|
|
|
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp1
|
|
|
|
|
|
ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp2
|
|
|
|
|
|
ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
|
|
|
|
|
|
WHERE c.version = $1
|
|
|
|
|
|
AND (c.node_id_1 IN (sqlc.slice('node1_ids')/*SLICE:node1_ids*/)
|
|
|
|
|
|
OR c.node_id_2 IN (sqlc.slice('node2_ids')/*SLICE:node2_ids*/));
|
|
|
|
|
|
|
2025-06-11 15:40:10 +02:00
|
|
|
|
-- name: ListChannelsByNodeID :many
|
|
|
|
|
|
SELECT sqlc.embed(c),
|
|
|
|
|
|
n1.pub_key AS node1_pubkey,
|
|
|
|
|
|
n2.pub_key AS node2_pubkey,
|
|
|
|
|
|
|
|
|
|
|
|
-- Policy 1
|
|
|
|
|
|
-- TODO(elle): use sqlc.embed to embed policy structs
|
|
|
|
|
|
-- once this issue is resolved:
|
|
|
|
|
|
-- https://github.com/sqlc-dev/sqlc/issues/2997
|
|
|
|
|
|
cp1.id AS policy1_id,
|
|
|
|
|
|
cp1.node_id AS policy1_node_id,
|
|
|
|
|
|
cp1.version AS policy1_version,
|
|
|
|
|
|
cp1.timelock AS policy1_timelock,
|
|
|
|
|
|
cp1.fee_ppm AS policy1_fee_ppm,
|
|
|
|
|
|
cp1.base_fee_msat AS policy1_base_fee_msat,
|
|
|
|
|
|
cp1.min_htlc_msat AS policy1_min_htlc_msat,
|
|
|
|
|
|
cp1.max_htlc_msat AS policy1_max_htlc_msat,
|
|
|
|
|
|
cp1.last_update AS policy1_last_update,
|
|
|
|
|
|
cp1.disabled AS policy1_disabled,
|
|
|
|
|
|
cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
|
|
|
|
|
|
cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
cp1.message_flags AS policy1_message_flags,
|
|
|
|
|
|
cp1.channel_flags AS policy1_channel_flags,
|
2025-06-11 15:40:10 +02:00
|
|
|
|
cp1.signature AS policy1_signature,
|
|
|
|
|
|
|
|
|
|
|
|
-- Policy 2
|
|
|
|
|
|
cp2.id AS policy2_id,
|
|
|
|
|
|
cp2.node_id AS policy2_node_id,
|
|
|
|
|
|
cp2.version AS policy2_version,
|
|
|
|
|
|
cp2.timelock AS policy2_timelock,
|
|
|
|
|
|
cp2.fee_ppm AS policy2_fee_ppm,
|
|
|
|
|
|
cp2.base_fee_msat AS policy2_base_fee_msat,
|
|
|
|
|
|
cp2.min_htlc_msat AS policy2_min_htlc_msat,
|
|
|
|
|
|
cp2.max_htlc_msat AS policy2_max_htlc_msat,
|
|
|
|
|
|
cp2.last_update AS policy2_last_update,
|
|
|
|
|
|
cp2.disabled AS policy2_disabled,
|
|
|
|
|
|
cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
|
|
|
|
|
|
cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
cp2.message_flags AS policy2_message_flags,
|
|
|
|
|
|
cp2.channel_flags AS policy2_channel_flags,
|
2025-06-11 15:40:10 +02:00
|
|
|
|
cp2.signature AS policy2_signature
|
|
|
|
|
|
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp1
|
2025-06-11 15:40:10 +02:00
|
|
|
|
ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
|
2025-07-15 17:44:23 +02:00
|
|
|
|
LEFT JOIN graph_channel_policies cp2
|
2025-06-11 15:40:10 +02:00
|
|
|
|
ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
|
|
|
|
|
|
WHERE c.version = $1
|
|
|
|
|
|
AND (c.node_id_1 = $2 OR c.node_id_2 = $2);
|
|
|
|
|
|
|
2025-06-11 16:47:07 +02:00
|
|
|
|
-- name: GetPublicV1ChannelsBySCID :many
|
|
|
|
|
|
SELECT *
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels
|
2025-06-11 16:47:07 +02:00
|
|
|
|
WHERE node_1_signature IS NOT NULL
|
|
|
|
|
|
AND scid >= @start_scid
|
|
|
|
|
|
AND scid < @end_scid;
|
|
|
|
|
|
|
2025-06-11 17:46:37 +02:00
|
|
|
|
-- name: ListChannelsPaginated :many
|
|
|
|
|
|
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
2025-06-11 17:46:37 +02:00
|
|
|
|
WHERE c.version = $1 AND c.id > $2
|
|
|
|
|
|
ORDER BY c.id
|
|
|
|
|
|
LIMIT $3;
|
|
|
|
|
|
|
2025-06-11 16:41:13 +02:00
|
|
|
|
-- name: ListChannelsWithPoliciesPaginated :many
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
sqlc.embed(c),
|
|
|
|
|
|
|
|
|
|
|
|
-- Join node pubkeys
|
|
|
|
|
|
n1.pub_key AS node1_pubkey,
|
|
|
|
|
|
n2.pub_key AS node2_pubkey,
|
|
|
|
|
|
|
|
|
|
|
|
-- Node 1 policy
|
|
|
|
|
|
cp1.id AS policy_1_id,
|
|
|
|
|
|
cp1.node_id AS policy_1_node_id,
|
|
|
|
|
|
cp1.version AS policy_1_version,
|
|
|
|
|
|
cp1.timelock AS policy_1_timelock,
|
|
|
|
|
|
cp1.fee_ppm AS policy_1_fee_ppm,
|
|
|
|
|
|
cp1.base_fee_msat AS policy_1_base_fee_msat,
|
|
|
|
|
|
cp1.min_htlc_msat AS policy_1_min_htlc_msat,
|
|
|
|
|
|
cp1.max_htlc_msat AS policy_1_max_htlc_msat,
|
|
|
|
|
|
cp1.last_update AS policy_1_last_update,
|
|
|
|
|
|
cp1.disabled AS policy_1_disabled,
|
|
|
|
|
|
cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
|
|
|
|
|
|
cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
cp1.message_flags AS policy1_message_flags,
|
|
|
|
|
|
cp1.channel_flags AS policy1_channel_flags,
|
2025-06-11 16:41:13 +02:00
|
|
|
|
cp1.signature AS policy_1_signature,
|
|
|
|
|
|
|
|
|
|
|
|
-- Node 2 policy
|
|
|
|
|
|
cp2.id AS policy_2_id,
|
|
|
|
|
|
cp2.node_id AS policy_2_node_id,
|
|
|
|
|
|
cp2.version AS policy_2_version,
|
|
|
|
|
|
cp2.timelock AS policy_2_timelock,
|
|
|
|
|
|
cp2.fee_ppm AS policy_2_fee_ppm,
|
|
|
|
|
|
cp2.base_fee_msat AS policy_2_base_fee_msat,
|
|
|
|
|
|
cp2.min_htlc_msat AS policy_2_min_htlc_msat,
|
|
|
|
|
|
cp2.max_htlc_msat AS policy_2_max_htlc_msat,
|
|
|
|
|
|
cp2.last_update AS policy_2_last_update,
|
|
|
|
|
|
cp2.disabled AS policy_2_disabled,
|
|
|
|
|
|
cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
|
|
|
|
|
|
cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
cp2.message_flags AS policy2_message_flags,
|
|
|
|
|
|
cp2.channel_flags AS policy2_channel_flags,
|
2025-06-11 16:41:13 +02:00
|
|
|
|
cp2.signature AS policy_2_signature
|
|
|
|
|
|
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp1
|
2025-06-11 16:41:13 +02:00
|
|
|
|
ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
|
2025-07-15 17:44:23 +02:00
|
|
|
|
LEFT JOIN graph_channel_policies cp2
|
2025-06-11 16:41:13 +02:00
|
|
|
|
ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
|
|
|
|
|
|
WHERE c.version = $1 AND c.id > $2
|
|
|
|
|
|
ORDER BY c.id
|
|
|
|
|
|
LIMIT $3;
|
|
|
|
|
|
|
2025-07-28 10:04:00 +02:00
|
|
|
|
-- name: ListChannelsWithPoliciesForCachePaginated :many
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
c.id as id,
|
|
|
|
|
|
c.scid as scid,
|
|
|
|
|
|
c.capacity AS capacity,
|
|
|
|
|
|
|
|
|
|
|
|
-- Join node pubkeys
|
|
|
|
|
|
n1.pub_key AS node1_pubkey,
|
|
|
|
|
|
n2.pub_key AS node2_pubkey,
|
|
|
|
|
|
|
|
|
|
|
|
-- Node 1 policy
|
|
|
|
|
|
cp1.timelock AS policy_1_timelock,
|
|
|
|
|
|
cp1.fee_ppm AS policy_1_fee_ppm,
|
|
|
|
|
|
cp1.base_fee_msat AS policy_1_base_fee_msat,
|
|
|
|
|
|
cp1.min_htlc_msat AS policy_1_min_htlc_msat,
|
|
|
|
|
|
cp1.max_htlc_msat AS policy_1_max_htlc_msat,
|
|
|
|
|
|
cp1.disabled AS policy_1_disabled,
|
|
|
|
|
|
cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
|
|
|
|
|
|
cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
|
|
|
|
|
|
cp1.message_flags AS policy1_message_flags,
|
|
|
|
|
|
cp1.channel_flags AS policy1_channel_flags,
|
|
|
|
|
|
|
|
|
|
|
|
-- Node 2 policy
|
|
|
|
|
|
cp2.timelock AS policy_2_timelock,
|
|
|
|
|
|
cp2.fee_ppm AS policy_2_fee_ppm,
|
|
|
|
|
|
cp2.base_fee_msat AS policy_2_base_fee_msat,
|
|
|
|
|
|
cp2.min_htlc_msat AS policy_2_min_htlc_msat,
|
|
|
|
|
|
cp2.max_htlc_msat AS policy_2_max_htlc_msat,
|
|
|
|
|
|
cp2.disabled AS policy_2_disabled,
|
|
|
|
|
|
cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
|
|
|
|
|
|
cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
|
|
|
|
|
|
cp2.message_flags AS policy2_message_flags,
|
|
|
|
|
|
cp2.channel_flags AS policy2_channel_flags
|
|
|
|
|
|
|
|
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp1
|
|
|
|
|
|
ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp2
|
|
|
|
|
|
ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
|
|
|
|
|
|
WHERE c.version = $1 AND c.id > $2
|
|
|
|
|
|
ORDER BY c.id
|
|
|
|
|
|
LIMIT $3;
|
|
|
|
|
|
|
2025-07-18 11:47:25 +02:00
|
|
|
|
-- name: DeleteChannels :exec
|
|
|
|
|
|
DELETE FROM graph_channels
|
|
|
|
|
|
WHERE id IN (sqlc.slice('ids')/*SLICE:ids*/);
|
2025-06-11 17:10:12 +02:00
|
|
|
|
|
2025-05-24 15:09:37 +02:00
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_channel_features table queries
|
2025-05-24 15:09:37 +02:00
|
|
|
|
─────────────────────────────────────────────
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: InsertChannelFeature :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_channel_features (
|
2025-05-24 15:09:37 +02:00
|
|
|
|
channel_id, feature_bit
|
|
|
|
|
|
) VALUES (
|
|
|
|
|
|
$1, $2
|
|
|
|
|
|
);
|
|
|
|
|
|
|
2025-07-29 12:46:58 +02:00
|
|
|
|
-- name: GetChannelFeaturesBatch :many
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
channel_id,
|
|
|
|
|
|
feature_bit
|
|
|
|
|
|
FROM graph_channel_features
|
|
|
|
|
|
WHERE channel_id IN (sqlc.slice('chan_ids')/*SLICE:chan_ids*/)
|
|
|
|
|
|
ORDER BY channel_id, feature_bit;
|
|
|
|
|
|
|
2025-05-24 15:09:37 +02:00
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_channel_extra_types table queries
|
2025-05-24 15:09:37 +02:00
|
|
|
|
─────────────────────────────────────────────
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: CreateChannelExtraType :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_channel_extra_types (
|
2025-05-24 15:09:37 +02:00
|
|
|
|
channel_id, type, value
|
|
|
|
|
|
)
|
|
|
|
|
|
VALUES ($1, $2, $3);
|
2025-06-11 14:25:39 +02:00
|
|
|
|
|
2025-07-29 12:46:58 +02:00
|
|
|
|
-- name: GetChannelExtrasBatch :many
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
channel_id,
|
|
|
|
|
|
type,
|
|
|
|
|
|
value
|
|
|
|
|
|
FROM graph_channel_extra_types
|
|
|
|
|
|
WHERE channel_id IN (sqlc.slice('chan_ids')/*SLICE:chan_ids*/)
|
|
|
|
|
|
ORDER BY channel_id, type;
|
|
|
|
|
|
|
2025-06-11 14:25:39 +02:00
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_channel_policies table queries
|
2025-06-11 14:25:39 +02:00
|
|
|
|
─────────────────────────────────────────────
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: UpsertEdgePolicy :one
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_channel_policies (
|
2025-06-11 14:25:39 +02:00
|
|
|
|
version, channel_id, node_id, timelock, fee_ppm,
|
|
|
|
|
|
base_fee_msat, min_htlc_msat, last_update, disabled,
|
|
|
|
|
|
max_htlc_msat, inbound_base_fee_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
inbound_fee_rate_milli_msat, message_flags, channel_flags,
|
|
|
|
|
|
signature
|
2025-06-11 14:25:39 +02:00
|
|
|
|
) VALUES (
|
2025-06-30 11:27:34 +02:00
|
|
|
|
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
|
2025-06-11 14:25:39 +02:00
|
|
|
|
)
|
|
|
|
|
|
ON CONFLICT (channel_id, node_id, version)
|
|
|
|
|
|
-- Update the following fields if a conflict occurs on channel_id,
|
|
|
|
|
|
-- node_id, and version.
|
|
|
|
|
|
DO UPDATE SET
|
|
|
|
|
|
timelock = EXCLUDED.timelock,
|
|
|
|
|
|
fee_ppm = EXCLUDED.fee_ppm,
|
|
|
|
|
|
base_fee_msat = EXCLUDED.base_fee_msat,
|
|
|
|
|
|
min_htlc_msat = EXCLUDED.min_htlc_msat,
|
|
|
|
|
|
last_update = EXCLUDED.last_update,
|
|
|
|
|
|
disabled = EXCLUDED.disabled,
|
|
|
|
|
|
max_htlc_msat = EXCLUDED.max_htlc_msat,
|
|
|
|
|
|
inbound_base_fee_msat = EXCLUDED.inbound_base_fee_msat,
|
|
|
|
|
|
inbound_fee_rate_milli_msat = EXCLUDED.inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
message_flags = EXCLUDED.message_flags,
|
|
|
|
|
|
channel_flags = EXCLUDED.channel_flags,
|
2025-06-11 14:25:39 +02:00
|
|
|
|
signature = EXCLUDED.signature
|
2025-07-15 17:44:23 +02:00
|
|
|
|
WHERE EXCLUDED.last_update > graph_channel_policies.last_update
|
2025-06-11 14:25:39 +02:00
|
|
|
|
RETURNING id;
|
|
|
|
|
|
|
2025-06-11 16:47:07 +02:00
|
|
|
|
-- name: GetChannelPolicyByChannelAndNode :one
|
|
|
|
|
|
SELECT *
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channel_policies
|
2025-06-11 16:47:07 +02:00
|
|
|
|
WHERE channel_id = $1
|
|
|
|
|
|
AND node_id = $2
|
|
|
|
|
|
AND version = $3;
|
|
|
|
|
|
|
2025-06-11 17:10:12 +02:00
|
|
|
|
-- name: GetChannelBySCIDWithPolicies :one
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
sqlc.embed(c),
|
|
|
|
|
|
sqlc.embed(n1),
|
|
|
|
|
|
sqlc.embed(n2),
|
|
|
|
|
|
|
|
|
|
|
|
-- Policy 1
|
|
|
|
|
|
cp1.id AS policy1_id,
|
|
|
|
|
|
cp1.node_id AS policy1_node_id,
|
|
|
|
|
|
cp1.version AS policy1_version,
|
|
|
|
|
|
cp1.timelock AS policy1_timelock,
|
|
|
|
|
|
cp1.fee_ppm AS policy1_fee_ppm,
|
|
|
|
|
|
cp1.base_fee_msat AS policy1_base_fee_msat,
|
|
|
|
|
|
cp1.min_htlc_msat AS policy1_min_htlc_msat,
|
|
|
|
|
|
cp1.max_htlc_msat AS policy1_max_htlc_msat,
|
|
|
|
|
|
cp1.last_update AS policy1_last_update,
|
|
|
|
|
|
cp1.disabled AS policy1_disabled,
|
|
|
|
|
|
cp1.inbound_base_fee_msat AS policy1_inbound_base_fee_msat,
|
|
|
|
|
|
cp1.inbound_fee_rate_milli_msat AS policy1_inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
cp1.message_flags AS policy1_message_flags,
|
|
|
|
|
|
cp1.channel_flags AS policy1_channel_flags,
|
2025-06-11 17:10:12 +02:00
|
|
|
|
cp1.signature AS policy1_signature,
|
|
|
|
|
|
|
|
|
|
|
|
-- Policy 2
|
|
|
|
|
|
cp2.id AS policy2_id,
|
|
|
|
|
|
cp2.node_id AS policy2_node_id,
|
|
|
|
|
|
cp2.version AS policy2_version,
|
|
|
|
|
|
cp2.timelock AS policy2_timelock,
|
|
|
|
|
|
cp2.fee_ppm AS policy2_fee_ppm,
|
|
|
|
|
|
cp2.base_fee_msat AS policy2_base_fee_msat,
|
|
|
|
|
|
cp2.min_htlc_msat AS policy2_min_htlc_msat,
|
|
|
|
|
|
cp2.max_htlc_msat AS policy2_max_htlc_msat,
|
|
|
|
|
|
cp2.last_update AS policy2_last_update,
|
|
|
|
|
|
cp2.disabled AS policy2_disabled,
|
|
|
|
|
|
cp2.inbound_base_fee_msat AS policy2_inbound_base_fee_msat,
|
|
|
|
|
|
cp2.inbound_fee_rate_milli_msat AS policy2_inbound_fee_rate_milli_msat,
|
2025-06-30 11:27:34 +02:00
|
|
|
|
cp2.message_flags AS policy_2_message_flags,
|
|
|
|
|
|
cp2.channel_flags AS policy_2_channel_flags,
|
2025-06-11 17:10:12 +02:00
|
|
|
|
cp2.signature AS policy2_signature
|
|
|
|
|
|
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_nodes n1 ON c.node_id_1 = n1.id
|
|
|
|
|
|
JOIN graph_nodes n2 ON c.node_id_2 = n2.id
|
|
|
|
|
|
LEFT JOIN graph_channel_policies cp1
|
2025-06-11 17:10:12 +02:00
|
|
|
|
ON cp1.channel_id = c.id AND cp1.node_id = c.node_id_1 AND cp1.version = c.version
|
2025-07-15 17:44:23 +02:00
|
|
|
|
LEFT JOIN graph_channel_policies cp2
|
2025-06-11 17:10:12 +02:00
|
|
|
|
ON cp2.channel_id = c.id AND cp2.node_id = c.node_id_2 AND cp2.version = c.version
|
|
|
|
|
|
WHERE c.scid = @scid
|
|
|
|
|
|
AND c.version = @version;
|
|
|
|
|
|
|
2025-06-11 14:25:39 +02:00
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_channel_policy_extra_types table queries
|
2025-06-11 14:25:39 +02:00
|
|
|
|
─────────────────────────────────────────────
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: InsertChanPolicyExtraType :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_channel_policy_extra_types (
|
2025-06-11 14:25:39 +02:00
|
|
|
|
channel_policy_id, type, value
|
|
|
|
|
|
)
|
|
|
|
|
|
VALUES ($1, $2, $3);
|
|
|
|
|
|
|
2025-07-29 12:46:58 +02:00
|
|
|
|
-- name: GetChannelPolicyExtraTypesBatch :many
|
|
|
|
|
|
SELECT
|
|
|
|
|
|
channel_policy_id as policy_id,
|
|
|
|
|
|
type,
|
|
|
|
|
|
value
|
|
|
|
|
|
FROM graph_channel_policy_extra_types
|
|
|
|
|
|
WHERE channel_policy_id IN (sqlc.slice('policy_ids')/*SLICE:policy_ids*/)
|
|
|
|
|
|
ORDER BY channel_policy_id, type;
|
|
|
|
|
|
|
2025-06-11 17:32:06 +02:00
|
|
|
|
-- name: GetV1DisabledSCIDs :many
|
|
|
|
|
|
SELECT c.scid
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_channels c
|
|
|
|
|
|
JOIN graph_channel_policies cp ON cp.channel_id = c.id
|
2025-06-11 17:32:06 +02:00
|
|
|
|
-- NOTE: this is V1 specific since for V1, disabled is a
|
|
|
|
|
|
-- simple, single boolean. The proposed V2 policy
|
|
|
|
|
|
-- structure will have a more complex disabled bit vector
|
|
|
|
|
|
-- and so the query for V2 may differ.
|
|
|
|
|
|
WHERE cp.disabled = true
|
|
|
|
|
|
AND c.version = 1
|
|
|
|
|
|
GROUP BY c.scid
|
|
|
|
|
|
HAVING COUNT(*) > 1;
|
|
|
|
|
|
|
2025-06-11 14:25:39 +02:00
|
|
|
|
-- name: DeleteChannelPolicyExtraTypes :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
DELETE FROM graph_channel_policy_extra_types
|
2025-06-11 14:25:39 +02:00
|
|
|
|
WHERE channel_policy_id = $1;
|
2025-06-11 17:04:21 +02:00
|
|
|
|
|
|
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_zombie_channels table queries
|
2025-06-11 17:04:21 +02:00
|
|
|
|
─────────────────────────────────────────────
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: UpsertZombieChannel :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
|
2025-06-11 17:04:21 +02:00
|
|
|
|
VALUES ($1, $2, $3, $4)
|
|
|
|
|
|
ON CONFLICT (scid, version)
|
|
|
|
|
|
DO UPDATE SET
|
|
|
|
|
|
-- If a conflict exists for the SCID and version pair, then we
|
|
|
|
|
|
-- update the node keys.
|
2025-07-15 17:44:23 +02:00
|
|
|
|
node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
|
|
|
|
|
|
node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2);
|
2025-06-11 17:04:21 +02:00
|
|
|
|
|
|
|
|
|
|
-- name: DeleteZombieChannel :execresult
|
2025-07-15 17:44:23 +02:00
|
|
|
|
DELETE FROM graph_zombie_channels
|
2025-06-11 17:04:21 +02:00
|
|
|
|
WHERE scid = $1
|
|
|
|
|
|
AND version = $2;
|
|
|
|
|
|
|
|
|
|
|
|
-- name: CountZombieChannels :one
|
|
|
|
|
|
SELECT COUNT(*)
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_zombie_channels
|
2025-06-11 17:04:21 +02:00
|
|
|
|
WHERE version = $1;
|
|
|
|
|
|
|
|
|
|
|
|
-- name: GetZombieChannel :one
|
|
|
|
|
|
SELECT *
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_zombie_channels
|
2025-06-11 17:04:21 +02:00
|
|
|
|
WHERE scid = $1
|
|
|
|
|
|
AND version = $2;
|
2025-06-11 17:14:41 +02:00
|
|
|
|
|
|
|
|
|
|
-- name: IsZombieChannel :one
|
|
|
|
|
|
SELECT EXISTS (
|
|
|
|
|
|
SELECT 1
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_zombie_channels
|
2025-06-11 17:14:41 +02:00
|
|
|
|
WHERE scid = $1
|
|
|
|
|
|
AND version = $2
|
|
|
|
|
|
) AS is_zombie;
|
2025-06-11 17:46:37 +02:00
|
|
|
|
|
2025-07-15 17:44:23 +02:00
|
|
|
|
/* ───────────────────────────<E29480><E29480><EFBFBD>─────────────────
|
|
|
|
|
|
graph_prune_log table queries
|
2025-06-11 17:46:37 +02:00
|
|
|
|
─────────────────────────────────────────────
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: UpsertPruneLogEntry :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_prune_log (
|
2025-06-11 17:46:37 +02:00
|
|
|
|
block_height, block_hash
|
|
|
|
|
|
) VALUES (
|
|
|
|
|
|
$1, $2
|
|
|
|
|
|
)
|
|
|
|
|
|
ON CONFLICT(block_height) DO UPDATE SET
|
|
|
|
|
|
block_hash = EXCLUDED.block_hash;
|
|
|
|
|
|
|
|
|
|
|
|
-- name: GetPruneTip :one
|
|
|
|
|
|
SELECT block_height, block_hash
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_prune_log
|
2025-06-11 17:46:37 +02:00
|
|
|
|
ORDER BY block_height DESC
|
|
|
|
|
|
LIMIT 1;
|
2025-06-11 17:50:26 +02:00
|
|
|
|
|
2025-07-02 12:06:29 +02:00
|
|
|
|
-- name: GetPruneHashByHeight :one
|
|
|
|
|
|
SELECT block_hash
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_prune_log
|
2025-07-02 12:06:29 +02:00
|
|
|
|
WHERE block_height = $1;
|
|
|
|
|
|
|
2025-06-11 17:50:26 +02:00
|
|
|
|
-- name: DeletePruneLogEntriesInRange :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
DELETE FROM graph_prune_log
|
2025-06-11 17:50:26 +02:00
|
|
|
|
WHERE block_height >= @start_height
|
|
|
|
|
|
AND block_height <= @end_height;
|
2025-06-11 17:55:28 +02:00
|
|
|
|
|
|
|
|
|
|
/* ─────────────────────────────────────────────
|
2025-07-15 17:44:23 +02:00
|
|
|
|
graph_closed_scid table queries
|
2025-06-11 17:55:28 +02:00
|
|
|
|
────────────────────────────────────────────-
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
-- name: InsertClosedChannel :exec
|
2025-07-15 17:44:23 +02:00
|
|
|
|
INSERT INTO graph_closed_scids (scid)
|
2025-06-11 17:55:28 +02:00
|
|
|
|
VALUES ($1)
|
|
|
|
|
|
ON CONFLICT (scid) DO NOTHING;
|
|
|
|
|
|
|
|
|
|
|
|
-- name: IsClosedChannel :one
|
|
|
|
|
|
SELECT EXISTS (
|
|
|
|
|
|
SELECT 1
|
2025-07-15 17:44:23 +02:00
|
|
|
|
FROM graph_closed_scids
|
2025-06-11 17:55:28 +02:00
|
|
|
|
WHERE scid = $1
|
|
|
|
|
|
);
|