@aztec/validator-ha-signer 0.0.1-commit.001888fc
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +195 -0
- package/dest/db/index.d.ts +5 -0
- package/dest/db/index.d.ts.map +1 -0
- package/dest/db/index.js +4 -0
- package/dest/db/lmdb.d.ts +66 -0
- package/dest/db/lmdb.d.ts.map +1 -0
- package/dest/db/lmdb.js +188 -0
- package/dest/db/migrations/1_initial-schema.d.ts +9 -0
- package/dest/db/migrations/1_initial-schema.d.ts.map +1 -0
- package/dest/db/migrations/1_initial-schema.js +20 -0
- package/dest/db/postgres.d.ts +86 -0
- package/dest/db/postgres.d.ts.map +1 -0
- package/dest/db/postgres.js +208 -0
- package/dest/db/schema.d.ts +96 -0
- package/dest/db/schema.d.ts.map +1 -0
- package/dest/db/schema.js +230 -0
- package/dest/db/test_helper.d.ts +10 -0
- package/dest/db/test_helper.d.ts.map +1 -0
- package/dest/db/test_helper.js +14 -0
- package/dest/db/types.d.ts +185 -0
- package/dest/db/types.d.ts.map +1 -0
- package/dest/db/types.js +64 -0
- package/dest/errors.d.ts +34 -0
- package/dest/errors.d.ts.map +1 -0
- package/dest/errors.js +34 -0
- package/dest/factory.d.ts +60 -0
- package/dest/factory.d.ts.map +1 -0
- package/dest/factory.js +115 -0
- package/dest/metrics.d.ts +51 -0
- package/dest/metrics.d.ts.map +1 -0
- package/dest/metrics.js +103 -0
- package/dest/migrations.d.ts +15 -0
- package/dest/migrations.d.ts.map +1 -0
- package/dest/migrations.js +53 -0
- package/dest/slashing_protection_service.d.ts +93 -0
- package/dest/slashing_protection_service.d.ts.map +1 -0
- package/dest/slashing_protection_service.js +236 -0
- package/dest/test/pglite_pool.d.ts +92 -0
- package/dest/test/pglite_pool.d.ts.map +1 -0
- package/dest/test/pglite_pool.js +210 -0
- package/dest/types.d.ts +99 -0
- package/dest/types.d.ts.map +1 -0
- package/dest/types.js +4 -0
- package/dest/validator_ha_signer.d.ts +79 -0
- package/dest/validator_ha_signer.d.ts.map +1 -0
- package/dest/validator_ha_signer.js +140 -0
- package/package.json +110 -0
- package/src/db/index.ts +4 -0
- package/src/db/lmdb.ts +264 -0
- package/src/db/migrations/1_initial-schema.ts +26 -0
- package/src/db/postgres.ts +284 -0
- package/src/db/schema.ts +267 -0
- package/src/db/test_helper.ts +17 -0
- package/src/db/types.ts +251 -0
- package/src/errors.ts +47 -0
- package/src/factory.ts +139 -0
- package/src/metrics.ts +138 -0
- package/src/migrations.ts +75 -0
- package/src/slashing_protection_service.ts +308 -0
- package/src/test/pglite_pool.ts +256 -0
- package/src/types.ts +154 -0
- package/src/validator_ha_signer.ts +183 -0
package/dest/metrics.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { Attributes, Metrics, createUpDownCounterWithDefault } from '@aztec/telemetry-client';
|
|
2
|
+
/**
|
|
3
|
+
* Metrics for HA signer tracking signing operations, lock acquisition, and cleanup.
|
|
4
|
+
*/ export class HASignerMetrics {
|
|
5
|
+
nodeId;
|
|
6
|
+
// Signing lifecycle metrics
|
|
7
|
+
signingDuration;
|
|
8
|
+
signingSuccessCount;
|
|
9
|
+
dutyAlreadySignedCount;
|
|
10
|
+
slashingProtectionCount;
|
|
11
|
+
signingErrorCount;
|
|
12
|
+
// Lock acquisition metrics
|
|
13
|
+
lockAcquiredCount;
|
|
14
|
+
// Cleanup metrics
|
|
15
|
+
cleanupStuckDutiesCount;
|
|
16
|
+
cleanupOldDutiesCount;
|
|
17
|
+
cleanupOutdatedRollupDutiesCount;
|
|
18
|
+
constructor(client, nodeId, name = 'HASignerMetrics'){
|
|
19
|
+
this.nodeId = nodeId;
|
|
20
|
+
const meter = client.getMeter(name);
|
|
21
|
+
// Signing lifecycle
|
|
22
|
+
this.signingDuration = meter.createHistogram(Metrics.HA_SIGNER_SIGNING_DURATION);
|
|
23
|
+
this.signingSuccessCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SIGNING_SUCCESS_COUNT);
|
|
24
|
+
this.dutyAlreadySignedCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_DUTY_ALREADY_SIGNED_COUNT);
|
|
25
|
+
this.slashingProtectionCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SLASHING_PROTECTION_COUNT);
|
|
26
|
+
this.signingErrorCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SIGNING_ERROR_COUNT);
|
|
27
|
+
// Lock acquisition
|
|
28
|
+
this.lockAcquiredCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_LOCK_ACQUIRED_COUNT);
|
|
29
|
+
// Cleanup
|
|
30
|
+
this.cleanupStuckDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_STUCK_DUTIES_COUNT);
|
|
31
|
+
this.cleanupOldDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_OLD_DUTIES_COUNT);
|
|
32
|
+
this.cleanupOutdatedRollupDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_OUTDATED_ROLLUP_DUTIES_COUNT);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Record a successful signing operation.
|
|
36
|
+
* @param dutyType - The type of duty signed
|
|
37
|
+
* @param durationMs - Duration from start of signWithProtection to completion
|
|
38
|
+
*/ recordSigningSuccess(dutyType, durationMs) {
|
|
39
|
+
const attributes = {
|
|
40
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
41
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
42
|
+
};
|
|
43
|
+
this.signingSuccessCount.add(1, attributes);
|
|
44
|
+
this.signingDuration.record(durationMs, attributes);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Record a DutyAlreadySignedError (expected in HA; another node signed first).
|
|
48
|
+
* @param dutyType - The type of duty
|
|
49
|
+
*/ recordDutyAlreadySigned(dutyType) {
|
|
50
|
+
const attributes = {
|
|
51
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
52
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
53
|
+
};
|
|
54
|
+
this.dutyAlreadySignedCount.add(1, attributes);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Record a SlashingProtectionError (attempted to sign different data for same duty).
|
|
58
|
+
* @param dutyType - The type of duty
|
|
59
|
+
*/ recordSlashingProtection(dutyType) {
|
|
60
|
+
const attributes = {
|
|
61
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
62
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
63
|
+
};
|
|
64
|
+
this.slashingProtectionCount.add(1, attributes);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Record a signing function failure (lock will be deleted for retry).
|
|
68
|
+
* @param dutyType - The type of duty
|
|
69
|
+
*/ recordSigningError(dutyType) {
|
|
70
|
+
const attributes = {
|
|
71
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
72
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
73
|
+
};
|
|
74
|
+
this.signingErrorCount.add(1, attributes);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Record lock acquisition.
|
|
78
|
+
* @param acquired - Whether a new lock was acquired (true) or existing record found (false)
|
|
79
|
+
*/ recordLockAcquire(acquired) {
|
|
80
|
+
if (acquired) {
|
|
81
|
+
const attributes = {
|
|
82
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
83
|
+
};
|
|
84
|
+
this.lockAcquiredCount.add(1, attributes);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Record cleanup metrics.
|
|
89
|
+
* @param type - Type of cleanup
|
|
90
|
+
* @param count - Number of duties cleaned up
|
|
91
|
+
*/ recordCleanup(type, count) {
|
|
92
|
+
const attributes = {
|
|
93
|
+
[Attributes.HA_NODE_ID]: this.nodeId
|
|
94
|
+
};
|
|
95
|
+
if (type === 'stuck') {
|
|
96
|
+
this.cleanupStuckDutiesCount.add(count, attributes);
|
|
97
|
+
} else if (type === 'old') {
|
|
98
|
+
this.cleanupOldDutiesCount.add(count, attributes);
|
|
99
|
+
} else if (type === 'outdated_rollup') {
|
|
100
|
+
this.cleanupOutdatedRollupDutiesCount.add(count, attributes);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface RunMigrationsOptions {
|
|
2
|
+
/** Migration direction ('up' to apply, 'down' to rollback). Defaults to 'up'. */
|
|
3
|
+
direction?: 'up' | 'down';
|
|
4
|
+
/** Enable verbose output. Defaults to false. */
|
|
5
|
+
verbose?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Run database migrations programmatically
|
|
9
|
+
*
|
|
10
|
+
* @param databaseUrl - PostgreSQL connection string
|
|
11
|
+
* @param options - Migration options (direction, verbose)
|
|
12
|
+
* @returns Array of applied migration names
|
|
13
|
+
*/
|
|
14
|
+
export declare function runMigrations(databaseUrl: string, options?: RunMigrationsOptions): Promise<string[]>;
|
|
15
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibWlncmF0aW9ucy5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL21pZ3JhdGlvbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBYUEsTUFBTSxXQUFXLG9CQUFvQjtJQUNuQyxpRkFBaUY7SUFDakYsU0FBUyxDQUFDLEVBQUUsSUFBSSxHQUFHLE1BQU0sQ0FBQztJQUMxQixnREFBZ0Q7SUFDaEQsT0FBTyxDQUFDLEVBQUUsT0FBTyxDQUFDO0NBQ25CO0FBRUQ7Ozs7OztHQU1HO0FBQ0gsd0JBQXNCLGFBQWEsQ0FBQyxXQUFXLEVBQUUsTUFBTSxFQUFFLE9BQU8sR0FBRSxvQkFBeUIsR0FBRyxPQUFPLENBQUMsTUFBTSxFQUFFLENBQUMsQ0ErQzlHIn0=
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrations.d.ts","sourceRoot":"","sources":["../src/migrations.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,oBAAoB;IACnC,iFAAiF;IACjF,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,CAAC;IAC1B,gDAAgD;IAChD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;GAMG;AACH,wBAAsB,aAAa,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,GAAE,oBAAyB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CA+C9G"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic migration runner
|
|
3
|
+
*/ import { createLogger } from '@aztec/foundation/log';
|
|
4
|
+
import { readdirSync } from 'fs';
|
|
5
|
+
import { runner } from 'node-pg-migrate';
|
|
6
|
+
import { dirname, join } from 'path';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = dirname(__filename);
|
|
10
|
+
/**
|
|
11
|
+
* Run database migrations programmatically
|
|
12
|
+
*
|
|
13
|
+
* @param databaseUrl - PostgreSQL connection string
|
|
14
|
+
* @param options - Migration options (direction, verbose)
|
|
15
|
+
* @returns Array of applied migration names
|
|
16
|
+
*/ export async function runMigrations(databaseUrl, options = {}) {
|
|
17
|
+
const direction = options.direction ?? 'up';
|
|
18
|
+
const verbose = options.verbose ?? false;
|
|
19
|
+
const log = createLogger('validator-ha-signer:migrations');
|
|
20
|
+
const migrationsDir = join(__dirname, 'db', 'migrations');
|
|
21
|
+
try {
|
|
22
|
+
log.info(`Running migrations ${direction}...`);
|
|
23
|
+
// Filter out .d.ts and .d.ts.map files - node-pg-migrate only needs .js files
|
|
24
|
+
const migrationFiles = readdirSync(migrationsDir);
|
|
25
|
+
const jsMigrationFiles = migrationFiles.filter((file)=>file.endsWith('.js') && !file.endsWith('.d.ts') && !file.endsWith('.d.ts.map'));
|
|
26
|
+
if (jsMigrationFiles.length === 0) {
|
|
27
|
+
log.info('No migration files found');
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const appliedMigrations = await runner({
|
|
31
|
+
databaseUrl,
|
|
32
|
+
dir: migrationsDir,
|
|
33
|
+
direction,
|
|
34
|
+
migrationsTable: 'pgmigrations',
|
|
35
|
+
count: direction === 'down' ? 1 : Infinity,
|
|
36
|
+
verbose,
|
|
37
|
+
log: (msg)=>verbose ? log.info(msg) : log.debug(msg),
|
|
38
|
+
// Ignore TypeScript declaration files - node-pg-migrate will try to import them otherwise
|
|
39
|
+
ignorePattern: '.*\\.d\\.(ts|js)$|.*\\.d\\.ts\\.map$'
|
|
40
|
+
});
|
|
41
|
+
if (appliedMigrations.length === 0) {
|
|
42
|
+
log.info('No migrations to apply - schema is up to date');
|
|
43
|
+
} else {
|
|
44
|
+
log.info(`Applied ${appliedMigrations.length} migration(s)`, {
|
|
45
|
+
migrations: appliedMigrations.map((m)=>m.name)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return appliedMigrations.map((m)=>m.name);
|
|
49
|
+
} catch (error) {
|
|
50
|
+
log.error('Migration failed', error);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
2
|
+
import type { BaseSignerConfig } from '@aztec/stdlib/ha-signing';
|
|
3
|
+
import { type CheckAndRecordParams, type DeleteDutyParams, type RecordSuccessParams } from './db/types.js';
|
|
4
|
+
import type { HASignerMetrics } from './metrics.js';
|
|
5
|
+
import type { SlashingProtectionDatabase } from './types.js';
|
|
6
|
+
export interface SlashingProtectionServiceDeps {
|
|
7
|
+
metrics: HASignerMetrics;
|
|
8
|
+
dateProvider: DateProvider;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Slashing Protection Service
|
|
12
|
+
*
|
|
13
|
+
* This service ensures that a validator only signs one block/attestation per slot,
|
|
14
|
+
* even when running multiple redundant nodes (HA setup).
|
|
15
|
+
*
|
|
16
|
+
* All nodes in the HA setup try to sign - the first one wins, others get
|
|
17
|
+
* DutyAlreadySignedError (normal) or SlashingProtectionError (if different data).
|
|
18
|
+
*
|
|
19
|
+
* Flow:
|
|
20
|
+
* 1. checkAndRecord() - Atomically try to acquire lock via tryInsertOrGetExisting
|
|
21
|
+
* 2. Caller performs the signing operation
|
|
22
|
+
* 3. recordSuccess() - Update to 'signed' status with signature
|
|
23
|
+
* OR deleteDuty() - Delete the record to allow retry
|
|
24
|
+
*/
|
|
25
|
+
export declare class SlashingProtectionService {
|
|
26
|
+
private readonly db;
|
|
27
|
+
private readonly config;
|
|
28
|
+
private readonly log;
|
|
29
|
+
private readonly pollingIntervalMs;
|
|
30
|
+
private readonly signingTimeoutMs;
|
|
31
|
+
private readonly maxStuckDutiesAgeMs;
|
|
32
|
+
private readonly metrics;
|
|
33
|
+
private readonly dateProvider;
|
|
34
|
+
private cleanupRunningPromise;
|
|
35
|
+
private lastOldDutiesCleanupAtMs?;
|
|
36
|
+
constructor(db: SlashingProtectionDatabase, config: BaseSignerConfig, deps: SlashingProtectionServiceDeps);
|
|
37
|
+
/**
|
|
38
|
+
* Check if a duty can be performed and acquire the lock if so.
|
|
39
|
+
*
|
|
40
|
+
* This method uses an atomic insert-or-get operation.
|
|
41
|
+
* It will:
|
|
42
|
+
* 1. Try to insert a new record with 'signing' status
|
|
43
|
+
* 2. If insert succeeds, we acquired the lock - return the lockToken
|
|
44
|
+
* 3. If a record exists, handle based on status:
|
|
45
|
+
* - SIGNED: Throw appropriate error (already signed or slashing protection)
|
|
46
|
+
* - SIGNING: Wait and poll until status changes, then handle result
|
|
47
|
+
*
|
|
48
|
+
* @returns The lockToken that must be used for recordSuccess/deleteDuty
|
|
49
|
+
* @throws DutyAlreadySignedError if the duty was already completed
|
|
50
|
+
* @throws SlashingProtectionError if attempting to sign different data for same slot/duty
|
|
51
|
+
*/
|
|
52
|
+
checkAndRecord(params: CheckAndRecordParams): Promise<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Record a successful signing operation.
|
|
55
|
+
* Updates the duty status to 'signed' and stores the signature.
|
|
56
|
+
* Only succeeds if the lockToken matches (caller must be the one who created the duty).
|
|
57
|
+
*
|
|
58
|
+
* @returns true if the update succeeded, false if token didn't match
|
|
59
|
+
*/
|
|
60
|
+
recordSuccess(params: RecordSuccessParams): Promise<boolean>;
|
|
61
|
+
/**
|
|
62
|
+
* Delete a duty record after a failed signing operation.
|
|
63
|
+
* Removes the record to allow another node/attempt to retry.
|
|
64
|
+
* Only succeeds if the lockToken matches (caller must be the one who created the duty).
|
|
65
|
+
*
|
|
66
|
+
* @returns true if the delete succeeded, false if token didn't match
|
|
67
|
+
*/
|
|
68
|
+
deleteDuty(params: DeleteDutyParams): Promise<boolean>;
|
|
69
|
+
/**
|
|
70
|
+
* Get the node ID for this service
|
|
71
|
+
*/
|
|
72
|
+
get nodeId(): string;
|
|
73
|
+
/**
|
|
74
|
+
* Start running tasks.
|
|
75
|
+
* Cleanup runs immediately on start to recover from any previous crashes.
|
|
76
|
+
*/
|
|
77
|
+
/**
|
|
78
|
+
* Start the background cleanup task.
|
|
79
|
+
* Also performs one-time cleanup of duties with outdated rollup addresses.
|
|
80
|
+
*/
|
|
81
|
+
start(): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Stop the background cleanup task.
|
|
84
|
+
*/
|
|
85
|
+
stop(): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Close the database connection.
|
|
88
|
+
* Should be called after stop() during graceful shutdown.
|
|
89
|
+
*/
|
|
90
|
+
close(): Promise<void>;
|
|
91
|
+
private cleanup;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW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YAMa,OAAO;CA+BtB"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Slashing Protection Service
|
|
3
|
+
*
|
|
4
|
+
* Provides distributed locking and slashing protection for validator duties.
|
|
5
|
+
* Uses an external database to coordinate across multiple validator nodes.
|
|
6
|
+
*/ import { createLogger } from '@aztec/foundation/log';
|
|
7
|
+
import { RunningPromise } from '@aztec/foundation/promise';
|
|
8
|
+
import { sleep } from '@aztec/foundation/sleep';
|
|
9
|
+
import { DutyStatus, getBlockIndexFromDutyIdentifier } from './db/types.js';
|
|
10
|
+
import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
11
|
+
/**
|
|
12
|
+
* Slashing Protection Service
|
|
13
|
+
*
|
|
14
|
+
* This service ensures that a validator only signs one block/attestation per slot,
|
|
15
|
+
* even when running multiple redundant nodes (HA setup).
|
|
16
|
+
*
|
|
17
|
+
* All nodes in the HA setup try to sign - the first one wins, others get
|
|
18
|
+
* DutyAlreadySignedError (normal) or SlashingProtectionError (if different data).
|
|
19
|
+
*
|
|
20
|
+
* Flow:
|
|
21
|
+
* 1. checkAndRecord() - Atomically try to acquire lock via tryInsertOrGetExisting
|
|
22
|
+
* 2. Caller performs the signing operation
|
|
23
|
+
* 3. recordSuccess() - Update to 'signed' status with signature
|
|
24
|
+
* OR deleteDuty() - Delete the record to allow retry
|
|
25
|
+
*/ export class SlashingProtectionService {
|
|
26
|
+
db;
|
|
27
|
+
config;
|
|
28
|
+
log;
|
|
29
|
+
pollingIntervalMs;
|
|
30
|
+
signingTimeoutMs;
|
|
31
|
+
maxStuckDutiesAgeMs;
|
|
32
|
+
metrics;
|
|
33
|
+
dateProvider;
|
|
34
|
+
cleanupRunningPromise;
|
|
35
|
+
lastOldDutiesCleanupAtMs;
|
|
36
|
+
constructor(db, config, deps){
|
|
37
|
+
this.db = db;
|
|
38
|
+
this.config = config;
|
|
39
|
+
this.log = createLogger('slashing-protection');
|
|
40
|
+
this.pollingIntervalMs = config.pollingIntervalMs;
|
|
41
|
+
this.signingTimeoutMs = config.signingTimeoutMs;
|
|
42
|
+
// Default to 144s (2x 72s Aztec slot duration) if not explicitly configured
|
|
43
|
+
this.maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? 144_000;
|
|
44
|
+
this.cleanupRunningPromise = new RunningPromise(this.cleanup.bind(this), this.log, this.maxStuckDutiesAgeMs);
|
|
45
|
+
this.metrics = deps.metrics;
|
|
46
|
+
this.dateProvider = deps.dateProvider;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Check if a duty can be performed and acquire the lock if so.
|
|
50
|
+
*
|
|
51
|
+
* This method uses an atomic insert-or-get operation.
|
|
52
|
+
* It will:
|
|
53
|
+
* 1. Try to insert a new record with 'signing' status
|
|
54
|
+
* 2. If insert succeeds, we acquired the lock - return the lockToken
|
|
55
|
+
* 3. If a record exists, handle based on status:
|
|
56
|
+
* - SIGNED: Throw appropriate error (already signed or slashing protection)
|
|
57
|
+
* - SIGNING: Wait and poll until status changes, then handle result
|
|
58
|
+
*
|
|
59
|
+
* @returns The lockToken that must be used for recordSuccess/deleteDuty
|
|
60
|
+
* @throws DutyAlreadySignedError if the duty was already completed
|
|
61
|
+
* @throws SlashingProtectionError if attempting to sign different data for same slot/duty
|
|
62
|
+
*/ async checkAndRecord(params) {
|
|
63
|
+
const { validatorAddress, slot, dutyType, messageHash, nodeId } = params;
|
|
64
|
+
const startTime = this.dateProvider.now();
|
|
65
|
+
this.log.debug(`Checking duty: ${dutyType} for slot ${slot}`, {
|
|
66
|
+
validatorAddress: validatorAddress.toString(),
|
|
67
|
+
nodeId
|
|
68
|
+
});
|
|
69
|
+
while(true){
|
|
70
|
+
// insert if not present, get existing if present
|
|
71
|
+
const { isNew, record } = await this.db.tryInsertOrGetExisting(params);
|
|
72
|
+
if (isNew) {
|
|
73
|
+
// We successfully acquired the lock
|
|
74
|
+
this.log.verbose(`Acquired lock for duty ${dutyType} at slot ${slot}`, {
|
|
75
|
+
validatorAddress: validatorAddress.toString(),
|
|
76
|
+
nodeId
|
|
77
|
+
});
|
|
78
|
+
this.metrics.recordLockAcquire(true);
|
|
79
|
+
return record.lockToken;
|
|
80
|
+
}
|
|
81
|
+
// Record already exists - handle based on status
|
|
82
|
+
if (record.status === DutyStatus.SIGNED) {
|
|
83
|
+
// Duty was already signed - check if same or different data
|
|
84
|
+
if (record.messageHash !== messageHash) {
|
|
85
|
+
this.log.verbose(`Slashing protection triggered for duty ${dutyType} at slot ${slot}`, {
|
|
86
|
+
validatorAddress: validatorAddress.toString(),
|
|
87
|
+
existingMessageHash: record.messageHash,
|
|
88
|
+
attemptedMessageHash: messageHash,
|
|
89
|
+
existingNodeId: record.nodeId,
|
|
90
|
+
attemptingNodeId: nodeId
|
|
91
|
+
});
|
|
92
|
+
this.metrics.recordSlashingProtection(dutyType);
|
|
93
|
+
throw new SlashingProtectionError(slot, dutyType, record.blockIndexWithinCheckpoint, record.messageHash, messageHash, record.nodeId);
|
|
94
|
+
}
|
|
95
|
+
this.metrics.recordDutyAlreadySigned(dutyType);
|
|
96
|
+
throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, record.nodeId);
|
|
97
|
+
} else if (record.status === DutyStatus.SIGNING) {
|
|
98
|
+
// Another node is currently signing - check for timeout
|
|
99
|
+
if (this.dateProvider.now() - startTime > this.signingTimeoutMs) {
|
|
100
|
+
this.log.warn(`Timeout waiting for signing to complete for duty ${dutyType} at slot ${slot}`, {
|
|
101
|
+
validatorAddress: validatorAddress.toString(),
|
|
102
|
+
timeoutMs: this.signingTimeoutMs,
|
|
103
|
+
signingNodeId: record.nodeId
|
|
104
|
+
});
|
|
105
|
+
this.metrics.recordDutyAlreadySigned(dutyType);
|
|
106
|
+
throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, 'unknown (timeout)');
|
|
107
|
+
}
|
|
108
|
+
// Wait and poll
|
|
109
|
+
this.log.debug(`Waiting for signing to complete for duty ${dutyType} at slot ${slot}`, {
|
|
110
|
+
validatorAddress: validatorAddress.toString(),
|
|
111
|
+
signingNodeId: record.nodeId
|
|
112
|
+
});
|
|
113
|
+
await sleep(this.pollingIntervalMs);
|
|
114
|
+
// Loop continues - next iteration will check status again
|
|
115
|
+
} else {
|
|
116
|
+
throw new Error(`Unknown duty status: ${record.status}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Record a successful signing operation.
|
|
122
|
+
* Updates the duty status to 'signed' and stores the signature.
|
|
123
|
+
* Only succeeds if the lockToken matches (caller must be the one who created the duty).
|
|
124
|
+
*
|
|
125
|
+
* @returns true if the update succeeded, false if token didn't match
|
|
126
|
+
*/ async recordSuccess(params) {
|
|
127
|
+
const { rollupAddress, validatorAddress, slot, dutyType, signature, nodeId, lockToken } = params;
|
|
128
|
+
const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
|
|
129
|
+
const success = await this.db.updateDutySigned(rollupAddress, validatorAddress, slot, dutyType, signature.toString(), lockToken, blockIndexWithinCheckpoint);
|
|
130
|
+
if (success) {
|
|
131
|
+
this.log.verbose(`Recorded successful signing for duty ${dutyType} at slot ${slot}`, {
|
|
132
|
+
validatorAddress: validatorAddress.toString(),
|
|
133
|
+
nodeId
|
|
134
|
+
});
|
|
135
|
+
} else {
|
|
136
|
+
this.log.warn(`Failed to record successful signing for duty ${dutyType} at slot ${slot}: invalid token`, {
|
|
137
|
+
validatorAddress: validatorAddress.toString(),
|
|
138
|
+
nodeId
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return success;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Delete a duty record after a failed signing operation.
|
|
145
|
+
* Removes the record to allow another node/attempt to retry.
|
|
146
|
+
* Only succeeds if the lockToken matches (caller must be the one who created the duty).
|
|
147
|
+
*
|
|
148
|
+
* @returns true if the delete succeeded, false if token didn't match
|
|
149
|
+
*/ async deleteDuty(params) {
|
|
150
|
+
const { rollupAddress, validatorAddress, slot, dutyType, lockToken } = params;
|
|
151
|
+
const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
|
|
152
|
+
const success = await this.db.deleteDuty(rollupAddress, validatorAddress, slot, dutyType, lockToken, blockIndexWithinCheckpoint);
|
|
153
|
+
if (success) {
|
|
154
|
+
this.log.info(`Deleted duty ${dutyType} at slot ${slot} to allow retry`, {
|
|
155
|
+
validatorAddress: validatorAddress.toString()
|
|
156
|
+
});
|
|
157
|
+
} else {
|
|
158
|
+
this.log.warn(`Failed to delete duty ${dutyType} at slot ${slot}: invalid token`, {
|
|
159
|
+
validatorAddress: validatorAddress.toString()
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return success;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Get the node ID for this service
|
|
166
|
+
*/ get nodeId() {
|
|
167
|
+
return this.config.nodeId;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Start running tasks.
|
|
171
|
+
* Cleanup runs immediately on start to recover from any previous crashes.
|
|
172
|
+
*/ /**
|
|
173
|
+
* Start the background cleanup task.
|
|
174
|
+
* Also performs one-time cleanup of duties with outdated rollup addresses.
|
|
175
|
+
*/ async start() {
|
|
176
|
+
// One-time cleanup at startup: remove duties from previous rollup versions
|
|
177
|
+
const numOutdatedRollupDuties = await this.db.cleanupOutdatedRollupDuties(this.config.l1Contracts.rollupAddress);
|
|
178
|
+
if (numOutdatedRollupDuties > 0) {
|
|
179
|
+
this.log.info(`Cleaned up ${numOutdatedRollupDuties} duties with outdated rollup address at startup`, {
|
|
180
|
+
currentRollupAddress: this.config.l1Contracts.rollupAddress.toString()
|
|
181
|
+
});
|
|
182
|
+
this.metrics.recordCleanup('outdated_rollup', numOutdatedRollupDuties);
|
|
183
|
+
}
|
|
184
|
+
this.cleanupRunningPromise.start();
|
|
185
|
+
this.log.info('Slashing protection service started', {
|
|
186
|
+
nodeId: this.config.nodeId
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Stop the background cleanup task.
|
|
191
|
+
*/ async stop() {
|
|
192
|
+
await this.cleanupRunningPromise.stop();
|
|
193
|
+
this.log.info('Slashing protection service stopped', {
|
|
194
|
+
nodeId: this.config.nodeId
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Close the database connection.
|
|
199
|
+
* Should be called after stop() during graceful shutdown.
|
|
200
|
+
*/ async close() {
|
|
201
|
+
await this.db.close();
|
|
202
|
+
this.log.info('Slashing protection database connection closed');
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Periodic cleanup of stuck duties and optionally old signed duties.
|
|
206
|
+
* Runs in the background via RunningPromise.
|
|
207
|
+
*/ async cleanup() {
|
|
208
|
+
// 1. Clean up stuck duties (our own node's duties that got stuck in 'signing' status)
|
|
209
|
+
const numStuckDuties = await this.db.cleanupOwnStuckDuties(this.config.nodeId, this.maxStuckDutiesAgeMs);
|
|
210
|
+
if (numStuckDuties > 0) {
|
|
211
|
+
this.log.verbose(`Cleaned up ${numStuckDuties} stuck duties`, {
|
|
212
|
+
nodeId: this.config.nodeId,
|
|
213
|
+
maxStuckDutiesAgeMs: this.maxStuckDutiesAgeMs
|
|
214
|
+
});
|
|
215
|
+
this.metrics.recordCleanup('stuck', numStuckDuties);
|
|
216
|
+
}
|
|
217
|
+
// 2. Clean up old signed duties if configured
|
|
218
|
+
// we shouldn't run this as often as stuck duty cleanup.
|
|
219
|
+
if (this.config.cleanupOldDutiesAfterHours !== undefined) {
|
|
220
|
+
const maxAgeMs = this.config.cleanupOldDutiesAfterHours * 60 * 60 * 1000;
|
|
221
|
+
const nowMs = this.dateProvider.now();
|
|
222
|
+
const shouldRun = this.lastOldDutiesCleanupAtMs === undefined || nowMs - this.lastOldDutiesCleanupAtMs >= maxAgeMs;
|
|
223
|
+
if (shouldRun) {
|
|
224
|
+
const numOldDuties = await this.db.cleanupOldDuties(maxAgeMs);
|
|
225
|
+
this.lastOldDutiesCleanupAtMs = nowMs;
|
|
226
|
+
if (numOldDuties > 0) {
|
|
227
|
+
this.log.verbose(`Cleaned up ${numOldDuties} old signed duties`, {
|
|
228
|
+
cleanupOldDutiesAfterHours: this.config.cleanupOldDutiesAfterHours,
|
|
229
|
+
maxAgeMs
|
|
230
|
+
});
|
|
231
|
+
this.metrics.recordCleanup('old', numOldDuties);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vendored pg-compatible Pool/Client wrapper for PGlite.
|
|
3
|
+
*
|
|
4
|
+
* Copied from @middle-management/pglite-pg-adapter v0.0.3
|
|
5
|
+
* https://www.npmjs.com/package/@middle-management/pglite-pg-adapter
|
|
6
|
+
*
|
|
7
|
+
* Modifications:
|
|
8
|
+
* - Converted to ESM and TypeScript
|
|
9
|
+
* - Uses PGliteInterface instead of PGlite class to avoid TypeScript
|
|
10
|
+
* type mismatches from ESM/CJS dual package resolution with private fields
|
|
11
|
+
* - Simplified rowCount calculation to handle CTEs properly
|
|
12
|
+
*/
|
|
13
|
+
import type { PGliteInterface } from '@electric-sql/pglite';
|
|
14
|
+
import { EventEmitter } from 'events';
|
|
15
|
+
import type { QueryResult, QueryResultRow } from 'pg';
|
|
16
|
+
import { Readable, Writable } from 'stream';
|
|
17
|
+
export interface PoolConfig {
|
|
18
|
+
pglite: PGliteInterface;
|
|
19
|
+
max?: number;
|
|
20
|
+
min?: number;
|
|
21
|
+
}
|
|
22
|
+
interface ClientConfig {
|
|
23
|
+
pglite: PGliteInterface;
|
|
24
|
+
host?: string;
|
|
25
|
+
port?: number;
|
|
26
|
+
ssl?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare class Client extends EventEmitter {
|
|
29
|
+
protected pglite: PGliteInterface;
|
|
30
|
+
protected _connected: boolean;
|
|
31
|
+
readonly host: string;
|
|
32
|
+
readonly port: number;
|
|
33
|
+
readonly ssl: boolean;
|
|
34
|
+
readonly connection: object;
|
|
35
|
+
readonly copyFrom: () => Writable;
|
|
36
|
+
readonly copyTo: () => Readable;
|
|
37
|
+
readonly pauseDrain: () => void;
|
|
38
|
+
readonly resumeDrain: () => void;
|
|
39
|
+
readonly escapeLiteral: (str: string) => string;
|
|
40
|
+
readonly escapeIdentifier: (str: string) => string;
|
|
41
|
+
readonly setTypeParser: () => void;
|
|
42
|
+
readonly getTypeParser: () => (value: string) => unknown;
|
|
43
|
+
constructor(config: ClientConfig);
|
|
44
|
+
connect(): Promise<void>;
|
|
45
|
+
end(): Promise<void>;
|
|
46
|
+
query<R extends QueryResultRow = any>(text: string, values?: any[]): Promise<QueryResult<R>>;
|
|
47
|
+
protected convertPGliteResult<R extends QueryResultRow>(result: {
|
|
48
|
+
rows: R[];
|
|
49
|
+
fields: Array<{
|
|
50
|
+
name: string;
|
|
51
|
+
dataTypeID: number;
|
|
52
|
+
}>;
|
|
53
|
+
affectedRows?: number;
|
|
54
|
+
}): QueryResult<R>;
|
|
55
|
+
get connected(): boolean;
|
|
56
|
+
}
|
|
57
|
+
export declare class Pool extends EventEmitter {
|
|
58
|
+
private clients;
|
|
59
|
+
private availableClients;
|
|
60
|
+
private waitingQueue;
|
|
61
|
+
private _ended;
|
|
62
|
+
private pglite;
|
|
63
|
+
private _config;
|
|
64
|
+
readonly expiredCount = 0;
|
|
65
|
+
readonly options: PoolConfig;
|
|
66
|
+
constructor(config: PoolConfig);
|
|
67
|
+
get totalCount(): number;
|
|
68
|
+
get idleCount(): number;
|
|
69
|
+
get waitingCount(): number;
|
|
70
|
+
get ending(): boolean;
|
|
71
|
+
get ended(): boolean;
|
|
72
|
+
connect(): Promise<PoolClient>;
|
|
73
|
+
query<R extends QueryResultRow = any>(text: string, values?: any[]): Promise<QueryResult<R>>;
|
|
74
|
+
releaseClient(client: PoolClient): void;
|
|
75
|
+
end(): Promise<void>;
|
|
76
|
+
}
|
|
77
|
+
export declare class PoolClient extends Client {
|
|
78
|
+
private pool;
|
|
79
|
+
private _released;
|
|
80
|
+
private _inUse;
|
|
81
|
+
private _userReleased;
|
|
82
|
+
constructor(pglite: PGliteInterface, pool: Pool);
|
|
83
|
+
query<R extends QueryResultRow = any>(text: string, values?: any[]): Promise<QueryResult<R>>;
|
|
84
|
+
release(): void;
|
|
85
|
+
end(): Promise<void>;
|
|
86
|
+
_markInUse(): void;
|
|
87
|
+
_markAvailable(): void;
|
|
88
|
+
_markReleased(): void;
|
|
89
|
+
get connected(): boolean;
|
|
90
|
+
}
|
|
91
|
+
export {};
|
|
92
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicGdsaXRlX3Bvb2wuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy90ZXN0L3BnbGl0ZV9wb29sLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7OztHQVdHO0FBQ0gsT0FBTyxLQUFLLEVBQUUsZUFBZSxFQUFFLE1BQU0sc0JBQXNCLENBQUM7QUFDNUQsT0FBTyxFQUFFLFlBQVksRUFBRSxNQUFNLFFBQVEsQ0FBQztBQUN0QyxPQUFPLEtBQUssRUFBRSxXQUFXLEVBQUUsY0FBYyxFQUFFLE1BQU0sSUFBSSxDQUFDO0FBQ3RELE9BQU8sRUFBRSxRQUFRLEVBQUUsUUFBUSxFQUFFLE1BQU0sUUFBUSxDQUFDO0FBRTVDLE1BQU0sV0FBVyxVQUFVO0lBQ3pCLE1BQU0sRUFBRSxlQUFlLENBQUM7SUFDeEIsR0FBRyxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQ2IsR0FBRyxDQUFDLEVBQUUsTUFBTSxDQUFDO0NBQ2Q7QUFFRCxVQUFVLFlBQVk7SUFDcEIsTUFBTSxFQUFFLGVBQWUsQ0FBQztJQUN4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