graph/db+sqldb: impl PruneGraph, PruneTip, ChannelView

Which lets us run `TestGraphPruning` and `TestBatchedAddChannelEdge`
against our SQL backends.
This commit is contained in:
Elle Mouton
2025-06-11 17:46:37 +02:00
parent 2da701cc4f
commit 9dd0361ed0
5 changed files with 391 additions and 2 deletions

View File

@@ -212,6 +212,16 @@ RETURNING id;
SELECT * FROM channels
WHERE scid = $1 AND version = $2;
-- name: GetChannelByOutpoint :one
SELECT
sqlc.embed(c),
n1.pub_key AS node1_pubkey,
n2.pub_key AS node2_pubkey
FROM channels c
JOIN nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id
WHERE c.outpoint = $1;
-- name: GetChannelAndNodesBySCID :one
SELECT
c.*,
@@ -411,6 +421,13 @@ WHERE node_1_signature IS NOT NULL
AND scid >= @start_scid
AND scid < @end_scid;
-- name: ListChannelsPaginated :many
SELECT id, bitcoin_key_1, bitcoin_key_2, outpoint
FROM channels c
WHERE c.version = $1 AND c.id > $2
ORDER BY c.id
LIMIT $3;
-- name: ListChannelsWithPoliciesPaginated :many
SELECT
sqlc.embed(c),
@@ -648,3 +665,23 @@ SELECT EXISTS (
WHERE scid = $1
AND version = $2
) AS is_zombie;
/* ─────────────────────────────────────────────
prune_log table queries
─────────────────────────────────────────────
*/
-- name: UpsertPruneLogEntry :exec
INSERT INTO prune_log (
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
FROM prune_log
ORDER BY block_height DESC
LIMIT 1;