sqldb+graph/db: prefix graph SQL objects with "graph_"

This makes it more clear what each table is for especially when viewed
with other invoice/payments tables.
This commit is contained in:
Elle Mouton
2025-07-15 17:44:23 +02:00
parent df6c02e3af
commit 74b70a5108
8 changed files with 615 additions and 608 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,32 +1,34 @@
-- Drop indexes.
DROP INDEX IF EXISTS nodes_unique;
DROP INDEX IF EXISTS node_extra_types_unique;
DROP INDEX IF EXISTS node_features_unique;
DROP INDEX IF EXISTS node_addresses_unique;
DROP INDEX IF EXISTS node_last_update_idx;
DROP INDEX IF EXISTS source_nodes_unique;
DROP INDEX IF EXISTS channels_node_id_1_idx;
DROP INDEX IF EXISTS channels_node_id_2_idx;
DROP INDEX IF EXISTS channels_unique;
DROP INDEX IF EXISTS channels_version_outpoint_idx;
DROP INDEX IF EXISTS channel_features_unique;
DROP INDEX IF EXISTS channel_extra_types_unique;
DROP INDEX IF EXISTS channel_policies_unique;
DROP INDEX IF EXISTS channel_policy_extra_types_unique;
DROP INDEX IF EXISTS channel_policy_last_update_idx;
DROP INDEX IF EXISTS graph_nodes_unique;
DROP INDEX IF EXISTS graph_node_extra_types_unique;
DROP INDEX IF EXISTS graph_node_features_unique;
DROP INDEX IF EXISTS graph_node_addresses_unique;
DROP INDEX IF EXISTS graph_node_last_update_idx;
DROP INDEX IF EXISTS graph_source_nodes_unique;
DROP INDEX IF EXISTS graph_channels_node_id_1_idx;
DROP INDEX IF EXISTS graph_channels_node_id_2_idx;
DROP INDEX IF EXISTS graph_channels_unique;
DROP INDEX IF EXISTS graph_channels_version_outpoint_idx;
DROP INDEX IF EXISTS graph_channel_features_unique;
DROP INDEX IF EXISTS graph_channel_extra_types_unique;
DROP INDEX IF EXISTS graph_channel_policies_unique;
DROP INDEX IF EXISTS graph_channel_policy_extra_types_unique;
DROP INDEX IF EXISTS graph_channel_policy_last_update_idx;
DROP INDEX IF EXISTS graph_zombie_channels_channel_id_version_idx;
-- Drop tables in order of reverse dependencies.
DROP TABLE IF EXISTS channel_policy_extra_types;
DROP TABLE IF EXISTS channel_policies;
DROP TABLE IF EXISTS channel_features;
DROP TABLE IF EXISTS channel_extra_types;
DROP TABLE IF EXISTS channels;
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;
DROP TABLE IF EXISTS channel_policy_extra_types;
DROP TABLE IF EXISTS zombie_channels;
DROP TABLE IF EXISTS prune_log;
DROP TABLE IF EXISTS closed_scids;
DROP TABLE IF EXISTS graph_channel_policy_extra_types;
DROP TABLE IF EXISTS graph_channel_policies;
DROP TABLE IF EXISTS graph_channel_features;
DROP TABLE IF EXISTS graph_channel_extra_types;
DROP TABLE IF EXISTS graph_channels;
DROP TABLE IF EXISTS graph_source_nodes;
DROP TABLE IF EXISTS graph_node_addresses;
DROP TABLE IF EXISTS graph_node_features;
DROP TABLE IF EXISTS graph_node_extra_types;
DROP TABLE IF EXISTS graph_nodes;
DROP TABLE IF EXISTS graph_channel_policy_extra_types;
DROP TABLE IF EXISTS graph_zombie_channels;
DROP TABLE IF EXISTS graph_prune_log;
DROP TABLE IF EXISTS graph_closed_scids;

View File

@@ -4,7 +4,7 @@
*/
-- nodes stores all the nodes that we are aware of in the LN graph.
CREATE TABLE IF NOT EXISTS nodes (
CREATE TABLE IF NOT EXISTS graph_nodes (
-- The db ID of the node. This will only be used DB level
-- relations.
id INTEGER PRIMARY KEY,
@@ -34,16 +34,16 @@ CREATE TABLE IF NOT EXISTS nodes (
-- A node (identified by a public key) can only have one active node
-- announcement per protocol.
CREATE UNIQUE INDEX IF NOT EXISTS nodes_unique ON nodes (
CREATE UNIQUE INDEX IF NOT EXISTS graph_nodes_unique ON graph_nodes (
pub_key, version
);
CREATE INDEX IF NOT EXISTS node_last_update_idx ON nodes(last_update);
CREATE INDEX IF NOT EXISTS graph_node_last_update_idx ON graph_nodes(last_update);
-- node_extra_types stores any extra TLV fields covered by a node announcement that
-- we do not have an explicit column for in the nodes table.
CREATE TABLE IF NOT EXISTS node_extra_types (
CREATE TABLE IF NOT EXISTS graph_node_extra_types (
-- The node id this TLV field belongs to.
node_id BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
node_id BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE,
-- The Type field.
type BIGINT NOT NULL,
@@ -51,26 +51,26 @@ CREATE TABLE IF NOT EXISTS node_extra_types (
-- The value field.
value BLOB
);
CREATE UNIQUE INDEX IF NOT EXISTS node_extra_types_unique ON node_extra_types (
CREATE UNIQUE INDEX IF NOT EXISTS graph_node_extra_types_unique ON graph_node_extra_types (
type, node_id
);
-- node_features contains the feature bits of a node.
CREATE TABLE IF NOT EXISTS node_features (
CREATE TABLE IF NOT EXISTS graph_node_features (
-- The node id this feature belongs to.
node_id BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
node_id BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE,
-- The feature bit value.
feature_bit INTEGER NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS node_features_unique ON node_features (
CREATE UNIQUE INDEX IF NOT EXISTS graph_node_features_unique ON graph_node_features (
node_id, feature_bit
);
-- node_addresses contains the advertised addresses of nodes.
CREATE TABLE IF NOT EXISTS node_addresses (
CREATE TABLE IF NOT EXISTS graph_node_addresses (
-- The node id this feature belongs to.
node_id BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
node_id BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE,
-- An enum that represents the type of address. This will
-- dictate how the address column should be parsed.
@@ -86,14 +86,14 @@ CREATE TABLE IF NOT EXISTS node_addresses (
-- The advertised address of the node.
address TEXT NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS node_addresses_unique ON node_addresses (
CREATE UNIQUE INDEX IF NOT EXISTS graph_node_addresses_unique ON graph_node_addresses (
node_id, type, position
);
CREATE TABLE IF NOT EXISTS source_nodes (
node_id BIGINT NOT NULL REFERENCES nodes (id) ON DELETE CASCADE
CREATE TABLE IF NOT EXISTS graph_source_nodes (
node_id BIGINT NOT NULL REFERENCES graph_nodes (id) ON DELETE CASCADE
);
CREATE UNIQUE INDEX IF NOT EXISTS source_nodes_unique ON source_nodes (
CREATE UNIQUE INDEX IF NOT EXISTS graph_source_nodes_unique ON graph_source_nodes (
node_id
);
@@ -103,7 +103,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS source_nodes_unique ON source_nodes (
*/
-- channels stores all teh channels that we are aware of in the graph.
CREATE TABLE IF NOT EXISTS channels (
CREATE TABLE IF NOT EXISTS graph_channels (
-- The db ID of the channel.
id INTEGER PRIMARY KEY,
@@ -113,13 +113,13 @@ CREATE TABLE IF NOT EXISTS channels (
-- The channel id (short channel id) of the channel.
scid BLOB NOT NULL,
-- A reference to a node in the nodes table for the node_1 node in
-- A reference to a node in the graph_nodes table for the node_1 node in
-- the channel announcement.
node_id_1 BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
node_id_1 BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE,
-- A reference to a node in the nodes table for the node_2 node in
-- A reference to a node in the graph_nodes table for the node_2 node in
-- the channel announcement.
node_id_2 BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
node_id_2 BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE,
-- The outpoint of the funding transaction. We chose to store this
-- in a string format for the sake of readability and user queries on
@@ -171,34 +171,34 @@ CREATE TABLE IF NOT EXISTS channels (
);
-- We'll want to lookup all the channels owned by a node, so we create
-- indexes on the node_id_1 and node_id_2 columns.
CREATE INDEX IF NOT EXISTS channels_node_id_1_idx ON channels(node_id_1);
CREATE INDEX IF NOT EXISTS channels_node_id_2_idx ON channels(node_id_2);
CREATE INDEX IF NOT EXISTS graph_channels_node_id_1_idx ON graph_channels(node_id_1);
CREATE INDEX IF NOT EXISTS graph_channels_node_id_2_idx ON graph_channels(node_id_2);
-- A channel (identified by a short channel id) can only have one active
-- channel announcement per protocol version. We also order the index by
-- scid in descending order so that we have an idea of the latest channel
-- announcement we know of.
CREATE UNIQUE INDEX IF NOT EXISTS channels_unique ON channels(version, scid DESC);
CREATE INDEX IF NOT EXISTS channels_version_outpoint_idx ON channels(version, outpoint);
CREATE UNIQUE INDEX IF NOT EXISTS graph_channels_unique ON graph_channels(version, scid DESC);
CREATE INDEX IF NOT EXISTS graph_channels_version_outpoint_idx ON graph_channels(version, outpoint);
-- channel_features contains the feature bits of a channel.
CREATE TABLE IF NOT EXISTS channel_features (
CREATE TABLE IF NOT EXISTS graph_channel_features (
-- The channel id this feature belongs to.
channel_id BIGINT NOT NULL REFERENCES channels(id) ON DELETE CASCADE,
channel_id BIGINT NOT NULL REFERENCES graph_channels(id) ON DELETE CASCADE,
-- The feature bit value.
feature_bit INTEGER NOT NULL
);
CREATE UNIQUE INDEX IF NOT EXISTS channel_features_unique ON channel_features (
CREATE UNIQUE INDEX IF NOT EXISTS graph_channel_features_unique ON graph_channel_features (
channel_id, feature_bit
);
-- channel_extra_types stores any extra TLV fields covered by a channels
-- announcement that we do not have an explicit column for in the channels
-- table.
CREATE TABLE IF NOT EXISTS channel_extra_types (
CREATE TABLE IF NOT EXISTS graph_channel_extra_types (
-- The channel id this TLV field belongs to.
channel_id BIGINT NOT NULL REFERENCES channels(id) ON DELETE CASCADE,
channel_id BIGINT NOT NULL REFERENCES graph_channels(id) ON DELETE CASCADE,
-- The Type field.
type BIGINT NOT NULL,
@@ -206,7 +206,7 @@ CREATE TABLE IF NOT EXISTS channel_extra_types (
-- The value field.
value BLOB
);
CREATE UNIQUE INDEX IF NOT EXISTS channel_extra_types_unique ON channel_extra_types (
CREATE UNIQUE INDEX IF NOT EXISTS graph_channel_extra_types_unique ON graph_channel_extra_types (
type, channel_id
);
@@ -215,7 +215,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS channel_extra_types_unique ON channel_extra_ty
─────────────────────────────────────────────
*/
CREATE TABLE IF NOT EXISTS channel_policies (
CREATE TABLE IF NOT EXISTS graph_channel_policies (
-- The db ID of the channel policy.
id INTEGER PRIMARY KEY,
@@ -223,10 +223,10 @@ CREATE TABLE IF NOT EXISTS channel_policies (
version SMALLINT NOT NULL,
-- The DB ID of the channel that this policy is referencing.
channel_id BIGINT NOT NULL REFERENCES channels(id) ON DELETE CASCADE,
channel_id BIGINT NOT NULL REFERENCES graph_channels(id) ON DELETE CASCADE,
-- The DB ID of the node that created the policy update.
node_id BIGINT NOT NULL REFERENCES nodes(id) ON DELETE CASCADE,
node_id BIGINT NOT NULL REFERENCES graph_nodes(id) ON DELETE CASCADE,
-- The number of blocks that the node will subtract from the expiry
-- of an incoming HTLC.
@@ -290,17 +290,17 @@ CREATE TABLE IF NOT EXISTS channel_policies (
);
-- A node can only have a single live policy update for a channel on a
-- given protocol at any given time.
CREATE UNIQUE INDEX IF NOT EXISTS channel_policies_unique ON channel_policies (
CREATE UNIQUE INDEX IF NOT EXISTS graph_channel_policies_unique ON graph_channel_policies (
channel_id, node_id, version
);
CREATE INDEX IF NOT EXISTS channel_policy_last_update_idx ON channel_policies(last_update);
CREATE INDEX IF NOT EXISTS graph_channel_policy_last_update_idx ON graph_channel_policies(last_update);
-- channel_policy_extra_types stores any extra TLV fields covered by a channel
-- update that we do not have an explicit column for in the channel_policies
-- table.
CREATE TABLE IF NOT EXISTS channel_policy_extra_types (
CREATE TABLE IF NOT EXISTS graph_channel_policy_extra_types (
-- The channel_policy id this TLV field belongs to.
channel_policy_id BIGINT NOT NULL REFERENCES channel_policies(id) ON DELETE CASCADE,
channel_policy_id BIGINT NOT NULL REFERENCES graph_channel_policies(id) ON DELETE CASCADE,
-- The Type field.
type BIGINT NOT NULL,
@@ -308,7 +308,7 @@ CREATE TABLE IF NOT EXISTS channel_policy_extra_types (
-- The value field.
value BLOB
);
CREATE UNIQUE INDEX IF NOT EXISTS channel_policy_extra_types_unique ON channel_policy_extra_types (
CREATE UNIQUE INDEX IF NOT EXISTS graph_channel_policy_extra_types_unique ON graph_channel_policy_extra_types (
type, channel_policy_id
);
@@ -317,7 +317,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS channel_policy_extra_types_unique ON channel_p
─────────────────────────────────────────────
*/
CREATE TABLE IF NOT EXISTS zombie_channels (
CREATE TABLE IF NOT EXISTS graph_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
@@ -337,10 +337,10 @@ CREATE TABLE IF NOT EXISTS zombie_channels (
-- 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);
CREATE UNIQUE INDEX IF NOT EXISTS graph_zombie_channels_channel_id_version_idx
ON graph_zombie_channels(scid, version);
CREATE TABLE IF NOT EXISTS prune_log (
CREATE TABLE IF NOT EXISTS graph_prune_log (
-- The block height that the prune was performed at.
-- NOTE: we don't use INTEGER PRIMARY KEY here since that would
-- get transformed into an auto-incrementing type by our SQL type
@@ -352,7 +352,7 @@ CREATE TABLE IF NOT EXISTS prune_log (
block_hash BLOB NOT NULL
);
CREATE TABLE IF NOT EXISTS closed_scids (
CREATE TABLE IF NOT EXISTS graph_closed_scids (
-- The short channel id of the channel.
scid BLOB PRIMARY KEY
);

View File

@@ -28,7 +28,7 @@ type AmpSubInvoiceHtlc struct {
Preimage []byte
}
type Channel struct {
type GraphChannel struct {
ID int64
Version int16
Scid []byte
@@ -44,18 +44,18 @@ type Channel struct {
Bitcoin2Signature []byte
}
type ChannelExtraType struct {
type GraphChannelExtraType struct {
ChannelID int64
Type int64
Value []byte
}
type ChannelFeature struct {
type GraphChannelFeature struct {
ChannelID int64
FeatureBit int32
}
type ChannelPolicy struct {
type GraphChannelPolicy struct {
ID int64
Version int16
ChannelID int64
@@ -74,16 +74,60 @@ type ChannelPolicy struct {
Signature []byte
}
type ChannelPolicyExtraType struct {
type GraphChannelPolicyExtraType struct {
ChannelPolicyID int64
Type int64
Value []byte
}
type ClosedScid struct {
type GraphClosedScid struct {
Scid []byte
}
type GraphNode struct {
ID int64
Version int16
PubKey []byte
Alias sql.NullString
LastUpdate sql.NullInt64
Color sql.NullString
Signature []byte
}
type GraphNodeAddress struct {
NodeID int64
Type int16
Position int32
Address string
}
type GraphNodeExtraType struct {
NodeID int64
Type int64
Value []byte
}
type GraphNodeFeature struct {
NodeID int64
FeatureBit int32
}
type GraphPruneLog struct {
BlockHeight int64
BlockHash []byte
}
type GraphSourceNode struct {
NodeID int64
}
type GraphZombieChannel struct {
Scid []byte
Version int16
NodeKey1 []byte
NodeKey2 []byte
}
type Invoice struct {
ID int64
Hash []byte
@@ -158,47 +202,3 @@ type MigrationTracker struct {
Version int32
MigrationTime time.Time
}
type Node struct {
ID int64
Version int16
PubKey []byte
Alias sql.NullString
LastUpdate sql.NullInt64
Color sql.NullString
Signature []byte
}
type NodeAddress struct {
NodeID int64
Type int16
Position int32
Address string
}
type NodeExtraType struct {
NodeID int64
Type int64
Value []byte
}
type NodeFeature struct {
NodeID int64
FeatureBit int32
}
type PruneLog struct {
BlockHeight int64
BlockHash []byte
}
type SourceNode struct {
NodeID int64
}
type ZombieChannel struct {
Scid []byte
Version int16
NodeKey1 []byte
NodeKey2 []byte
}

View File

@@ -37,15 +37,15 @@ type Querier interface {
GetChannelAndNodesBySCID(ctx context.Context, arg GetChannelAndNodesBySCIDParams) (GetChannelAndNodesBySCIDRow, error)
GetChannelByOutpoint(ctx context.Context, outpoint string) (GetChannelByOutpointRow, error)
GetChannelByOutpointWithPolicies(ctx context.Context, arg GetChannelByOutpointWithPoliciesParams) (GetChannelByOutpointWithPoliciesRow, error)
GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (Channel, error)
GetChannelBySCID(ctx context.Context, arg GetChannelBySCIDParams) (GraphChannel, error)
GetChannelBySCIDWithPolicies(ctx context.Context, arg GetChannelBySCIDWithPoliciesParams) (GetChannelBySCIDWithPoliciesRow, error)
GetChannelFeaturesAndExtras(ctx context.Context, channelID int64) ([]GetChannelFeaturesAndExtrasRow, error)
GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (ChannelPolicy, error)
GetChannelPolicyByChannelAndNode(ctx context.Context, arg GetChannelPolicyByChannelAndNodeParams) (GraphChannelPolicy, error)
GetChannelPolicyExtraTypes(ctx context.Context, arg GetChannelPolicyExtraTypesParams) ([]GetChannelPolicyExtraTypesRow, error)
GetChannelsByPolicyLastUpdateRange(ctx context.Context, arg GetChannelsByPolicyLastUpdateRangeParams) ([]GetChannelsByPolicyLastUpdateRangeRow, error)
GetChannelsBySCIDRange(ctx context.Context, arg GetChannelsBySCIDRangeParams) ([]GetChannelsBySCIDRangeRow, error)
GetDatabaseVersion(ctx context.Context) (int32, error)
GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]NodeExtraType, error)
GetExtraNodeTypes(ctx context.Context, nodeID int64) ([]GraphNodeExtraType, error)
// This method may return more than one invoice if filter using multiple fields
// from different invoices. It is the caller's responsibility to ensure that
// we bubble up an error in those cases.
@@ -58,14 +58,14 @@ type Querier interface {
GetKVInvoicePaymentHashByAddIndex(ctx context.Context, addIndex int64) ([]byte, error)
GetMigration(ctx context.Context, version int32) (time.Time, error)
GetNodeAddressesByPubKey(ctx context.Context, arg GetNodeAddressesByPubKeyParams) ([]GetNodeAddressesByPubKeyRow, error)
GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (Node, error)
GetNodeFeatures(ctx context.Context, nodeID int64) ([]NodeFeature, error)
GetNodeByPubKey(ctx context.Context, arg GetNodeByPubKeyParams) (GraphNode, error)
GetNodeFeatures(ctx context.Context, nodeID int64) ([]GraphNodeFeature, error)
GetNodeFeaturesByPubKey(ctx context.Context, arg GetNodeFeaturesByPubKeyParams) ([]int32, error)
GetNodeIDByPubKey(ctx context.Context, arg GetNodeIDByPubKeyParams) (int64, error)
GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]Node, error)
GetNodesByLastUpdateRange(ctx context.Context, arg GetNodesByLastUpdateRangeParams) ([]GraphNode, error)
GetPruneHashByHeight(ctx context.Context, blockHeight int64) ([]byte, error)
GetPruneTip(ctx context.Context) (PruneLog, error)
GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]Channel, error)
GetPruneTip(ctx context.Context) (GraphPruneLog, error)
GetPublicV1ChannelsBySCID(ctx context.Context, arg GetPublicV1ChannelsBySCIDParams) ([]GraphChannel, error)
GetSCIDByOutpoint(ctx context.Context, arg GetSCIDByOutpointParams) ([]byte, error)
GetSourceNodesByVersion(ctx context.Context, version int16) ([]GetSourceNodesByVersionRow, error)
// NOTE: this is V1 specific since for V1, disabled is a
@@ -73,7 +73,7 @@ type Querier interface {
// structure will have a more complex disabled bit vector
// and so the query for V2 may differ.
GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error)
GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (ZombieChannel, error)
GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error)
HighestSCID(ctx context.Context, version int16) ([]byte, error)
InsertAMPSubInvoice(ctx context.Context, arg InsertAMPSubInvoiceParams) error
InsertAMPSubInvoiceHTLC(ctx context.Context, arg InsertAMPSubInvoiceHTLCParams) error
@@ -95,7 +95,7 @@ type Querier interface {
ListChannelsPaginated(ctx context.Context, arg ListChannelsPaginatedParams) ([]ListChannelsPaginatedRow, error)
ListChannelsWithPoliciesPaginated(ctx context.Context, arg ListChannelsWithPoliciesPaginatedParams) ([]ListChannelsWithPoliciesPaginatedRow, error)
ListNodeIDsAndPubKeys(ctx context.Context, arg ListNodeIDsAndPubKeysParams) ([]ListNodeIDsAndPubKeysRow, error)
ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]Node, error)
ListNodesPaginated(ctx context.Context, arg ListNodesPaginatedParams) ([]GraphNode, error)
NextInvoiceSettleIndex(ctx context.Context) (int64, error)
OnAMPSubInvoiceCanceled(ctx context.Context, arg OnAMPSubInvoiceCanceledParams) error
OnAMPSubInvoiceCreated(ctx context.Context, arg OnAMPSubInvoiceCreatedParams) error

View File

@@ -1,10 +1,10 @@
/* ─────────────────────────────────────────────
nodes table queries
────────────────────────────────────────────
graph_nodes table queries
───────────────────────────<EFBFBD><EFBFBD>─────────────────
*/
-- name: UpsertNode :one
INSERT INTO nodes (
INSERT INTO graph_nodes (
version, pub_key, alias, last_update, color, signature
) VALUES (
$1, $2, $3, $4, $5, $6
@@ -17,32 +17,32 @@ ON CONFLICT (pub_key, version)
last_update = EXCLUDED.last_update,
color = EXCLUDED.color,
signature = EXCLUDED.signature
WHERE nodes.last_update IS NULL
OR EXCLUDED.last_update > nodes.last_update
WHERE graph_nodes.last_update IS NULL
OR EXCLUDED.last_update > graph_nodes.last_update
RETURNING id;
-- name: GetNodeByPubKey :one
SELECT *
FROM nodes
FROM graph_nodes
WHERE pub_key = $1
AND version = $2;
-- name: GetNodeIDByPubKey :one
SELECT id
FROM nodes
FROM graph_nodes
WHERE pub_key = $1
AND version = $2;
-- name: ListNodesPaginated :many
SELECT *
FROM nodes
FROM graph_nodes
WHERE version = $1 AND id > $2
ORDER BY id
LIMIT $3;
-- name: ListNodeIDsAndPubKeys :many
SELECT id, pub_key
FROM nodes
FROM graph_nodes
WHERE version = $1 AND id > $2
ORDER BY id
LIMIT $3;
@@ -50,8 +50,8 @@ LIMIT $3;
-- name: IsPublicV1Node :one
SELECT EXISTS (
SELECT 1
FROM channels c
JOIN nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
FROM graph_channels c
JOIN graph_nodes n ON n.id = c.node_id_1 OR n.id = c.node_id_2
-- 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
@@ -66,37 +66,37 @@ SELECT EXISTS (
);
-- name: DeleteUnconnectedNodes :many
DELETE FROM nodes
DELETE FROM graph_nodes
WHERE
-- Ignore any of our source nodes.
NOT EXISTS (
SELECT 1
FROM source_nodes sn
WHERE sn.node_id = nodes.id
FROM graph_source_nodes sn
WHERE sn.node_id = graph_nodes.id
)
-- Select all nodes that do not have any channels.
AND NOT EXISTS (
SELECT 1
FROM channels c
WHERE c.node_id_1 = nodes.id OR c.node_id_2 = nodes.id
FROM graph_channels c
WHERE c.node_id_1 = graph_nodes.id OR c.node_id_2 = graph_nodes.id
) RETURNING pub_key;
-- name: DeleteNodeByPubKey :execresult
DELETE FROM nodes
DELETE FROM graph_nodes
WHERE pub_key = $1
AND version = $2;
-- name: DeleteNode :exec
DELETE FROM nodes
DELETE FROM graph_nodes
WHERE id = $1;
/* ─────────────────────────────────────────────
node_features table queries
graph_node_features table queries
─────────────────────────────────────────────
*/
-- name: InsertNodeFeature :exec
INSERT INTO node_features (
INSERT INTO graph_node_features (
node_id, feature_bit
) VALUES (
$1, $2
@@ -104,28 +104,28 @@ INSERT INTO node_features (
-- name: GetNodeFeatures :many
SELECT *
FROM node_features
FROM graph_node_features
WHERE node_id = $1;
-- name: GetNodeFeaturesByPubKey :many
SELECT f.feature_bit
FROM nodes n
JOIN node_features f ON f.node_id = n.id
FROM graph_nodes n
JOIN graph_node_features f ON f.node_id = n.id
WHERE n.pub_key = $1
AND n.version = $2;
-- name: DeleteNodeFeature :exec
DELETE FROM node_features
DELETE FROM graph_node_features
WHERE node_id = $1
AND feature_bit = $2;
/* ─────────────────────────────────────────────
node_addresses table queries
────────────────────────────────────────────
graph_node_addresses table queries
───────────────────────────────────<EFBFBD><EFBFBD>─────────
*/
-- name: InsertNodeAddress :exec
INSERT INTO node_addresses (
INSERT INTO graph_node_addresses (
node_id,
type,
address,
@@ -136,28 +136,28 @@ INSERT INTO node_addresses (
-- name: GetNodeAddressesByPubKey :many
SELECT a.type, a.address
FROM nodes n
LEFT JOIN node_addresses a ON a.node_id = n.id
FROM graph_nodes n
LEFT JOIN graph_node_addresses a ON a.node_id = n.id
WHERE n.pub_key = $1 AND n.version = $2
ORDER BY a.type ASC, a.position ASC;
-- name: GetNodesByLastUpdateRange :many
SELECT *
FROM nodes
FROM graph_nodes
WHERE last_update >= @start_time
AND last_update < @end_time;
-- name: DeleteNodeAddresses :exec
DELETE FROM node_addresses
DELETE FROM graph_node_addresses
WHERE node_id = $1;
/* ─────────────────────────────────────────────
node_extra_types table queries
graph_node_extra_types table queries
─────────────────────────────────────────────
*/
-- name: UpsertNodeExtraType :exec
INSERT INTO node_extra_types (
INSERT INTO graph_node_extra_types (
node_id, type, value
)
VALUES ($1, $2, $3)
@@ -168,37 +168,37 @@ ON CONFLICT (type, node_id)
-- name: GetExtraNodeTypes :many
SELECT *
FROM node_extra_types
FROM graph_node_extra_types
WHERE node_id = $1;
-- name: DeleteExtraNodeType :exec
DELETE FROM node_extra_types
DELETE FROM graph_node_extra_types
WHERE node_id = $1
AND type = $2;
/* ─────────────────────────────────────────────
source_nodes table queries
graph_source_nodes table queries
─────────────────────────────────────────────
*/
-- name: AddSourceNode :exec
INSERT INTO source_nodes (node_id)
INSERT INTO graph_source_nodes (node_id)
VALUES ($1)
ON CONFLICT (node_id) DO NOTHING;
-- name: GetSourceNodesByVersion :many
SELECT sn.node_id, n.pub_key
FROM source_nodes sn
JOIN nodes n ON sn.node_id = n.id
FROM graph_source_nodes sn
JOIN graph_nodes n ON sn.node_id = n.id
WHERE n.version = $1;
/* ─────────────────────────────────────────────
channels table queries
graph_channels table queries
─────────────────────────────────────────────
*/
-- name: CreateChannel :one
INSERT INTO channels (
INSERT INTO graph_channels (
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,
@@ -209,7 +209,7 @@ INSERT INTO channels (
RETURNING id;
-- name: AddV1ChannelProof :execresult
UPDATE channels
UPDATE graph_channels
SET node_1_signature = $2,
node_2_signature = $3,
bitcoin_1_signature = $4,
@@ -221,14 +221,14 @@ WHERE scid = $1
SELECT sqlc.embed(c),
n1.pub_key AS node1_pub_key,
n2.pub_key AS node2_pub_key
FROM channels c
JOIN nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id
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 scid >= @start_scid
AND scid < @end_scid;
-- name: GetChannelBySCID :one
SELECT * FROM channels
SELECT * FROM graph_channels
WHERE scid = $1 AND version = $2;
-- name: GetChannelByOutpoint :one
@@ -236,9 +236,9 @@ 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
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 = $1;
-- name: GetChannelAndNodesBySCID :one
@@ -246,9 +246,9 @@ SELECT
c.*,
n1.pub_key AS node1_pub_key,
n2.pub_key AS node2_pub_key
FROM channels c
JOIN nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id
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.scid = $1
AND c.version = $2;
@@ -259,7 +259,7 @@ SELECT
cf.feature_bit AS feature_bit,
NULL AS extra_key,
NULL AS value
FROM channel_features cf
FROM graph_channel_features cf
WHERE cf.channel_id = $1
UNION ALL
@@ -270,11 +270,11 @@ SELECT
0 AS feature_bit,
cet.type AS extra_key,
cet.value AS value
FROM channel_extra_types cet
FROM graph_channel_extra_types cet
WHERE cet.channel_id = $1;
-- name: GetSCIDByOutpoint :one
SELECT scid from channels
SELECT scid from graph_channels
WHERE outpoint = $1 AND version = $2;
-- name: GetChannelsByPolicyLastUpdateRange :many
@@ -317,12 +317,12 @@ SELECT
cp2.channel_flags AS policy2_channel_flags,
cp2.signature AS policy2_signature
FROM channels c
JOIN nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id
LEFT JOIN channel_policies cp1
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 channel_policies cp2
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 (
@@ -377,18 +377,18 @@ SELECT
cp2.message_flags AS policy_2_message_flags,
cp2.channel_flags AS policy_2_channel_flags,
cp2.signature AS policy_2_signature
FROM channels c
JOIN nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id
LEFT JOIN channel_policies cp1
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 channel_policies cp2
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.outpoint = $1 AND c.version = $2;
-- name: HighestSCID :one
SELECT scid
FROM channels
FROM graph_channels
WHERE version = $1
ORDER BY scid DESC
LIMIT 1;
@@ -435,26 +435,26 @@ SELECT sqlc.embed(c),
cp2.channel_flags AS policy2_channel_flags,
cp2.signature AS policy2_signature
FROM channels c
JOIN nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id
LEFT JOIN channel_policies cp1
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 channel_policies cp2
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 = $2 OR c.node_id_2 = $2);
-- name: GetPublicV1ChannelsBySCID :many
SELECT *
FROM channels
FROM graph_channels
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
FROM graph_channels c
WHERE c.version = $1 AND c.id > $2
ORDER BY c.id
LIMIT $3;
@@ -501,50 +501,50 @@ SELECT
cp2.channel_flags AS policy2_channel_flags,
cp2.signature AS policy_2_signature
FROM channels c
JOIN nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id
LEFT JOIN channel_policies cp1
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 channel_policies cp2
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;
-- name: DeleteChannel :exec
DELETE FROM channels WHERE id = $1;
DELETE FROM graph_channels WHERE id = $1;
/* ─────────────────────────────────────────────
channel_features table queries
graph_channel_features table queries
─────────────────────────────────────────────
*/
-- name: InsertChannelFeature :exec
INSERT INTO channel_features (
INSERT INTO graph_channel_features (
channel_id, feature_bit
) VALUES (
$1, $2
);
/* ─────────────────────────────────────────────
channel_extra_types table queries
graph_channel_extra_types table queries
─────────────────────────────────────────────
*/
-- name: CreateChannelExtraType :exec
INSERT INTO channel_extra_types (
INSERT INTO graph_channel_extra_types (
channel_id, type, value
)
VALUES ($1, $2, $3);
/* ─────────────────────────────────────────────
channel_policies table queries
graph_channel_policies table queries
─────────────────────────────────────────────
*/
-- name: UpsertEdgePolicy :one
INSERT INTO channel_policies (
INSERT INTO graph_channel_policies (
version, channel_id, node_id, timelock, fee_ppm,
base_fee_msat, min_htlc_msat, last_update, disabled,
max_htlc_msat, inbound_base_fee_msat,
@@ -569,12 +569,12 @@ ON CONFLICT (channel_id, node_id, version)
message_flags = EXCLUDED.message_flags,
channel_flags = EXCLUDED.channel_flags,
signature = EXCLUDED.signature
WHERE EXCLUDED.last_update > channel_policies.last_update
WHERE EXCLUDED.last_update > graph_channel_policies.last_update
RETURNING id;
-- name: GetChannelPolicyByChannelAndNode :one
SELECT *
FROM channel_policies
FROM graph_channel_policies
WHERE channel_id = $1
AND node_id = $2
AND version = $3;
@@ -619,23 +619,23 @@ SELECT
cp2.channel_flags AS policy_2_channel_flags,
cp2.signature AS policy2_signature
FROM channels c
JOIN nodes n1 ON c.node_id_1 = n1.id
JOIN nodes n2 ON c.node_id_2 = n2.id
LEFT JOIN channel_policies cp1
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 channel_policies cp2
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.scid = @scid
AND c.version = @version;
/* ─────────────────────────────────────────────
channel_policy_extra_types table queries
graph_channel_policy_extra_types table queries
─────────────────────────────────────────────
*/
-- name: InsertChanPolicyExtraType :exec
INSERT INTO channel_policy_extra_types (
INSERT INTO graph_channel_policy_extra_types (
channel_policy_id, type, value
)
VALUES ($1, $2, $3);
@@ -647,15 +647,15 @@ SELECT
cp.node_id,
cpet.type,
cpet.value
FROM channel_policies cp
JOIN channel_policy_extra_types cpet
FROM graph_channel_policies cp
JOIN graph_channel_policy_extra_types cpet
ON cp.id = cpet.channel_policy_id
WHERE cp.id = $1 OR cp.id = $2;
-- name: GetV1DisabledSCIDs :many
SELECT c.scid
FROM channels c
JOIN channel_policies cp ON cp.channel_id = c.id
FROM graph_channels c
JOIN graph_channel_policies cp ON cp.channel_id = c.id
-- 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
@@ -666,55 +666,55 @@ GROUP BY c.scid
HAVING COUNT(*) > 1;
-- name: DeleteChannelPolicyExtraTypes :exec
DELETE FROM channel_policy_extra_types
DELETE FROM graph_channel_policy_extra_types
WHERE channel_policy_id = $1;
/* ─────────────────────────────────────────────
zombie_channels table queries
graph_zombie_channels table queries
─────────────────────────────────────────────
*/
-- name: UpsertZombieChannel :exec
INSERT INTO zombie_channels (scid, version, node_key_1, node_key_2)
INSERT INTO graph_zombie_channels (scid, version, node_key_1, node_key_2)
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.
node_key_1 = COALESCE(EXCLUDED.node_key_1, zombie_channels.node_key_1),
node_key_2 = COALESCE(EXCLUDED.node_key_2, zombie_channels.node_key_2);
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);
-- name: DeleteZombieChannel :execresult
DELETE FROM zombie_channels
DELETE FROM graph_zombie_channels
WHERE scid = $1
AND version = $2;
-- name: CountZombieChannels :one
SELECT COUNT(*)
FROM zombie_channels
FROM graph_zombie_channels
WHERE version = $1;
-- name: GetZombieChannel :one
SELECT *
FROM zombie_channels
FROM graph_zombie_channels
WHERE scid = $1
AND version = $2;
-- name: IsZombieChannel :one
SELECT EXISTS (
SELECT 1
FROM zombie_channels
FROM graph_zombie_channels
WHERE scid = $1
AND version = $2
) AS is_zombie;
/* ────────────────────────────────────────────
prune_log table queries
/* ───────────────────────────<EFBFBD><EFBFBD><EFBFBD>─────────────────
graph_prune_log table queries
─────────────────────────────────────────────
*/
-- name: UpsertPruneLogEntry :exec
INSERT INTO prune_log (
INSERT INTO graph_prune_log (
block_height, block_hash
) VALUES (
$1, $2
@@ -724,33 +724,33 @@ ON CONFLICT(block_height) DO UPDATE SET
-- name: GetPruneTip :one
SELECT block_height, block_hash
FROM prune_log
FROM graph_prune_log
ORDER BY block_height DESC
LIMIT 1;
-- name: GetPruneHashByHeight :one
SELECT block_hash
FROM prune_log
FROM graph_prune_log
WHERE block_height = $1;
-- name: DeletePruneLogEntriesInRange :exec
DELETE FROM prune_log
DELETE FROM graph_prune_log
WHERE block_height >= @start_height
AND block_height <= @end_height;
/* ─────────────────────────────────────────────
closed_scid table queries
graph_closed_scid table queries
────────────────────────────────────────────-
*/
-- name: InsertClosedChannel :exec
INSERT INTO closed_scids (scid)
INSERT INTO graph_closed_scids (scid)
VALUES ($1)
ON CONFLICT (scid) DO NOTHING;
-- name: IsClosedChannel :one
SELECT EXISTS (
SELECT 1
FROM closed_scids
FROM graph_closed_scids
WHERE scid = $1
);