What changed, and why it matters
This commit updates the database query that stores Lightning Network node announcements so it can also record a new 'block height' field used by a newer protocol version. It is a schema/query evolution, not a fix for an active security flaw. There is no indication it addresses a vulnerability.
No security action required. Treat as normal code review for database schema evolution and verify downstream callers populate BlockHeight correctly.
Security signals we found
No security framing in commit title or message
No CVE, advisory, or researcher attribution present
Change is a schema/query evolution for a new protocol field
WHERE clause adds a monotonicity guard (>=) for block_height, which is a consistency measure, not a vulnerability fix
Evidence from the diff
The patch modifies two SQL upsert queries (UpsertNode and UpsertSourceNode) in sqldb/sqlc/queries/graph.sql and the generated sqldb/sqlc/graph.sql.go. It adds a block_height column to the INSERT and DO UPDATE SET lists, adds a BlockHeight parameter to the Go structs, and extends the WHERE clause so updates are applied only when the incoming block_height is greater than or equal to the stored one. The change is framed as supporting v2 node announcements. No security relevance is stated, and the diff itself shows normal feature/schema evolution rather than a security patch.
Changed components
sqldb/sqlc/queries/graph.sqlsqldb/sqlc/graph.sql.goUpsertNode SQL queryUpsertSourceNode SQL queryInspect captured patch +40 / −24
diff --git a/sqldb/sqlc/graph.sql.go b/sqldb/sqlc/graph.sql.go
index 8b10e49..cdf15a9 100644
--- a/sqldb/sqlc/graph.sql.go
+++ b/sqldb/sqlc/graph.sql.go
@@ -3673,9 +3673,9 @@ const upsertNode = `-- name: UpsertNode :one
*/
INSERT INTO graph_nodes (
- version, pub_key, alias, last_update, color, signature
+ version, pub_key, alias, last_update, block_height, color, signature
) VALUES (
- $1, $2, $3, $4, $5, $6
+ $1, $2, $3, $4, $5, $6, $7
)
ON CONFLICT (pub_key, version)
-- Update the following fields if a conflict occurs on pub_key
@@ -3683,20 +3683,24 @@ ON CONFLICT (pub_key, version)
DO UPDATE SET
alias = EXCLUDED.alias,
last_update = EXCLUDED.last_update,
+ block_height = EXCLUDED.block_height,
color = EXCLUDED.color,
signature = EXCLUDED.signature
-WHERE graph_nodes.last_update IS NULL
- OR EXCLUDED.last_update > graph_nodes.last_update
+WHERE (graph_nodes.last_update IS NULL
+ OR EXCLUDED.last_update > graph_nodes.last_update)
+AND (graph_nodes.block_height IS NULL
+ OR EXCLUDED.block_height >= graph_nodes.block_height)
RETURNING id
`
type UpsertNodeParams struct {
- Version int16
- PubKey []byte
- Alias sql.NullString
- LastUpdate sql.NullInt64
- Color sql.NullString
- Signature []byte
+ Version int16
+ PubKey []byte
+ Alias sql.NullString
+ LastUpdate sql.NullInt64
+ BlockHeight sql.NullInt64
+ Color sql.NullString
+ Signature []byte
}
func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64, error) {
@@ -3705,6 +3709,7 @@ func (q *Queries) UpsertNode(ctx context.Context, arg UpsertNodeParams) (int64,
arg.PubKey,
arg.Alias,
arg.LastUpdate,
+ arg.BlockHeight,
arg.Color,
arg.Signature,
)
@@ -3801,9 +3806,9 @@ func (q *Queries) UpsertPruneLogEntry(ctx context.Context, arg UpsertPruneLogEnt
const upsertSourceNode = `-- name: UpsertSourceNode :one
INSERT INTO graph_nodes (
- version, pub_key, alias, last_update, color, signature
+ version, pub_key, alias, last_update, block_height, color, signature
) VALUES (
- $1, $2, $3, $4, $5, $6
+ $1, $2, $3, $4, $5, $6, $7
)
ON CONFLICT (pub_key, version)
-- Update the following fields if a conflict occurs on pub_key
@@ -3811,20 +3816,24 @@ ON CONFLICT (pub_key, version)
DO UPDATE SET
alias = EXCLUDED.alias,
last_update = EXCLUDED.last_update,
+ block_height = EXCLUDED.block_height,
color = EXCLUDED.color,
signature = EXCLUDED.signature
WHERE graph_nodes.last_update IS NULL
OR EXCLUDED.last_update >= graph_nodes.last_update
+AND (graph_nodes.block_height IS NULL
+ OR EXCLUDED.block_height >= graph_nodes.block_height)
RETURNING id
`
type UpsertSourceNodeParams struct {
- Version int16
- PubKey []byte
- Alias sql.NullString
- LastUpdate sql.NullInt64
- Color sql.NullString
- Signature []byte
+ Version int16
+ PubKey []byte
+ Alias sql.NullString
+ LastUpdate sql.NullInt64
+ BlockHeight sql.NullInt64
+ Color sql.NullString
+ Signature []byte
}
// We use a separate upsert for our own node since we want to be less strict
@@ -3836,6 +3845,7 @@ func (q *Queries) UpsertSourceNode(ctx context.Context, arg UpsertSourceNodePara
arg.PubKey,
arg.Alias,
arg.LastUpdate,
+ arg.BlockHeight,
arg.Color,
arg.Signature,
)
diff --git a/sqldb/sqlc/queries/graph.sql b/sqldb/sqlc/queries/graph.sql
index a8ff040..4804376 100644
--- a/sqldb/sqlc/queries/graph.sql
+++ b/sqldb/sqlc/queries/graph.sql
@@ -5,9 +5,9 @@
-- name: UpsertNode :one
INSERT INTO graph_nodes (
- version, pub_key, alias, last_update, color, signature
+ version, pub_key, alias, last_update, block_height, color, signature
) VALUES (
- $1, $2, $3, $4, $5, $6
+ $1, $2, $3, $4, $5, $6, $7
)
ON CONFLICT (pub_key, version)
-- Update the following fields if a conflict occurs on pub_key
@@ -15,10 +15,13 @@ ON CONFLICT (pub_key, version)
DO UPDATE SET
alias = EXCLUDED.alias,
last_update = EXCLUDED.last_update,
+ block_height = EXCLUDED.block_height,
color = EXCLUDED.color,
signature = EXCLUDED.signature
-WHERE graph_nodes.last_update IS NULL
- OR EXCLUDED.last_update > graph_nodes.last_update
+WHERE (graph_nodes.last_update IS NULL
+ OR EXCLUDED.last_update > graph_nodes.last_update)
+AND (graph_nodes.block_height IS NULL
+ OR EXCLUDED.block_height >= graph_nodes.block_height)
RETURNING id;
-- We use a separate upsert for our own node since we want to be less strict
@@ -26,9 +29,9 @@ RETURNING id;
-- update the record even if the last_update is the same as what we have.
-- name: UpsertSourceNode :one
INSERT INTO graph_nodes (
- version, pub_key, alias, last_update, color, signature
+ version, pub_key, alias, last_update, block_height, color, signature
) VALUES (
- $1, $2, $3, $4, $5, $6
+ $1, $2, $3, $4, $5, $6, $7
)
ON CONFLICT (pub_key, version)
-- Update the following fields if a conflict occurs on pub_key
@@ -36,10 +39,13 @@ ON CONFLICT (pub_key, version)
DO UPDATE SET
alias = EXCLUDED.alias,
last_update = EXCLUDED.last_update,
+ block_height = EXCLUDED.block_height,
color = EXCLUDED.color,
signature = EXCLUDED.signature
WHERE graph_nodes.last_update IS NULL
OR EXCLUDED.last_update >= graph_nodes.last_update
+AND (graph_nodes.block_height IS NULL
+ OR EXCLUDED.block_height >= graph_nodes.block_height)
RETURNING id;
-- name: GetNodesByIDs :many
Why this scored 18/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.