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.
This commit is contained in:
Elle Mouton committed 2026-02-13 07:21:24 +02:00
1 parent 0cfb9c9d2c
commit 677e6ea89c
2 files changed
+24 -2

No files matched your search

+12 -1
View File
@@ -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
`
+12 -1
View File
@@ -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