From c648c7a22db1ae0eda2d6aaa2bbf49e927293552 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Wed, 11 Jun 2025 16:59:40 +0200 Subject: [PATCH] sqldb/sqlc: add zombie index table Note that this table will only contain entries for channels that we have deleted from the `channels` table which is why we cannot use foreign keys. Similarly, we may no longer have node entries for the nodes in the table. --- sqldb/sqlc/migrations/000007_graph.down.sql | 4 ++- sqldb/sqlc/migrations/000007_graph.up.sql | 28 +++++++++++++++++++++ sqldb/sqlc/models.go | 7 ++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/sqldb/sqlc/migrations/000007_graph.down.sql b/sqldb/sqlc/migrations/000007_graph.down.sql index 0990705ef..a2f519a2c 100644 --- a/sqldb/sqlc/migrations/000007_graph.down.sql +++ b/sqldb/sqlc/migrations/000007_graph.down.sql @@ -25,4 +25,6 @@ DROP TABLE IF EXISTS source_nodes; DROP TABLE IF EXISTS node_addresses; DROP TABLE IF EXISTS node_features; DROP TABLE IF EXISTS node_extra_types; -DROP TABLE IF EXISTS nodes; \ No newline at end of file +DROP TABLE IF EXISTS nodes; +DROP TABLE IF EXISTS channel_policy_extra_types; +DROP TABLE IF EXISTS zombie_channels; \ No newline at end of file diff --git a/sqldb/sqlc/migrations/000007_graph.up.sql b/sqldb/sqlc/migrations/000007_graph.up.sql index 0d179f1d3..a4303bf95 100644 --- a/sqldb/sqlc/migrations/000007_graph.up.sql +++ b/sqldb/sqlc/migrations/000007_graph.up.sql @@ -292,3 +292,31 @@ CREATE TABLE IF NOT EXISTS channel_policy_extra_types ( CREATE UNIQUE INDEX IF NOT EXISTS channel_policy_extra_types_unique ON channel_policy_extra_types ( type, channel_policy_id ); + +/* ───────────────────────────────────────────── + Other graph related tables + ───────────────────────────────────────────── +*/ + +CREATE TABLE IF NOT EXISTS zombie_channels ( + -- The channel id (short channel id) of the channel. + -- NOTE: we don't use a foreign key here to the `channels` + -- table since we may delete the channel record once it + -- is marked as a zombie. + scid BLOB NOT NULL, + + -- The protocol version that this node was gossiped on. + version SMALLINT NOT NULL, + + -- The public key of the node 1 node of the channel. If + -- this is not null, it means an update from this node + -- will be able to resurrect the channel. + node_key_1 BLOB, + + -- The public key of the node 2 node of the channel. If + -- this is not null, it means an update from this node + -- will be able to resurrect the channel. + node_key_2 BLOB +); +CREATE UNIQUE INDEX IF NOT EXISTS zombie_channels_channel_id_version_idx + ON zombie_channels(scid, version); diff --git a/sqldb/sqlc/models.go b/sqldb/sqlc/models.go index 70082eb4d..b750936d6 100644 --- a/sqldb/sqlc/models.go +++ b/sqldb/sqlc/models.go @@ -184,3 +184,10 @@ type NodeFeature struct { type SourceNode struct { NodeID int64 } + +type ZombieChannel struct { + Scid []byte + Version int16 + NodeKey1 []byte + NodeKey2 []byte +}