Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/release-notes/release-notes-0.19.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,15 @@
## Testing
## Database

* Add [new SQL tables](https://github.com/lightningnetwork/lnd/pull/9003) for
blinded paths.

## Code Health

## Tooling and Documentation

# Contributors (Alphabetical Order)

* Elle Mouton
* Pins
* Ziggie
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing the end point

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 BLOB NOT NULL UNIQUE,

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

-- introduction_node is the public key of the first hop of the path.
introduction_node BLOB 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: missing the end point

node_pub_key BLOB 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;