From 677e6ea89c9a386db22eacb6d169761b369eeedd Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 3 Feb 2026 15:44:05 +0200 Subject: [PATCH] sqldb: use version-specific staleness checks in UpsertChannelPolicy Update the UpsertChannelPolicy query to apply different staleness checks based on gossip version. For v1 policies, continue checking last_update timestamps. For v2 policies, check block_height instead, using >= comparison to handle policies from the same block. The version-specific WHERE clause ensures that policy updates are only applied when they contain newer information according to the versioning scheme appropriate for that gossip version. --- sqldb/sqlc/graph.sql.go | 13 ++++++++++++- sqldb/sqlc/queries/graph.sql | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sqldb/sqlc/graph.sql.go b/sqldb/sqlc/graph.sql.go index 1d569b18e..aa2a04671 100644 --- a/sqldb/sqlc/graph.sql.go +++ b/sqldb/sqlc/graph.sql.go @@ -3804,7 +3804,18 @@ ON CONFLICT (channel_id, node_id, version) signature = EXCLUDED.signature, block_height = EXCLUDED.block_height, disable_flags = EXCLUDED.disable_flags -WHERE EXCLUDED.last_update > graph_channel_policies.last_update +WHERE ( + EXCLUDED.version = 1 AND ( + graph_channel_policies.last_update IS NULL + OR EXCLUDED.last_update > graph_channel_policies.last_update + ) +) +OR ( + EXCLUDED.version = 2 AND ( + graph_channel_policies.block_height IS NULL + OR EXCLUDED.block_height >= graph_channel_policies.block_height + ) +) RETURNING id ` diff --git a/sqldb/sqlc/queries/graph.sql b/sqldb/sqlc/queries/graph.sql index e5c18c39c..a4a42a1e3 100644 --- a/sqldb/sqlc/queries/graph.sql +++ b/sqldb/sqlc/queries/graph.sql @@ -954,7 +954,18 @@ ON CONFLICT (channel_id, node_id, version) signature = EXCLUDED.signature, block_height = EXCLUDED.block_height, disable_flags = EXCLUDED.disable_flags -WHERE EXCLUDED.last_update > graph_channel_policies.last_update +WHERE ( + EXCLUDED.version = 1 AND ( + graph_channel_policies.last_update IS NULL + OR EXCLUDED.last_update > graph_channel_policies.last_update + ) +) +OR ( + EXCLUDED.version = 2 AND ( + graph_channel_policies.block_height IS NULL + OR EXCLUDED.block_height >= graph_channel_policies.block_height + ) +) RETURNING id; -- name: GetChannelPolicyByChannelAndNode :one