Skip to content

Commit

Permalink
sqldb: add blinded path tables
Browse files Browse the repository at this point in the history
This commit adds two new tables: blinded_paths and blinded_path_hops. A
single invoice can have multiple blinded_path entries and a single
blinded_path can have multiple blinded_paths.
The commit also adds various queries for the two new tables.
  • Loading branch information
ellemouton committed Sep 9, 2024
1 parent 67f4ead commit b6e1be7
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 0 deletions.
140 changes: 140 additions & 0 deletions sqldb/sqlc/blinded_paths.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sqldb/sqlc/migrations/000005_invoice_blinded_paths.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP TABLE IF EXISTS blinded_paths;
DROP TABLE IF EXISTS blinded_path_hops;
50 changes: 50 additions & 0 deletions sqldb/sqlc/migrations/000005_invoice_blinded_paths.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- blinded_paths contains information about blinded paths included in the
-- associated invoice.
CREATE TABLE IF NOT EXISTS blinded_paths(
-- The id of the blinded path
id BIGINT PRIMARY KEY,

-- invoice_id is the reference to the invoice this blinded_path was created
-- for.
invoice_id BIGINT NOT NULL REFERENCES invoices(id) ON DELETE CASCADE,

-- last_ephemeral_pub is the public key of the last ephemeral blinding
-- point of this path.
last_ephemeral_pub BYTEA NOT NULL UNIQUE,

-- session_key is the private key used for the first ephemeral blinding
-- key of this path.
session_key BYTEA NOT NULL,

-- introduction_node is the public key of the first hop of the path.
introduction_node BYTEA NOT NULL,

-- amount_msat is the total amount in millisatoshis expected to be
-- forwarded along this path.
amount_msat BIGINT NOT NULL
);

-- blinded_paths_hops holds information about a specific hop of a blinded path in
-- blinded_paths.
CREATE TABLE IF NOT EXISTS blinded_path_hops(
-- blinded_path_id is the reference to the blinded_path_id this
-- blinded_path_hop is part of.
blinded_path_id BIGINT NOT NULL REFERENCES blinded_paths(id) ON DELETE CASCADE,

-- hop_index is the index of this hop along the associated blinded path.
hop_index BIGINT NOT NULL,

-- channel_id is the ID of the channel that connects this hop to the previous one.
channel_id BIGINT NOT NULL,

-- node_pub_key is the public key of the node of this hop
node_pub_key BYTEA NOT NULL,

-- amount_to_fwd is the amount that this hop was instructed to forward.
amount_to_fwd BIGINT NOT NULL,

-- The hop_index is unique per path.
UNIQUE (blinded_path_id, hop_index)
);

CREATE INDEX IF NOT EXISTS blinded_path_hops_path_id_idx ON blinded_path_hops(blinded_path_id);
17 changes: 17 additions & 0 deletions sqldb/sqlc/models.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions sqldb/sqlc/querier.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 26 additions & 0 deletions sqldb/sqlc/queries/blinded_paths.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
-- name: InsertBlindedPath :one
INSERT INTO blinded_paths (
invoice_id, last_ephemeral_pub, session_key, introduction_node,
amount_msat
) VALUES (
$1, $2, $3, $4, $5
) RETURNING id;

-- name: FetchBlindedPaths :many
SELECT *
FROM blinded_paths
WHERE invoice_id = $1;

-- name: InsertBlindedPathHop :exec
INSERT INTO blinded_path_hops (
blinded_path_id, hop_index, channel_id, node_pub_key,
amount_to_fwd
) VALUES (
$1, $2, $3, $4, $5
);

-- name: FetchBlindedPathHops :many
SELECT *
FROM blinded_path_hops
WHERE blinded_path_id = $1
ORDER BY hop_index;

0 comments on commit b6e1be7

Please sign in to comment.