@aztec/validator-ha-signer 0.0.1-commit.ffe5b04ea → 0.0.1-commit.fff30aa
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 +2 -0
- package/dest/config.d.ts +101 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +92 -0
- package/dest/db/in_memory.d.ts +20 -0
- package/dest/db/in_memory.d.ts.map +1 -0
- package/dest/db/in_memory.js +73 -0
- package/dest/db/index.d.ts +1 -2
- package/dest/db/index.d.ts.map +1 -1
- package/dest/db/index.js +0 -1
- package/dest/db/postgres.d.ts +2 -4
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +13 -13
- package/dest/db/types.d.ts +18 -37
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +15 -30
- package/dest/factory.d.ts +13 -18
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +22 -42
- package/dest/slashing_protection_service.d.ts +3 -12
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +6 -17
- package/dest/types.d.ts +70 -17
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +20 -3
- package/dest/validator_ha_signer.d.ts +4 -12
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +8 -16
- package/package.json +6 -10
- package/src/config.ts +149 -0
- package/src/db/in_memory.ts +107 -0
- package/src/db/index.ts +0 -1
- package/src/db/postgres.ts +11 -13
- package/src/db/types.ts +16 -61
- package/src/factory.ts +28 -53
- package/src/slashing_protection_service.ts +7 -28
- package/src/types.ts +104 -32
- package/src/validator_ha_signer.ts +12 -33
- package/dest/db/lmdb.d.ts +0 -66
- package/dest/db/lmdb.d.ts.map +0 -1
- package/dest/db/lmdb.js +0 -188
- package/dest/metrics.d.ts +0 -51
- package/dest/metrics.d.ts.map +0 -1
- package/dest/metrics.js +0 -103
- package/src/db/lmdb.ts +0 -264
- package/src/metrics.ts +0 -138
package/dest/factory.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { CreateHASignerDeps,
|
|
1
|
+
import type { ValidatorHASignerConfig } from './config.js';
|
|
2
|
+
import type { CreateHASignerDeps, SlashingProtectionDatabase } from './types.js';
|
|
3
3
|
import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
4
4
|
/**
|
|
5
5
|
* Create a validator HA signer with PostgreSQL backend
|
|
@@ -16,6 +16,7 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
16
16
|
* ```typescript
|
|
17
17
|
* const { signer, db } = await createHASigner({
|
|
18
18
|
* databaseUrl: process.env.DATABASE_URL,
|
|
19
|
+
* haSigningEnabled: true,
|
|
19
20
|
* nodeId: 'validator-node-1',
|
|
20
21
|
* pollingIntervalMs: 100,
|
|
21
22
|
* signingTimeoutMs: 3000,
|
|
@@ -39,22 +40,16 @@ export declare function createHASigner(config: ValidatorHASignerConfig, deps?: C
|
|
|
39
40
|
db: SlashingProtectionDatabase;
|
|
40
41
|
}>;
|
|
41
42
|
/**
|
|
42
|
-
* Create
|
|
43
|
-
*
|
|
44
|
-
* This provides double-signing protection for nodes that are NOT running in a
|
|
45
|
-
* high-availability (multi-node) setup. It prevents a proposer from sending two
|
|
46
|
-
* proposals for the same slot if the node crashes and restarts mid-proposal.
|
|
47
|
-
*
|
|
48
|
-
* When `config.dataDirectory` is set, the protection database is persisted to disk
|
|
49
|
-
* and survives crashes/restarts. When unset, an ephemeral in-memory store is
|
|
50
|
-
* used which protects within a single run but not across restarts.
|
|
51
|
-
*
|
|
52
|
-
* @param config - Local signer config
|
|
53
|
-
* @param deps - Optional dependencies (telemetry, date provider).
|
|
54
|
-
* @returns An object containing the signer and database instances.
|
|
43
|
+
* Create an in-memory SlashingProtectionDatabase that can be shared across
|
|
44
|
+
* multiple validator nodes in the same process. Used for testing HA setups.
|
|
55
45
|
*/
|
|
56
|
-
export declare function
|
|
46
|
+
export declare function createSharedSlashingProtectionDb(): SlashingProtectionDatabase;
|
|
47
|
+
/**
|
|
48
|
+
* Create a ValidatorHASigner backed by a pre-existing SlashingProtectionDatabase.
|
|
49
|
+
* Used for testing HA setups where multiple nodes share the same protection database.
|
|
50
|
+
*/
|
|
51
|
+
export declare function createSignerFromSharedDb(db: SlashingProtectionDatabase, config: Pick<ValidatorHASignerConfig, 'nodeId' | 'pollingIntervalMs' | 'signingTimeoutMs' | 'maxStuckDutiesAgeMs' | 'l1Contracts'>): {
|
|
57
52
|
signer: ValidatorHASigner;
|
|
58
53
|
db: SlashingProtectionDatabase;
|
|
59
|
-
}
|
|
60
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZmFjdG9yeS5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL2ZhY3RvcnkudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBS0EsT0FBTyxLQUFLLEVBQUUsdUJBQXVCLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFHM0QsT0FBTyxLQUFLLEVBQUUsa0JBQWtCLEVBQUUsMEJBQTBCLEVBQUUsTUFBTSxZQUFZLENBQUM7QUFDakYsT0FBTyxFQUFFLGlCQUFpQixFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFFN0Q7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztHQWlDRztBQUNILHdCQUFzQixjQUFjLENBQ2xDLE1BQU0sRUFBRSx1QkFBdUIsRUFDL0IsSUFBSSxDQUFDLEVBQUUsa0JBQWtCLEdBQ3hCLE9BQU8sQ0FBQztJQUNULE1BQU0sRUFBRSxpQkFBaUIsQ0FBQztJQUMxQixFQUFFLEVBQUUsMEJBQTBCLENBQUM7Q0FDaEMsQ0FBQyxDQStCRDtBQUVEOzs7R0FHRztBQUNILHdCQUFnQixnQ0FBZ0MsSUFBSSwwQkFBMEIsQ0FFN0U7QUFFRDs7O0dBR0c7QUFDSCx3QkFBZ0Isd0JBQXdCLENBQ3RDLEVBQUUsRUFBRSwwQkFBMEIsRUFDOUIsTUFBTSxFQUFFLElBQUksQ0FDVix1QkFBdUIsRUFDdkIsUUFBUSxHQUFHLG1CQUFtQixHQUFHLGtCQUFrQixHQUFHLHFCQUFxQixHQUFHLGFBQWEsQ0FDNUYsR0FDQTtJQUFFLE1BQU0sRUFBRSxpQkFBaUIsQ0FBQztJQUFDLEVBQUUsRUFBRSwwQkFBMEIsQ0FBQTtDQUFFLENBVy9EIn0=
|
package/dest/factory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../src/factory.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAG3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AACjF,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,uBAAuB,EAC/B,IAAI,CAAC,EAAE,kBAAkB,GACxB,OAAO,CAAC;IACT,MAAM,EAAE,iBAAiB,CAAC;IAC1B,EAAE,EAAE,0BAA0B,CAAC;CAChC,CAAC,CA+BD;AAED;;;GAGG;AACH,wBAAgB,gCAAgC,IAAI,0BAA0B,CAE7E;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,EAAE,EAAE,0BAA0B,EAC9B,MAAM,EAAE,IAAI,CACV,uBAAuB,EACvB,QAAQ,GAAG,mBAAmB,GAAG,kBAAkB,GAAG,qBAAqB,GAAG,aAAa,CAC5F,GACA;IAAE,MAAM,EAAE,iBAAiB,CAAC;IAAC,EAAE,EAAE,0BAA0B,CAAA;CAAE,CAW/D"}
|
package/dest/factory.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Factory functions for creating validator HA signers
|
|
3
|
-
*/ import {
|
|
4
|
-
import {
|
|
5
|
-
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
6
|
-
import { Pool } from 'pg';
|
|
7
|
-
import { LmdbSlashingProtectionDatabase } from './db/lmdb.js';
|
|
3
|
+
*/ import { Pool } from 'pg';
|
|
4
|
+
import { InMemorySlashingProtectionDatabase } from './db/in_memory.js';
|
|
8
5
|
import { PostgresSlashingProtectionDatabase } from './db/postgres.js';
|
|
9
|
-
import { HASignerMetrics } from './metrics.js';
|
|
10
6
|
import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
11
7
|
/**
|
|
12
8
|
* Create a validator HA signer with PostgreSQL backend
|
|
@@ -23,6 +19,7 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
23
19
|
* ```typescript
|
|
24
20
|
* const { signer, db } = await createHASigner({
|
|
25
21
|
* databaseUrl: process.env.DATABASE_URL,
|
|
22
|
+
* haSigningEnabled: true,
|
|
26
23
|
* nodeId: 'validator-node-1',
|
|
27
24
|
* pollingIntervalMs: 100,
|
|
28
25
|
* signingTimeoutMs: 3000,
|
|
@@ -45,8 +42,6 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
45
42
|
if (!databaseUrl) {
|
|
46
43
|
throw new Error('databaseUrl is required for createHASigner');
|
|
47
44
|
}
|
|
48
|
-
const telemetryClient = deps?.telemetryClient ?? getTelemetryClient();
|
|
49
|
-
const dateProvider = deps?.dateProvider ?? new DateProvider();
|
|
50
45
|
// Create connection pool (or use provided pool)
|
|
51
46
|
let pool;
|
|
52
47
|
if (!deps?.pool) {
|
|
@@ -64,12 +59,10 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
64
59
|
const db = new PostgresSlashingProtectionDatabase(pool);
|
|
65
60
|
// Verify database schema is initialized and version matches
|
|
66
61
|
await db.initialize();
|
|
67
|
-
// Create metrics
|
|
68
|
-
const metrics = new HASignerMetrics(telemetryClient, signerConfig.nodeId);
|
|
69
62
|
// Create signer
|
|
70
|
-
const signer = new ValidatorHASigner(db,
|
|
71
|
-
|
|
72
|
-
|
|
63
|
+
const signer = new ValidatorHASigner(db, {
|
|
64
|
+
...signerConfig,
|
|
65
|
+
databaseUrl
|
|
73
66
|
});
|
|
74
67
|
return {
|
|
75
68
|
signer,
|
|
@@ -77,37 +70,24 @@ import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
|
77
70
|
};
|
|
78
71
|
}
|
|
79
72
|
/**
|
|
80
|
-
* Create
|
|
81
|
-
*
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
|
|
89
|
-
*
|
|
90
|
-
* @param config - Local signer config
|
|
91
|
-
* @param deps - Optional dependencies (telemetry, date provider).
|
|
92
|
-
* @returns An object containing the signer and database instances.
|
|
93
|
-
*/ export async function createLocalSignerWithProtection(config, deps) {
|
|
94
|
-
const telemetryClient = deps?.telemetryClient ?? getTelemetryClient();
|
|
95
|
-
const dateProvider = deps?.dateProvider ?? new DateProvider();
|
|
96
|
-
const kvStore = await createStore('signing-protection', LmdbSlashingProtectionDatabase.SCHEMA_VERSION, {
|
|
97
|
-
dataDirectory: config.dataDirectory,
|
|
98
|
-
dataStoreMapSizeKb: config.signingProtectionMapSizeKb ?? config.dataStoreMapSizeKb,
|
|
99
|
-
l1Contracts: config.l1Contracts
|
|
100
|
-
});
|
|
101
|
-
const db = new LmdbSlashingProtectionDatabase(kvStore, dateProvider);
|
|
73
|
+
* Create an in-memory SlashingProtectionDatabase that can be shared across
|
|
74
|
+
* multiple validator nodes in the same process. Used for testing HA setups.
|
|
75
|
+
*/ export function createSharedSlashingProtectionDb() {
|
|
76
|
+
return new InMemorySlashingProtectionDatabase();
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a ValidatorHASigner backed by a pre-existing SlashingProtectionDatabase.
|
|
80
|
+
* Used for testing HA setups where multiple nodes share the same protection database.
|
|
81
|
+
*/ export function createSignerFromSharedDb(db, config) {
|
|
102
82
|
const signerConfig = {
|
|
103
|
-
|
|
104
|
-
|
|
83
|
+
haSigningEnabled: true,
|
|
84
|
+
l1Contracts: config.l1Contracts,
|
|
85
|
+
nodeId: config.nodeId || `shared-${Date.now()}`,
|
|
86
|
+
pollingIntervalMs: config.pollingIntervalMs ?? 100,
|
|
87
|
+
signingTimeoutMs: config.signingTimeoutMs ?? 3000,
|
|
88
|
+
maxStuckDutiesAgeMs: config.maxStuckDutiesAgeMs
|
|
105
89
|
};
|
|
106
|
-
const
|
|
107
|
-
const signer = new ValidatorHASigner(db, signerConfig, {
|
|
108
|
-
metrics,
|
|
109
|
-
dateProvider
|
|
110
|
-
});
|
|
90
|
+
const signer = new ValidatorHASigner(db, signerConfig);
|
|
111
91
|
return {
|
|
112
92
|
signer,
|
|
113
93
|
db
|
|
@@ -1,12 +1,5 @@
|
|
|
1
|
-
import type { DateProvider } from '@aztec/foundation/timer';
|
|
2
|
-
import type { BaseSignerConfig } from '@aztec/stdlib/ha-signing';
|
|
3
1
|
import { type CheckAndRecordParams, type DeleteDutyParams, type RecordSuccessParams } from './db/types.js';
|
|
4
|
-
import type {
|
|
5
|
-
import type { SlashingProtectionDatabase } from './types.js';
|
|
6
|
-
export interface SlashingProtectionServiceDeps {
|
|
7
|
-
metrics: HASignerMetrics;
|
|
8
|
-
dateProvider: DateProvider;
|
|
9
|
-
}
|
|
2
|
+
import type { SlashingProtectionDatabase, ValidatorHASignerConfig } from './types.js';
|
|
10
3
|
/**
|
|
11
4
|
* Slashing Protection Service
|
|
12
5
|
*
|
|
@@ -29,11 +22,9 @@ export declare class SlashingProtectionService {
|
|
|
29
22
|
private readonly pollingIntervalMs;
|
|
30
23
|
private readonly signingTimeoutMs;
|
|
31
24
|
private readonly maxStuckDutiesAgeMs;
|
|
32
|
-
private readonly metrics;
|
|
33
|
-
private readonly dateProvider;
|
|
34
25
|
private cleanupRunningPromise;
|
|
35
26
|
private lastOldDutiesCleanupAtMs?;
|
|
36
|
-
constructor(db: SlashingProtectionDatabase, config:
|
|
27
|
+
constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig);
|
|
37
28
|
/**
|
|
38
29
|
* Check if a duty can be performed and acquire the lock if so.
|
|
39
30
|
*
|
|
@@ -90,4 +81,4 @@ export declare class SlashingProtectionService {
|
|
|
90
81
|
close(): Promise<void>;
|
|
91
82
|
private cleanup;
|
|
92
83
|
}
|
|
93
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
84
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xhc2hpbmdfcHJvdGVjdGlvbl9zZXJ2aWNlLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvc2xhc2hpbmdfcHJvdGVjdGlvbl9zZXJ2aWNlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQVVBLE9BQU8sRUFDTCxLQUFLLG9CQUFvQixFQUN6QixLQUFLLGdCQUFnQixFQUVyQixLQUFLLG1CQUFtQixFQUV6QixNQUFNLGVBQWUsQ0FBQztBQUV2QixPQUFPLEtBQUssRUFBRSwwQkFBMEIsRUFBRSx1QkFBdUIsRUFBRSxNQUFNLFlBQVksQ0FBQztBQUV0Rjs7Ozs7Ozs7Ozs7Ozs7R0FjRztBQUNILHFCQUFhLHlCQUF5QjtJQVVsQyxPQUFPLENBQUMsUUFBUSxDQUFDLEVBQUU7SUFDbkIsT0FBTyxDQUFDLFFBQVEsQ0FBQyxNQUFNO0lBVnpCLE9BQU8sQ0FBQyxRQUFRLENBQUMsR0FBRyxDQUFTO0lBQzdCLE9BQU8sQ0FBQyxRQUFRLENBQUMsaUJBQWlCLENBQVM7SUFDM0MsT0FBTyxDQUFDLFFBQVEsQ0FBQyxnQkFBZ0IsQ0FBUztJQUMxQyxPQUFPLENBQUMsUUFBUSxDQUFDLG1CQUFtQixDQUFTO0lBRTdDLE9BQU8sQ0FBQyxxQkFBcUIsQ0FBaUI7SUFDOUMsT0FBTyxDQUFDLHdCQUF3QixDQUFDLENBQVM7SUFFMUMsWUFDbUIsRUFBRSxFQUFFLDBCQUEwQixFQUM5QixNQUFNLEVBQUUsdUJBQXVCLEVBU2pEO0lBRUQ7Ozs7Ozs7Ozs7Ozs7O09BY0c7SUFDRyxjQUFjLENBQUMsTUFBTSxFQUFFLG9CQUFvQixHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FpRWxFO0lBRUQ7Ozs7OztPQU1HO0lBQ0csYUFBYSxDQUFDLE1BQU0sRUFBRSxtQkFBbUIsR0FBRyxPQUFPLENBQUMsT0FBTyxDQUFDLENBMkJqRTtJQUVEOzs7Ozs7T0FNRztJQUNHLFVBQVUsQ0FBQyxNQUFNLEVBQUUsZ0JBQWdCLEdBQUcsT0FBTyxDQUFDLE9BQU8sQ0FBQyxDQXdCM0Q7SUFFRDs7T0FFRztJQUNILElBQUksTUFBTSxJQUFJLE1BQU0sQ0FFbkI7SUFFRDs7O09BR0c7SUFDSDs7O09BR0c7SUFDRyxLQUFLLGtCQVdWO0lBRUQ7O09BRUc7SUFDRyxJQUFJLGtCQUdUO0lBRUQ7OztPQUdHO0lBQ0csS0FBSyxrQkFHVjtZQU1hLE9BQU87Q0E2QnRCIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"slashing_protection_service.d.ts","sourceRoot":"","sources":["../src/slashing_protection_service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"slashing_protection_service.d.ts","sourceRoot":"","sources":["../src/slashing_protection_service.ts"],"names":[],"mappings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;
|
|
32
|
-
metrics;
|
|
33
|
-
dateProvider;
|
|
34
32
|
cleanupRunningPromise;
|
|
35
33
|
lastOldDutiesCleanupAtMs;
|
|
36
|
-
constructor(db, config
|
|
34
|
+
constructor(db, config){
|
|
37
35
|
this.db = db;
|
|
38
36
|
this.config = config;
|
|
39
37
|
this.log = createLogger('slashing-protection');
|
|
@@ -42,8 +40,6 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
42
40
|
// Default to 144s (2x 72s Aztec slot duration) if not explicitly configured
|
|
43
41
|
this.maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? 144_000;
|
|
44
42
|
this.cleanupRunningPromise = new RunningPromise(this.cleanup.bind(this), this.log, this.maxStuckDutiesAgeMs);
|
|
45
|
-
this.metrics = deps.metrics;
|
|
46
|
-
this.dateProvider = deps.dateProvider;
|
|
47
43
|
}
|
|
48
44
|
/**
|
|
49
45
|
* Check if a duty can be performed and acquire the lock if so.
|
|
@@ -61,7 +57,7 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
61
57
|
* @throws SlashingProtectionError if attempting to sign different data for same slot/duty
|
|
62
58
|
*/ async checkAndRecord(params) {
|
|
63
59
|
const { validatorAddress, slot, dutyType, messageHash, nodeId } = params;
|
|
64
|
-
const startTime =
|
|
60
|
+
const startTime = Date.now();
|
|
65
61
|
this.log.debug(`Checking duty: ${dutyType} for slot ${slot}`, {
|
|
66
62
|
validatorAddress: validatorAddress.toString(),
|
|
67
63
|
nodeId
|
|
@@ -71,11 +67,10 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
71
67
|
const { isNew, record } = await this.db.tryInsertOrGetExisting(params);
|
|
72
68
|
if (isNew) {
|
|
73
69
|
// We successfully acquired the lock
|
|
74
|
-
this.log.
|
|
70
|
+
this.log.verbose(`Acquired lock for duty ${dutyType} at slot ${slot}`, {
|
|
75
71
|
validatorAddress: validatorAddress.toString(),
|
|
76
72
|
nodeId
|
|
77
73
|
});
|
|
78
|
-
this.metrics.recordLockAcquire(true);
|
|
79
74
|
return record.lockToken;
|
|
80
75
|
}
|
|
81
76
|
// Record already exists - handle based on status
|
|
@@ -89,20 +84,17 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
89
84
|
existingNodeId: record.nodeId,
|
|
90
85
|
attemptingNodeId: nodeId
|
|
91
86
|
});
|
|
92
|
-
this.metrics.recordSlashingProtection(dutyType);
|
|
93
87
|
throw new SlashingProtectionError(slot, dutyType, record.blockIndexWithinCheckpoint, record.messageHash, messageHash, record.nodeId);
|
|
94
88
|
}
|
|
95
|
-
this.metrics.recordDutyAlreadySigned(dutyType);
|
|
96
89
|
throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, record.nodeId);
|
|
97
90
|
} else if (record.status === DutyStatus.SIGNING) {
|
|
98
91
|
// Another node is currently signing - check for timeout
|
|
99
|
-
if (
|
|
92
|
+
if (Date.now() - startTime > this.signingTimeoutMs) {
|
|
100
93
|
this.log.warn(`Timeout waiting for signing to complete for duty ${dutyType} at slot ${slot}`, {
|
|
101
94
|
validatorAddress: validatorAddress.toString(),
|
|
102
95
|
timeoutMs: this.signingTimeoutMs,
|
|
103
96
|
signingNodeId: record.nodeId
|
|
104
97
|
});
|
|
105
|
-
this.metrics.recordDutyAlreadySigned(dutyType);
|
|
106
98
|
throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, 'unknown (timeout)');
|
|
107
99
|
}
|
|
108
100
|
// Wait and poll
|
|
@@ -128,7 +120,7 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
128
120
|
const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
|
|
129
121
|
const success = await this.db.updateDutySigned(rollupAddress, validatorAddress, slot, dutyType, signature.toString(), lockToken, blockIndexWithinCheckpoint);
|
|
130
122
|
if (success) {
|
|
131
|
-
this.log.
|
|
123
|
+
this.log.verbose(`Recorded successful signing for duty ${dutyType} at slot ${slot}`, {
|
|
132
124
|
validatorAddress: validatorAddress.toString(),
|
|
133
125
|
nodeId
|
|
134
126
|
});
|
|
@@ -179,7 +171,6 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
179
171
|
this.log.info(`Cleaned up ${numOutdatedRollupDuties} duties with outdated rollup address at startup`, {
|
|
180
172
|
currentRollupAddress: this.config.l1Contracts.rollupAddress.toString()
|
|
181
173
|
});
|
|
182
|
-
this.metrics.recordCleanup('outdated_rollup', numOutdatedRollupDuties);
|
|
183
174
|
}
|
|
184
175
|
this.cleanupRunningPromise.start();
|
|
185
176
|
this.log.info('Slashing protection service started', {
|
|
@@ -212,13 +203,12 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
212
203
|
nodeId: this.config.nodeId,
|
|
213
204
|
maxStuckDutiesAgeMs: this.maxStuckDutiesAgeMs
|
|
214
205
|
});
|
|
215
|
-
this.metrics.recordCleanup('stuck', numStuckDuties);
|
|
216
206
|
}
|
|
217
207
|
// 2. Clean up old signed duties if configured
|
|
218
208
|
// we shouldn't run this as often as stuck duty cleanup.
|
|
219
209
|
if (this.config.cleanupOldDutiesAfterHours !== undefined) {
|
|
220
210
|
const maxAgeMs = this.config.cleanupOldDutiesAfterHours * 60 * 60 * 1000;
|
|
221
|
-
const nowMs =
|
|
211
|
+
const nowMs = Date.now();
|
|
222
212
|
const shouldRun = this.lastOldDutiesCleanupAtMs === undefined || nowMs - this.lastOldDutiesCleanupAtMs >= maxAgeMs;
|
|
223
213
|
if (shouldRun) {
|
|
224
214
|
const numOldDuties = await this.db.cleanupOldDuties(maxAgeMs);
|
|
@@ -228,7 +218,6 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
|
|
|
228
218
|
cleanupOldDutiesAfterHours: this.config.cleanupOldDutiesAfterHours,
|
|
229
219
|
maxAgeMs
|
|
230
220
|
});
|
|
231
|
-
this.metrics.recordCleanup('old', numOldDuties);
|
|
232
221
|
}
|
|
233
222
|
}
|
|
234
223
|
}
|
package/dest/types.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { BlockNumber, type CheckpointNumber, type IndexWithinCheckpoint, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
-
import { DutyType, type HAProtectedSigningContext, type SigningContext, type ValidatorHASignerConfig, getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib, isHAProtectedContext } from '@aztec/stdlib/ha-signing';
|
|
5
|
-
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
6
3
|
import type { Pool } from 'pg';
|
|
7
|
-
import type {
|
|
8
|
-
|
|
4
|
+
import type { ValidatorHASignerConfig } from './config.js';
|
|
5
|
+
import { type BlockProposalDutyIdentifier, type CheckAndRecordParams, type DeleteDutyParams, type DutyIdentifier, type DutyRow, DutyType, type OtherDutyIdentifier, type RecordSuccessParams, type ValidatorDutyRecord } from './db/types.js';
|
|
6
|
+
export type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyRow, OtherDutyIdentifier, RecordSuccessParams, ValidatorDutyRecord, ValidatorHASignerConfig, };
|
|
9
7
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
10
|
-
export { isHAProtectedContext };
|
|
11
|
-
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
12
8
|
/**
|
|
13
9
|
* Result of tryInsertOrGetExisting operation
|
|
14
10
|
*/
|
|
@@ -27,19 +23,76 @@ export interface CreateHASignerDeps {
|
|
|
27
23
|
* If provided, databaseUrl and poolConfig are ignored
|
|
28
24
|
*/
|
|
29
25
|
pool?: Pool;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Base context for signing operations
|
|
29
|
+
*/
|
|
30
|
+
interface BaseSigningContext {
|
|
31
|
+
/** Slot number for this duty */
|
|
32
|
+
slot: SlotNumber;
|
|
30
33
|
/**
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Optional date provider for timestamps
|
|
34
|
+
* Block or checkpoint number for this duty.
|
|
35
|
+
* For block proposals, this is the block number.
|
|
36
|
+
* For checkpoint proposals, this is the checkpoint number.
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
+
blockNumber: BlockNumber | CheckpointNumber;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Signing context for block proposals.
|
|
42
|
+
* blockIndexWithinCheckpoint is REQUIRED and must be >= 0.
|
|
43
|
+
*/
|
|
44
|
+
export interface BlockProposalSigningContext extends BaseSigningContext {
|
|
45
|
+
/** Block index within checkpoint (0, 1, 2...). Required for block proposals. */
|
|
46
|
+
blockIndexWithinCheckpoint: IndexWithinCheckpoint;
|
|
47
|
+
dutyType: DutyType.BLOCK_PROPOSAL;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Signing context for non-block-proposal duties that require HA protection.
|
|
51
|
+
* blockIndexWithinCheckpoint is not applicable (internally always -1).
|
|
52
|
+
*/
|
|
53
|
+
export interface OtherSigningContext extends BaseSigningContext {
|
|
54
|
+
dutyType: DutyType.CHECKPOINT_PROPOSAL | DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS;
|
|
38
55
|
}
|
|
39
56
|
/**
|
|
40
|
-
*
|
|
57
|
+
* Signing context for governance/slashing votes which only need slot for HA protection.
|
|
58
|
+
* blockNumber is not applicable (internally always 0).
|
|
59
|
+
*/
|
|
60
|
+
export interface VoteSigningContext {
|
|
61
|
+
slot: SlotNumber;
|
|
62
|
+
dutyType: DutyType.GOVERNANCE_VOTE | DutyType.SLASHING_VOTE;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Signing context for duties which don't require slot/blockNumber
|
|
66
|
+
* as they don't need HA protection (AUTH_REQUEST, TXS).
|
|
67
|
+
*/
|
|
68
|
+
export interface NoHAProtectionSigningContext {
|
|
69
|
+
dutyType: DutyType.AUTH_REQUEST | DutyType.TXS;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Signing contexts that require HA protection (excludes AUTH_REQUEST).
|
|
73
|
+
* Used by the HA signer's signWithProtection method.
|
|
74
|
+
*/
|
|
75
|
+
export type HAProtectedSigningContext = BlockProposalSigningContext | OtherSigningContext | VoteSigningContext;
|
|
76
|
+
/**
|
|
77
|
+
* Type guard to check if a SigningContext requires HA protection.
|
|
78
|
+
* Returns true for contexts that need HA protection, false for AUTH_REQUEST and TXS.
|
|
79
|
+
*/
|
|
80
|
+
export declare function isHAProtectedContext(context: SigningContext): context is HAProtectedSigningContext;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the block number from a signing context.
|
|
83
|
+
* - Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE): returns BlockNumber(0)
|
|
84
|
+
* - Other duties: returns the blockNumber from the context
|
|
85
|
+
*/
|
|
86
|
+
export declare function getBlockNumberFromSigningContext(context: HAProtectedSigningContext): BlockNumber | CheckpointNumber;
|
|
87
|
+
/**
|
|
88
|
+
* Context required for slashing protection during signing operations.
|
|
89
|
+
* Uses discriminated union to enforce type safety:
|
|
90
|
+
* - BLOCK_PROPOSAL duties MUST have blockIndexWithinCheckpoint >= 0
|
|
91
|
+
* - Other duty types do NOT have blockIndexWithinCheckpoint (internally -1)
|
|
92
|
+
* - Vote duties only need slot (blockNumber is internally 0)
|
|
93
|
+
* - AUTH_REQUEST and TXS duties don't need slot/blockNumber (no HA protection needed)
|
|
41
94
|
*/
|
|
42
|
-
export type
|
|
95
|
+
export type SigningContext = HAProtectedSigningContext | NoHAProtectionSigningContext;
|
|
43
96
|
/**
|
|
44
97
|
* Database interface for slashing protection operations
|
|
45
98
|
* This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
|
|
@@ -96,4 +149,4 @@ export interface SlashingProtectionDatabase {
|
|
|
96
149
|
*/
|
|
97
150
|
close(): Promise<void>;
|
|
98
151
|
}
|
|
99
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
152
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsV0FBVyxFQUNYLEtBQUssZ0JBQWdCLEVBQ3JCLEtBQUsscUJBQXFCLEVBQzFCLEtBQUssVUFBVSxFQUNoQixNQUFNLGlDQUFpQyxDQUFDO0FBQ3pDLE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBRWhFLE9BQU8sS0FBSyxFQUFFLElBQUksRUFBRSxNQUFNLElBQUksQ0FBQztBQUUvQixPQUFPLEtBQUssRUFBRSx1QkFBdUIsRUFBRSxNQUFNLGFBQWEsQ0FBQztBQUMzRCxPQUFPLEVBQ0wsS0FBSywyQkFBMkIsRUFDaEMsS0FBSyxvQkFBb0IsRUFDekIsS0FBSyxnQkFBZ0IsRUFDckIsS0FBSyxjQUFjLEVBQ25CLEtBQUssT0FBTyxFQUNaLFFBQVEsRUFDUixLQUFLLG1CQUFtQixFQUN4QixLQUFLLG1CQUFtQixFQUN4QixLQUFLLG1CQUFtQixFQUN6QixNQUFNLGVBQWUsQ0FBQztBQUV2QixZQUFZLEVBQ1YsMkJBQTJCLEVBQzNCLG9CQUFvQixFQUNwQixnQkFBZ0IsRUFDaEIsY0FBYyxFQUNkLE9BQU8sRUFDUCxtQkFBbUIsRUFDbkIsbUJBQW1CLEVBQ25CLG1CQUFtQixFQUNuQix1QkFBdUIsR0FDeEIsQ0FBQ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Q3pCLGdCQUFnQixFQUFFLFVBQVUsRUFDNUIsSUFBSSxFQUFFLFVBQVUsRUFDaEIsUUFBUSxFQUFFLFFBQVEsRUFDbEIsU0FBUyxFQUFFLE1BQU0sRUFDakIsMEJBQTBCLEVBQUUsTUFBTSxHQUNqQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7SUFFcEI7OztPQUdHO0lBQ0gscUJBQXFCLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUV6RTs7Ozs7T0FLRztJQUNILDJCQUEyQixDQUFDLG9CQUFvQixFQUFFLFVBQVUsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7SUFFL0U7Ozs7T0FJRztJQUNILGdCQUFnQixDQUFDLFFBQVEsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBRXBEOzs7T0FHRztJQUNILEtBQUssSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7Q0FDeEIifQ==
|
package/dest/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,oB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AAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/E;;;;OAIG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpD;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
|
package/dest/types.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { DutyType } from './db/types.js';
|
|
2
3
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
/**
|
|
5
|
+
* Type guard to check if a SigningContext requires HA protection.
|
|
6
|
+
* Returns true for contexts that need HA protection, false for AUTH_REQUEST and TXS.
|
|
7
|
+
*/ export function isHAProtectedContext(context) {
|
|
8
|
+
return context.dutyType !== DutyType.AUTH_REQUEST && context.dutyType !== DutyType.TXS;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Gets the block number from a signing context.
|
|
12
|
+
* - Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE): returns BlockNumber(0)
|
|
13
|
+
* - Other duties: returns the blockNumber from the context
|
|
14
|
+
*/ export function getBlockNumberFromSigningContext(context) {
|
|
15
|
+
// Check for duty types that have blockNumber
|
|
16
|
+
if (context.dutyType === DutyType.BLOCK_PROPOSAL || context.dutyType === DutyType.CHECKPOINT_PROPOSAL || context.dutyType === DutyType.ATTESTATION || context.dutyType === DutyType.ATTESTATIONS_AND_SIGNERS) {
|
|
17
|
+
return context.blockNumber;
|
|
18
|
+
}
|
|
19
|
+
// Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE) don't have blockNumber
|
|
20
|
+
return BlockNumber(0);
|
|
21
|
+
}
|
|
@@ -8,14 +8,8 @@
|
|
|
8
8
|
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
9
9
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
10
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
11
|
-
import type {
|
|
12
|
-
import { type
|
|
13
|
-
import type { HASignerMetrics } from './metrics.js';
|
|
14
|
-
import type { SlashingProtectionDatabase } from './types.js';
|
|
15
|
-
export interface ValidatorHASignerDeps {
|
|
16
|
-
metrics: HASignerMetrics;
|
|
17
|
-
dateProvider: DateProvider;
|
|
18
|
-
}
|
|
11
|
+
import type { ValidatorHASignerConfig } from './config.js';
|
|
12
|
+
import { type HAProtectedSigningContext, type SlashingProtectionDatabase } from './types.js';
|
|
19
13
|
/**
|
|
20
14
|
* Validator High Availability Signer
|
|
21
15
|
*
|
|
@@ -40,9 +34,7 @@ export declare class ValidatorHASigner {
|
|
|
40
34
|
private readonly log;
|
|
41
35
|
private readonly slashingProtection;
|
|
42
36
|
private readonly rollupAddress;
|
|
43
|
-
|
|
44
|
-
private readonly metrics;
|
|
45
|
-
constructor(db: SlashingProtectionDatabase, config: BaseSignerConfig, deps: ValidatorHASignerDeps);
|
|
37
|
+
constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig);
|
|
46
38
|
/**
|
|
47
39
|
* Sign a message with slashing protection.
|
|
48
40
|
*
|
|
@@ -76,4 +68,4 @@ export declare class ValidatorHASigner {
|
|
|
76
68
|
*/
|
|
77
69
|
stop(): Promise<void>;
|
|
78
70
|
}
|
|
79
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
71
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdG9yX2hhX3NpZ25lci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3ZhbGlkYXRvcl9oYV9zaWduZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUF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@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator_ha_signer.d.ts","sourceRoot":"","sources":["../src/validator_ha_signer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;
|
|
1
|
+
{"version":3,"file":"validator_ha_signer.d.ts","sourceRoot":"","sources":["../src/validator_ha_signer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAGjE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAG3D,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAEhC,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,iBAAiB;IAO1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IANzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA4B;IAC/D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAa;IAE3C,YACE,EAAE,EAAE,0BAA0B,EACb,MAAM,EAAE,uBAAuB,EAkBjD;IAED;;;;;;;;;;;;;;;;OAgBG;IACG,kBAAkB,CACtB,gBAAgB,EAAE,UAAU,EAC5B,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,yBAAyB,EAClC,MAAM,EAAE,CAAC,WAAW,EAAE,QAAQ,KAAK,OAAO,CAAC,SAAS,CAAC,GACpD,OAAO,CAAC,SAAS,CAAC,CA+CpB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACG,KAAK,kBAEV;IAED;;;OAGG;IACG,IAAI,kBAGT;CACF"}
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
* This ensures that even with multiple validator nodes running, only one
|
|
6
6
|
* node will sign for a given duty (slot + duty type).
|
|
7
7
|
*/ import { createLogger } from '@aztec/foundation/log';
|
|
8
|
-
import { DutyType
|
|
8
|
+
import { DutyType } from './db/types.js';
|
|
9
9
|
import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
10
|
+
import { getBlockNumberFromSigningContext } from './types.js';
|
|
10
11
|
/**
|
|
11
12
|
* Validator High Availability Signer
|
|
12
13
|
*
|
|
@@ -30,21 +31,18 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
30
31
|
log;
|
|
31
32
|
slashingProtection;
|
|
32
33
|
rollupAddress;
|
|
33
|
-
|
|
34
|
-
metrics;
|
|
35
|
-
constructor(db, config, deps){
|
|
34
|
+
constructor(db, config){
|
|
36
35
|
this.config = config;
|
|
37
36
|
this.log = createLogger('validator-ha-signer');
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
if (!config.haSigningEnabled) {
|
|
38
|
+
// this shouldn't happen, the validator should use different signer for non-HA setups
|
|
39
|
+
throw new Error('Validator HA Signer is not enabled in config');
|
|
40
|
+
}
|
|
40
41
|
if (!config.nodeId || config.nodeId === '') {
|
|
41
42
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
42
43
|
}
|
|
43
44
|
this.rollupAddress = config.l1Contracts.rollupAddress;
|
|
44
|
-
this.slashingProtection = new SlashingProtectionService(db, config
|
|
45
|
-
metrics: deps.metrics,
|
|
46
|
-
dateProvider: deps.dateProvider
|
|
47
|
-
});
|
|
45
|
+
this.slashingProtection = new SlashingProtectionService(db, config);
|
|
48
46
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
49
47
|
nodeId: config.nodeId,
|
|
50
48
|
rollupAddress: this.rollupAddress.toString()
|
|
@@ -67,8 +65,6 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
67
65
|
* @throws DutyAlreadySignedError if the duty was already signed (expected in HA)
|
|
68
66
|
* @throws SlashingProtectionError if attempting to sign different data for same slot (expected in HA)
|
|
69
67
|
*/ async signWithProtection(validatorAddress, messageHash, context, signFn) {
|
|
70
|
-
const startTime = this.dateProvider.now();
|
|
71
|
-
const dutyType = context.dutyType;
|
|
72
68
|
let dutyIdentifier;
|
|
73
69
|
if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
|
|
74
70
|
dutyIdentifier = {
|
|
@@ -87,7 +83,6 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
87
83
|
};
|
|
88
84
|
}
|
|
89
85
|
// Acquire lock and get the token for ownership verification
|
|
90
|
-
// DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
|
|
91
86
|
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
92
87
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
93
88
|
...dutyIdentifier,
|
|
@@ -105,7 +100,6 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
105
100
|
...dutyIdentifier,
|
|
106
101
|
lockToken
|
|
107
102
|
});
|
|
108
|
-
this.metrics.recordSigningError(dutyType);
|
|
109
103
|
throw error;
|
|
110
104
|
}
|
|
111
105
|
// Record success (only succeeds if we own the lock)
|
|
@@ -115,8 +109,6 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
115
109
|
nodeId: this.config.nodeId,
|
|
116
110
|
lockToken
|
|
117
111
|
});
|
|
118
|
-
const duration = this.dateProvider.now() - startTime;
|
|
119
|
-
this.metrics.recordSigningSuccess(dutyType, duration);
|
|
120
112
|
return signature;
|
|
121
113
|
}
|
|
122
114
|
/**
|