graph/db+sqldb: batch validation for zombie index migration

Finally, we update the migrateZombieIndex function to use batch
validation just like was done in the previous commits. Here, we
additionally make sure to validate the entire zombie index entry and not
just the SCID.
This commit is contained in:
Elle Mouton
2025-08-13 14:11:40 +02:00
parent a490e03479
commit 5b06474744
5 changed files with 160 additions and 21 deletions

View File

@@ -2261,6 +2261,57 @@ func (q *Queries) GetZombieChannel(ctx context.Context, arg GetZombieChannelPara
return i, err
}
const getZombieChannelsSCIDs = `-- name: GetZombieChannelsSCIDs :many
SELECT scid, version, node_key_1, node_key_2
FROM graph_zombie_channels
WHERE version = $1
AND scid IN (/*SLICE:scids*/?)
`
type GetZombieChannelsSCIDsParams struct {
Version int16
Scids [][]byte
}
func (q *Queries) GetZombieChannelsSCIDs(ctx context.Context, arg GetZombieChannelsSCIDsParams) ([]GraphZombieChannel, error) {
query := getZombieChannelsSCIDs
var queryParams []interface{}
queryParams = append(queryParams, arg.Version)
if len(arg.Scids) > 0 {
for _, v := range arg.Scids {
queryParams = append(queryParams, v)
}
query = strings.Replace(query, "/*SLICE:scids*/?", makeQueryParams(len(queryParams), len(arg.Scids)), 1)
} else {
query = strings.Replace(query, "/*SLICE:scids*/?", "NULL", 1)
}
rows, err := q.db.QueryContext(ctx, query, queryParams...)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GraphZombieChannel
for rows.Next() {
var i GraphZombieChannel
if err := rows.Scan(
&i.Scid,
&i.Version,
&i.NodeKey1,
&i.NodeKey2,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const highestSCID = `-- name: HighestSCID :one
SELECT scid
FROM graph_channels

View File

@@ -84,6 +84,7 @@ type Querier interface {
// and so the query for V2 may differ.
GetV1DisabledSCIDs(ctx context.Context) ([][]byte, error)
GetZombieChannel(ctx context.Context, arg GetZombieChannelParams) (GraphZombieChannel, error)
GetZombieChannelsSCIDs(ctx context.Context, arg GetZombieChannelsSCIDsParams) ([]GraphZombieChannel, error)
HighestSCID(ctx context.Context, version int16) ([]byte, error)
InsertAMPSubInvoice(ctx context.Context, arg InsertAMPSubInvoiceParams) error
InsertAMPSubInvoiceHTLC(ctx context.Context, arg InsertAMPSubInvoiceHTLCParams) error

View File

@@ -908,6 +908,12 @@ DO UPDATE SET
node_key_1 = COALESCE(EXCLUDED.node_key_1, graph_zombie_channels.node_key_1),
node_key_2 = COALESCE(EXCLUDED.node_key_2, graph_zombie_channels.node_key_2);
-- name: GetZombieChannelsSCIDs :many
SELECT *
FROM graph_zombie_channels
WHERE version = @version
AND scid IN (sqlc.slice('scids')/*SLICE:scids*/);
-- name: DeleteZombieChannel :execresult
DELETE FROM graph_zombie_channels
WHERE scid = $1