feat: add route and neighbor reconfirmation task

prunes stale and ambiguous routes and neighbors

keep that data clean
This commit is contained in:
Enot (ded) Skelly
2026-06-12 10:54:06 -07:00
parent 044aecbd3c
commit 4ebe4c869b
8 changed files with 136 additions and 2 deletions
+54
View File
@@ -2704,6 +2704,60 @@ func (q *Queries) ListTraceTags(ctx context.Context, arg ListTraceTagsParams) ([
return items, nil
}
const reconfirmNeighbors = `-- name: ReconfirmNeighbors :exec
DELETE FROM node_neighbors nn
WHERE NOT EXISTS (
SELECT 1 FROM node_short_ids ns
WHERE ns.node_id = nn.neighbor_id
AND ns.iata = nn.iata
)
OR (
SELECT COUNT(*) FROM node_short_ids ns
WHERE ns.iata = nn.iata
AND ns.prefix_4 = (
SELECT prefix_4 FROM node_short_ids
WHERE node_id = nn.neighbor_id
AND iata = nn.iata
)
) > 1
`
// Delete node_neighbors where the neighbor has departed from node_short_ids
// for that IATA, or where its prefix_4 is now ambiguous.
func (q *Queries) ReconfirmNeighbors(ctx context.Context) error {
_, err := q.db.Exec(ctx, reconfirmNeighbors)
return err
}
const reconfirmRoutes = `-- name: ReconfirmRoutes :exec
DELETE FROM known_routes kr
WHERE EXISTS (
SELECT 1
FROM unnest(kr.node_ids) AS hop_node_id
WHERE NOT EXISTS (
SELECT 1 FROM node_short_ids ns
WHERE ns.node_id = hop_node_id
AND ns.iata = kr.iata
)
)
OR EXISTS (
SELECT 1
FROM unnest(kr.hash_prefix) AS hop_prefix
WHERE (
SELECT COUNT(*) FROM node_short_ids ns
WHERE ns.iata = kr.iata
AND ns.prefix_4 = hop_prefix
) > 1
)
`
// Delete known_routes where any hop node has departed from node_short_ids for
// that IATA, or where any hop's prefix_4 is now ambiguous (matches >1 node).
func (q *Queries) ReconfirmRoutes(ctx context.Context) error {
_, err := q.db.Exec(ctx, reconfirmRoutes)
return err
}
const refreshHourlyStats = `-- name: RefreshHourlyStats :exec
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_hourly_iata_stats
`