/** * PostgreSQL implementation of SlashingProtectionDatabase */ import { SlotNumber } from '@aztec/foundation/branded-types'; import { EthAddress } from '@aztec/foundation/eth-address'; import type { QueryResult, QueryResultRow } from 'pg'; import type { SlashingProtectionDatabase, TryInsertOrGetResult } from '../types.js'; import type { CheckAndRecordParams, DutyType } from './types.js'; /** * Minimal pool interface for database operations. * Both pg.Pool and test adapters (e.g., PGlite) satisfy this interface. */ export interface QueryablePool { query(text: string, values?: any[]): Promise>; end(): Promise; } /** * PostgreSQL implementation of the slashing protection database */ export declare class PostgresSlashingProtectionDatabase implements SlashingProtectionDatabase { private readonly pool; private readonly log; constructor(pool: QueryablePool); /** * Verify that database migrations have been run and schema version matches. * Should be called once at startup. * * @throws Error if migrations haven't been run or schema version is outdated */ initialize(): Promise; /** * Atomically try to insert a new duty record, or get the existing one if present. * * @returns { isNew: true, record } if we successfully inserted and acquired the lock * @returns { isNew: false, record } if a record already exists. lock_token is empty if the record already exists. * * Retries if no rows are returned, which can happen under high concurrency * when another transaction just committed the row but it's not yet visible. */ tryInsertOrGetExisting(params: CheckAndRecordParams): Promise; /** * Update a duty to 'signed' status with the signature. * Only succeeds if the lockToken matches (caller must be the one who created the duty). * * @returns true if the update succeeded, false if token didn't match or duty not found */ updateDutySigned(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, signature: string, lockToken: string, blockIndexWithinCheckpoint: number): Promise; /** * Delete a duty record. * Only succeeds if the lockToken matches (caller must be the one who created the duty). * Used when signing fails to allow another node/attempt to retry. * * @returns true if the delete succeeded, false if token didn't match or duty not found */ deleteDuty(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, lockToken: string, blockIndexWithinCheckpoint: number): Promise; /** * Convert a database row to a ValidatorDutyRecord. * Maps snake_case column names to StoredDutyRecord (camelCase, ms timestamps), * then delegates to the shared recordFromFields() converter. */ private rowToRecord; /** * Close the database connection pool */ close(): Promise; /** * Cleanup own stuck duties * @returns the number of duties cleaned up */ cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise; /** * Cleanup duties with outdated rollup address. * Removes all duties where the rollup address doesn't match the current one. * Used after a rollup upgrade to clean up duties for the old rollup. * @returns the number of duties cleaned up */ cleanupOutdatedRollupDuties(currentRollupAddress: EthAddress): Promise; /** * Cleanup old signed duties. * Removes only signed duties older than the specified age. * Does not remove 'signing' duties as they may be in progress. * @returns the number of duties cleaned up */ cleanupOldDuties(maxAgeMs: number): Promise; } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicG9zdGdyZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9kYi9wb3N0Z3Jlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7R0FFRztBQUNILE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxpQ0FBaUMsQ0FBQztBQUU3RCxPQUFPLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFJM0QsT0FBTyxLQUFLLEVBQUUsV0FBVyxFQUFFLGNBQWMsRUFBRSxNQUFNLElBQUksQ0FBQztBQUV0RCxPQUFPLEtBQUssRUFBRSwwQkFBMEIsRUFBRSxvQkFBb0IsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQVVwRixPQUFPLEtBQUssRUFBRSxvQkFBb0IsRUFBVyxRQUFRLEVBQXVDLE1BQU0sWUFBWSxDQUFDO0FBRy9HOzs7R0FHRztBQUNILE1BQU0sV0FBVyxhQUFhO0lBQzVCLEtBQUssQ0FBQyxDQUFDLFNBQVMsY0FBYyxHQUFHLEdBQUcsRUFBRSxJQUFJLEVBQUUsTUFBTSxFQUFFLE1BQU0sQ0FBQyxFQUFFLEdBQUcsRUFBRSxHQUFHLE9BQU8sQ0FBQyxXQUFXLENBQUMsQ0FBQyxDQUFDLENBQUMsQ0FBQztJQUM3RixHQUFHLElBQUksT0FB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