@aztec/validator-ha-signer 0.0.1-commit.96bb3f7 → 0.0.1-commit.96dac018d

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.
Files changed (50) hide show
  1. package/README.md +52 -37
  2. package/dest/db/postgres.d.ts +34 -5
  3. package/dest/db/postgres.d.ts.map +1 -1
  4. package/dest/db/postgres.js +80 -22
  5. package/dest/db/schema.d.ts +21 -10
  6. package/dest/db/schema.d.ts.map +1 -1
  7. package/dest/db/schema.js +49 -20
  8. package/dest/db/types.d.ts +76 -31
  9. package/dest/db/types.d.ts.map +1 -1
  10. package/dest/db/types.js +32 -8
  11. package/dest/errors.d.ts +9 -5
  12. package/dest/errors.d.ts.map +1 -1
  13. package/dest/errors.js +7 -4
  14. package/dest/factory.d.ts +6 -14
  15. package/dest/factory.d.ts.map +1 -1
  16. package/dest/factory.js +17 -12
  17. package/dest/metrics.d.ts +51 -0
  18. package/dest/metrics.d.ts.map +1 -0
  19. package/dest/metrics.js +103 -0
  20. package/dest/migrations.d.ts +1 -1
  21. package/dest/migrations.d.ts.map +1 -1
  22. package/dest/migrations.js +13 -2
  23. package/dest/slashing_protection_service.d.ts +25 -6
  24. package/dest/slashing_protection_service.d.ts.map +1 -1
  25. package/dest/slashing_protection_service.js +72 -20
  26. package/dest/test/pglite_pool.d.ts +92 -0
  27. package/dest/test/pglite_pool.d.ts.map +1 -0
  28. package/dest/test/pglite_pool.js +210 -0
  29. package/dest/types.d.ts +38 -18
  30. package/dest/types.d.ts.map +1 -1
  31. package/dest/types.js +4 -1
  32. package/dest/validator_ha_signer.d.ts +18 -13
  33. package/dest/validator_ha_signer.d.ts.map +1 -1
  34. package/dest/validator_ha_signer.js +46 -33
  35. package/package.json +13 -10
  36. package/src/db/postgres.ts +101 -21
  37. package/src/db/schema.ts +51 -20
  38. package/src/db/types.ts +110 -31
  39. package/src/errors.ts +7 -2
  40. package/src/factory.ts +20 -14
  41. package/src/metrics.ts +138 -0
  42. package/src/migrations.ts +17 -1
  43. package/src/slashing_protection_service.ts +117 -25
  44. package/src/test/pglite_pool.ts +256 -0
  45. package/src/types.ts +63 -19
  46. package/src/validator_ha_signer.ts +66 -42
  47. package/dest/config.d.ts +0 -47
  48. package/dest/config.d.ts.map +0 -1
  49. package/dest/config.js +0 -64
  50. package/src/config.ts +0 -116
@@ -0,0 +1,256 @@
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
+
18
+ export interface PoolConfig {
19
+ pglite: PGliteInterface;
20
+ max?: number;
21
+ min?: number;
22
+ }
23
+
24
+ interface ClientConfig {
25
+ pglite: PGliteInterface;
26
+ host?: string;
27
+ port?: number;
28
+ ssl?: boolean;
29
+ }
30
+
31
+ export class Client extends EventEmitter {
32
+ protected pglite: PGliteInterface;
33
+ protected _connected = false;
34
+ readonly host: string;
35
+ readonly port: number;
36
+ readonly ssl: boolean;
37
+ readonly connection: object;
38
+
39
+ // Stub implementations for pg compatibility
40
+ readonly copyFrom = (): Writable => new Writable();
41
+ readonly copyTo = (): Readable => new Readable();
42
+ readonly pauseDrain = (): void => {};
43
+ readonly resumeDrain = (): void => {};
44
+ readonly escapeLiteral = (str: string): string => `'${str.replace(/'/g, "''")}'`;
45
+ readonly escapeIdentifier = (str: string): string => `"${str.replace(/"/g, '""')}"`;
46
+ readonly setTypeParser = (): void => {};
47
+ readonly getTypeParser = (): ((value: string) => unknown) => (value: string) => value;
48
+
49
+ constructor(config: ClientConfig) {
50
+ super();
51
+ this.pglite = config.pglite;
52
+ this.host = config.host || 'localhost';
53
+ this.port = config.port || 5432;
54
+ this.ssl = typeof config.ssl === 'boolean' ? config.ssl : !!config.ssl;
55
+ this.connection = {};
56
+ }
57
+
58
+ connect(): Promise<void> {
59
+ if (this._connected) {
60
+ return Promise.resolve();
61
+ }
62
+ this._connected = true;
63
+ this.emit('connect');
64
+ return Promise.resolve();
65
+ }
66
+
67
+ end(): Promise<void> {
68
+ if (!this._connected) {
69
+ return Promise.resolve();
70
+ }
71
+ this._connected = false;
72
+ this.emit('end');
73
+ return Promise.resolve();
74
+ }
75
+
76
+ async query<R extends QueryResultRow = any>(text: string, values?: any[]): Promise<QueryResult<R>> {
77
+ if (!this._connected) {
78
+ throw new Error('Client is not connected');
79
+ }
80
+ const result = await this.pglite.query<R>(text, values);
81
+ return this.convertPGliteResult(result);
82
+ }
83
+
84
+ protected convertPGliteResult<R extends QueryResultRow>(result: {
85
+ rows: R[];
86
+ fields: Array<{ name: string; dataTypeID: number }>;
87
+ affectedRows?: number;
88
+ }): QueryResult<R> {
89
+ return {
90
+ command: '',
91
+ rowCount: 'affectedRows' in result ? (result.affectedRows ?? 0) : result.rows.length,
92
+ oid: 0,
93
+ fields: result.fields.map(field => ({
94
+ name: field.name,
95
+ tableID: 0,
96
+ columnID: 0,
97
+ dataTypeID: field.dataTypeID,
98
+ dataTypeSize: -1,
99
+ dataTypeModifier: -1,
100
+ format: 'text',
101
+ })),
102
+ rows: result.rows,
103
+ };
104
+ }
105
+
106
+ get connected(): boolean {
107
+ return this._connected;
108
+ }
109
+ }
110
+
111
+ export class Pool extends EventEmitter {
112
+ private clients: PoolClient[] = [];
113
+ private availableClients: PoolClient[] = [];
114
+ private waitingQueue: Array<(client: PoolClient) => void> = [];
115
+ private _ended = false;
116
+ private pglite: PGliteInterface;
117
+ private _config: PoolConfig;
118
+
119
+ readonly expiredCount = 0;
120
+ readonly options: PoolConfig;
121
+
122
+ constructor(config: PoolConfig) {
123
+ super();
124
+ this._config = { max: 10, min: 0, ...config };
125
+ this.pglite = config.pglite;
126
+ this.options = config;
127
+ }
128
+
129
+ get totalCount(): number {
130
+ return this.clients.length;
131
+ }
132
+
133
+ get idleCount(): number {
134
+ return this.availableClients.length;
135
+ }
136
+
137
+ get waitingCount(): number {
138
+ return this.waitingQueue.length;
139
+ }
140
+
141
+ get ending(): boolean {
142
+ return this._ended;
143
+ }
144
+
145
+ get ended(): boolean {
146
+ return this._ended;
147
+ }
148
+
149
+ connect(): Promise<PoolClient> {
150
+ if (this._ended) {
151
+ return Promise.reject(new Error('Pool is ended'));
152
+ }
153
+
154
+ if (this.availableClients.length > 0) {
155
+ const client = this.availableClients.pop()!;
156
+ client._markInUse();
157
+ return Promise.resolve(client);
158
+ }
159
+
160
+ if (this.clients.length < (this._config.max || 10)) {
161
+ const client = new PoolClient(this.pglite, this);
162
+ this.clients.push(client);
163
+ return Promise.resolve(client);
164
+ }
165
+
166
+ return new Promise(resolve => {
167
+ this.waitingQueue.push(resolve);
168
+ });
169
+ }
170
+
171
+ async query<R extends QueryResultRow = any>(text: string, values?: any[]): Promise<QueryResult<R>> {
172
+ const client = await this.connect();
173
+ try {
174
+ return await client.query<R>(text, values);
175
+ } finally {
176
+ client.release();
177
+ }
178
+ }
179
+
180
+ releaseClient(client: PoolClient): void {
181
+ const index = this.clients.indexOf(client);
182
+ if (index !== -1) {
183
+ client._markAvailable();
184
+ if (this.waitingQueue.length > 0) {
185
+ const resolve = this.waitingQueue.shift()!;
186
+ client._markInUse();
187
+ resolve(client);
188
+ } else {
189
+ this.availableClients.push(client);
190
+ }
191
+ }
192
+ }
193
+
194
+ end(): Promise<void> {
195
+ this._ended = true;
196
+ this.clients.forEach(client => client._markReleased());
197
+ this.clients = [];
198
+ this.availableClients = [];
199
+ this.emit('end');
200
+ return Promise.resolve();
201
+ }
202
+ }
203
+
204
+ export class PoolClient extends Client {
205
+ private pool: Pool;
206
+ private _released = false;
207
+ private _inUse = true;
208
+ private _userReleased = false;
209
+
210
+ constructor(pglite: PGliteInterface, pool: Pool) {
211
+ super({ pglite });
212
+ this.pool = pool;
213
+ this._connected = true;
214
+ }
215
+
216
+ override async query<R extends QueryResultRow = any>(text: string, values?: any[]): Promise<QueryResult<R>> {
217
+ if (this._userReleased && !this._inUse) {
218
+ throw new Error('Client has been released back to the pool');
219
+ }
220
+ const result = await this.pglite.query<R>(text, values);
221
+ return this.convertPGliteResult(result);
222
+ }
223
+
224
+ release(): void {
225
+ if (this._released || this._userReleased) {
226
+ return;
227
+ }
228
+ this._userReleased = true;
229
+ this.pool.releaseClient(this);
230
+ }
231
+
232
+ override end(): Promise<void> {
233
+ this.release();
234
+ return Promise.resolve();
235
+ }
236
+
237
+ _markInUse(): void {
238
+ this._inUse = true;
239
+ this._userReleased = false;
240
+ }
241
+
242
+ _markAvailable(): void {
243
+ this._inUse = false;
244
+ this._userReleased = false;
245
+ }
246
+
247
+ _markReleased(): void {
248
+ this._released = true;
249
+ this._inUse = false;
250
+ this._userReleased = true;
251
+ }
252
+
253
+ override get connected(): boolean {
254
+ return this._connected && !this._released;
255
+ }
256
+ }
package/src/types.ts CHANGED
@@ -1,27 +1,45 @@
1
+ import { SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import { DateProvider } from '@aztec/foundation/timer';
4
+ import {
5
+ DutyType,
6
+ type HAProtectedSigningContext,
7
+ type SigningContext,
8
+ type ValidatorHASignerConfig,
9
+ getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib,
10
+ isHAProtectedContext,
11
+ } from '@aztec/stdlib/ha-signing';
12
+ import type { TelemetryClient } from '@aztec/telemetry-client';
2
13
 
3
14
  import type { Pool } from 'pg';
4
15
 
5
- import type { CreateHASignerConfig, SlashingProtectionConfig } from './config.js';
6
16
  import type {
17
+ BlockProposalDutyIdentifier,
7
18
  CheckAndRecordParams,
8
19
  DeleteDutyParams,
9
20
  DutyIdentifier,
10
- DutyType,
21
+ DutyRow,
22
+ OtherDutyIdentifier,
11
23
  RecordSuccessParams,
12
24
  ValidatorDutyRecord,
13
25
  } from './db/types.js';
14
26
 
15
27
  export type {
28
+ BlockProposalDutyIdentifier,
16
29
  CheckAndRecordParams,
17
- CreateHASignerConfig,
18
30
  DeleteDutyParams,
19
31
  DutyIdentifier,
32
+ DutyRow,
33
+ HAProtectedSigningContext,
34
+ OtherDutyIdentifier,
20
35
  RecordSuccessParams,
21
- SlashingProtectionConfig,
36
+ SigningContext,
22
37
  ValidatorDutyRecord,
38
+ ValidatorHASignerConfig,
23
39
  };
24
- export { DutyStatus, DutyType } from './db/types.js';
40
+ export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
41
+ export { isHAProtectedContext };
42
+ export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
25
43
 
26
44
  /**
27
45
  * Result of tryInsertOrGetExisting operation
@@ -42,18 +60,14 @@ export interface CreateHASignerDeps {
42
60
  * If provided, databaseUrl and poolConfig are ignored
43
61
  */
44
62
  pool?: Pool;
45
- }
46
-
47
- /**
48
- * Context required for slashing protection during signing operations
49
- */
50
- export interface SigningContext {
51
- /** Slot number for this duty */
52
- slot: bigint;
53
- /** Block number for this duty */
54
- blockNumber: bigint;
55
- /** Type of duty being performed */
56
- dutyType: DutyType;
63
+ /**
64
+ * Optional telemetry client for metrics
65
+ */
66
+ telemetryClient?: TelemetryClient;
67
+ /**
68
+ * Optional date provider for timestamps
69
+ */
70
+ dateProvider?: DateProvider;
57
71
  }
58
72
 
59
73
  /**
@@ -81,11 +95,13 @@ export interface SlashingProtectionDatabase {
81
95
  * @returns true if the update succeeded, false if token didn't match or duty not found
82
96
  */
83
97
  updateDutySigned(
98
+ rollupAddress: EthAddress,
84
99
  validatorAddress: EthAddress,
85
- slot: bigint,
100
+ slot: SlotNumber,
86
101
  dutyType: DutyType,
87
102
  signature: string,
88
103
  lockToken: string,
104
+ blockIndexWithinCheckpoint: number,
89
105
  ): Promise<boolean>;
90
106
 
91
107
  /**
@@ -95,11 +111,39 @@ export interface SlashingProtectionDatabase {
95
111
  *
96
112
  * @returns true if the delete succeeded, false if token didn't match or duty not found
97
113
  */
98
- deleteDuty(validatorAddress: EthAddress, slot: bigint, dutyType: DutyType, lockToken: string): Promise<boolean>;
114
+ deleteDuty(
115
+ rollupAddress: EthAddress,
116
+ validatorAddress: EthAddress,
117
+ slot: SlotNumber,
118
+ dutyType: DutyType,
119
+ lockToken: string,
120
+ blockIndexWithinCheckpoint: number,
121
+ ): Promise<boolean>;
99
122
 
100
123
  /**
101
124
  * Cleanup own stuck duties
102
125
  * @returns the number of duties cleaned up
103
126
  */
104
127
  cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number>;
128
+
129
+ /**
130
+ * Cleanup duties with outdated rollup address.
131
+ * Removes all duties where the rollup address doesn't match the current one.
132
+ * Used after a rollup upgrade to clean up duties for the old rollup.
133
+ * @returns the number of duties cleaned up
134
+ */
135
+ cleanupOutdatedRollupDuties(currentRollupAddress: EthAddress): Promise<number>;
136
+
137
+ /**
138
+ * Cleanup old signed duties.
139
+ * Removes only signed duties older than the specified age.
140
+ * @returns the number of duties cleaned up
141
+ */
142
+ cleanupOldDuties(maxAgeMs: number): Promise<number>;
143
+
144
+ /**
145
+ * Close the database connection.
146
+ * Should be called during graceful shutdown.
147
+ */
148
+ close(): Promise<void>;
105
149
  }
@@ -6,13 +6,26 @@
6
6
  * node will sign for a given duty (slot + duty type).
7
7
  */
8
8
  import type { Buffer32 } from '@aztec/foundation/buffer';
9
- import type { EthAddress } from '@aztec/foundation/eth-address';
9
+ import { EthAddress } from '@aztec/foundation/eth-address';
10
10
  import type { Signature } from '@aztec/foundation/eth-signature';
11
11
  import { type Logger, createLogger } from '@aztec/foundation/log';
12
+ import type { DateProvider } from '@aztec/foundation/timer';
13
+ import {
14
+ DutyType,
15
+ type HAProtectedSigningContext,
16
+ type ValidatorHASignerConfig,
17
+ getBlockNumberFromSigningContext,
18
+ } from '@aztec/stdlib/ha-signing';
12
19
 
13
- import type { CreateHASignerConfig } from './config.js';
20
+ import type { DutyIdentifier } from './db/types.js';
21
+ import type { HASignerMetrics } from './metrics.js';
14
22
  import { SlashingProtectionService } from './slashing_protection_service.js';
15
- import type { SigningContext, SlashingProtectionDatabase } from './types.js';
23
+ import type { SlashingProtectionDatabase } from './types.js';
24
+
25
+ export interface ValidatorHASignerDeps {
26
+ metrics: HASignerMetrics;
27
+ dateProvider: DateProvider;
28
+ }
16
29
 
17
30
  /**
18
31
  * Validator High Availability Signer
@@ -35,15 +48,23 @@ import type { SigningContext, SlashingProtectionDatabase } from './types.js';
35
48
  */
36
49
  export class ValidatorHASigner {
37
50
  private readonly log: Logger;
38
- private readonly slashingProtection: SlashingProtectionService | undefined;
51
+ private readonly slashingProtection: SlashingProtectionService;
52
+ private readonly rollupAddress: EthAddress;
53
+
54
+ private readonly dateProvider: DateProvider;
55
+ private readonly metrics: HASignerMetrics;
39
56
 
40
57
  constructor(
41
58
  db: SlashingProtectionDatabase,
42
- private readonly config: CreateHASignerConfig,
59
+ private readonly config: ValidatorHASignerConfig,
60
+ deps: ValidatorHASignerDeps,
43
61
  ) {
44
62
  this.log = createLogger('validator-ha-signer');
45
63
 
46
- if (!config.enabled) {
64
+ this.metrics = deps.metrics;
65
+ this.dateProvider = deps.dateProvider;
66
+
67
+ if (!config.haSigningEnabled) {
47
68
  // this shouldn't happen, the validator should use different signer for non-HA setups
48
69
  throw new Error('Validator HA Signer is not enabled in config');
49
70
  }
@@ -51,9 +72,14 @@ export class ValidatorHASigner {
51
72
  if (!config.nodeId || config.nodeId === '') {
52
73
  throw new Error('NODE_ID is required for high-availability setups');
53
74
  }
54
- this.slashingProtection = new SlashingProtectionService(db, config);
75
+ this.rollupAddress = config.l1Contracts.rollupAddress;
76
+ this.slashingProtection = new SlashingProtectionService(db, config, {
77
+ metrics: deps.metrics,
78
+ dateProvider: deps.dateProvider,
79
+ });
55
80
  this.log.info('Validator HA Signer initialized with slashing protection', {
56
81
  nodeId: config.nodeId,
82
+ rollupAddress: this.rollupAddress.toString(),
57
83
  });
58
84
  }
59
85
 
@@ -67,7 +93,7 @@ export class ValidatorHASigner {
67
93
  *
68
94
  * @param validatorAddress - The validator's Ethereum address
69
95
  * @param messageHash - The hash to be signed
70
- * @param context - The signing context (slot, block number, duty type)
96
+ * @param context - The signing context (HA-protected duty types only)
71
97
  * @param signFn - Function that performs the actual signing
72
98
  * @returns The signature
73
99
  *
@@ -77,29 +103,36 @@ export class ValidatorHASigner {
77
103
  async signWithProtection(
78
104
  validatorAddress: EthAddress,
79
105
  messageHash: Buffer32,
80
- context: SigningContext,
106
+ context: HAProtectedSigningContext,
81
107
  signFn: (messageHash: Buffer32) => Promise<Signature>,
82
108
  ): Promise<Signature> {
83
- // If slashing protection is disabled, just sign directly
84
- if (!this.slashingProtection) {
85
- this.log.info('Signing without slashing protection enabled', {
86
- validatorAddress: validatorAddress.toString(),
87
- nodeId: this.config.nodeId,
109
+ const startTime = this.dateProvider.now();
110
+ const dutyType = context.dutyType;
111
+
112
+ let dutyIdentifier: DutyIdentifier;
113
+ if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
114
+ dutyIdentifier = {
115
+ rollupAddress: this.rollupAddress,
116
+ validatorAddress,
117
+ slot: context.slot,
118
+ blockIndexWithinCheckpoint: context.blockIndexWithinCheckpoint,
88
119
  dutyType: context.dutyType,
120
+ };
121
+ } else {
122
+ dutyIdentifier = {
123
+ rollupAddress: this.rollupAddress,
124
+ validatorAddress,
89
125
  slot: context.slot,
90
- blockNumber: context.blockNumber,
91
- });
92
- return await signFn(messageHash);
126
+ dutyType: context.dutyType,
127
+ };
93
128
  }
94
129
 
95
- const { slot, blockNumber, dutyType } = context;
96
-
97
130
  // Acquire lock and get the token for ownership verification
131
+ // DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
132
+ const blockNumber = getBlockNumberFromSigningContext(context);
98
133
  const lockToken = await this.slashingProtection.checkAndRecord({
99
- validatorAddress,
100
- slot,
134
+ ...dutyIdentifier,
101
135
  blockNumber,
102
- dutyType,
103
136
  messageHash: messageHash.toString(),
104
137
  nodeId: this.config.nodeId,
105
138
  });
@@ -110,33 +143,23 @@ export class ValidatorHASigner {
110
143
  signature = await signFn(messageHash);
111
144
  } catch (error: any) {
112
145
  // Delete duty to allow retry (only succeeds if we own the lock)
113
- await this.slashingProtection.deleteDuty({
114
- validatorAddress,
115
- slot,
116
- dutyType,
117
- lockToken,
118
- });
146
+ await this.slashingProtection.deleteDuty({ ...dutyIdentifier, lockToken });
147
+ this.metrics.recordSigningError(dutyType);
119
148
  throw error;
120
149
  }
121
150
 
122
151
  // Record success (only succeeds if we own the lock)
123
152
  await this.slashingProtection.recordSuccess({
124
- validatorAddress,
125
- slot,
126
- dutyType,
153
+ ...dutyIdentifier,
127
154
  signature,
128
155
  nodeId: this.config.nodeId,
129
156
  lockToken,
130
157
  });
131
158
 
132
- return signature;
133
- }
159
+ const duration = this.dateProvider.now() - startTime;
160
+ this.metrics.recordSigningSuccess(dutyType, duration);
134
161
 
135
- /**
136
- * Check if slashing protection is enabled
137
- */
138
- get isEnabled(): boolean {
139
- return this.slashingProtection !== undefined;
162
+ return signature;
140
163
  }
141
164
 
142
165
  /**
@@ -150,15 +173,16 @@ export class ValidatorHASigner {
150
173
  * Start the HA signer background tasks (cleanup of stuck duties).
151
174
  * Should be called after construction and before signing operations.
152
175
  */
153
- start() {
154
- this.slashingProtection?.start();
176
+ async start() {
177
+ await this.slashingProtection.start();
155
178
  }
156
179
 
157
180
  /**
158
- * Stop the HA signer background tasks.
181
+ * Stop the HA signer background tasks and close database connection.
159
182
  * Should be called during graceful shutdown.
160
183
  */
161
184
  async stop() {
162
- await this.slashingProtection?.stop();
185
+ await this.slashingProtection.stop();
186
+ await this.slashingProtection.close();
163
187
  }
164
188
  }
package/dest/config.d.ts DELETED
@@ -1,47 +0,0 @@
1
- import { type ConfigMappingsType } from '@aztec/foundation/config';
2
- /**
3
- * Configuration for the slashing protection service
4
- */
5
- export interface SlashingProtectionConfig {
6
- /** Whether slashing protection is enabled */
7
- enabled: boolean;
8
- /** Unique identifier for this node */
9
- nodeId: string;
10
- /** How long to wait between polls when a duty is being signed (ms) */
11
- pollingIntervalMs: number;
12
- /** Maximum time to wait for a duty being signed to complete (ms) */
13
- signingTimeoutMs: number;
14
- /** Maximum age of a stuck duty in ms */
15
- maxStuckDutiesAgeMs: number;
16
- }
17
- export declare const slashingProtectionConfigMappings: ConfigMappingsType<SlashingProtectionConfig>;
18
- export declare const defaultSlashingProtectionConfig: SlashingProtectionConfig;
19
- /**
20
- * Configuration for creating an HA signer with PostgreSQL backend
21
- */
22
- export interface CreateHASignerConfig extends SlashingProtectionConfig {
23
- /**
24
- * PostgreSQL connection string
25
- * Format: postgresql://user:password@host:port/database
26
- */
27
- databaseUrl: string;
28
- /**
29
- * PostgreSQL connection pool configuration
30
- */
31
- /** Maximum number of clients in the pool (default: 10) */
32
- poolMaxCount?: number;
33
- /** Minimum number of clients in the pool (default: 0) */
34
- poolMinCount?: number;
35
- /** Idle timeout in milliseconds (default: 10000) */
36
- poolIdleTimeoutMs?: number;
37
- /** Connection timeout in milliseconds (default: 0, no timeout) */
38
- poolConnectionTimeoutMs?: number;
39
- }
40
- export declare const createHASignerConfigMappings: ConfigMappingsType<CreateHASignerConfig>;
41
- /**
42
- * Returns the validator HA signer configuration from environment variables.
43
- * Note: If an environment variable is not set, the default value is used.
44
- * @returns The validator HA signer configuration.
45
- */
46
- export declare function getConfigEnvVars(): CreateHASignerConfig;
47
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFDTCxLQUFLLGtCQUFrQixFQUt4QixNQUFNLDBCQUEwQixDQUFDO0FBRWxDOztHQUVHO0FBQ0gsTUFBTSxXQUFXLHdCQUF3QjtJQUN2Qyw2Q0FBNkM7SUFDN0MsT0FBTyxFQUFFLE9BQU8sQ0FBQztJQUNqQixzQ0FBc0M7SUFDdEMsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUNmLHNFQUFzRTtJQUN0RSxpQkFBaUIsRUFBRSxNQUFNLENBQUM7SUFDMUIsb0VBQW9FO0lBQ3BFLGdCQUFnQixFQUFFLE1BQU0sQ0FBQztJQUN6Qix3Q0FBd0M7SUFDeEMsbUJBQW1CLEVBQUUsTUFBTSxDQUFDO0NBQzdCO0FBRUQsZUFBTyxNQUFNLGdDQUFnQyxFQUFFLGtCQUFrQixDQUFDLHdCQUF3QixDQTJCekYsQ0FBQztBQUVGLGVBQU8sTUFBTSwrQkFBK0IsRUFBRSx3QkFFN0MsQ0FBQztBQUVGOztHQUVHO0FBQ0gsTUFBTSxXQUFXLG9CQUFxQixTQUFRLHdCQUF3QjtJQUNwRTs7O09BR0c7SUFDSCxXQUFXLEVBQUUsTUFBTSxDQUFDO0lBQ3BCOztPQUVHO0lBQ0gsMERBQTBEO0lBQzFELFlBQVksQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUN0Qix5REFBeUQ7SUFDekQsWUFBWSxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQ3RCLG9EQUFvRDtJQUNwRCxpQkFBaUIsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUMzQixrRUFBa0U7SUFDbEUsdUJBQXVCLENBQUMsRUFBRSxNQUFNLENBQUM7Q0FDbEM7QUFFRCxlQUFPLE1BQU0sNEJBQTRCLEVBQUUsa0JBQWtCLENBQUMsb0JBQW9CLENBMkJqRixDQUFDO0FBRUY7Ozs7R0FJRztBQUNILHdCQUFnQixnQkFBZ0IsSUFBSSxvQkFBb0IsQ0FFdkQifQ==
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAKxB,MAAM,0BAA0B,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,gBAAgB,EAAE,MAAM,CAAC;IACzB,wCAAwC;IACxC,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,eAAO,MAAM,gCAAgC,EAAE,kBAAkB,CAAC,wBAAwB,CA2BzF,CAAC;AAEF,eAAO,MAAM,+BAA+B,EAAE,wBAE7C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,wBAAwB;IACpE;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;OAEG;IACH,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kEAAkE;IAClE,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,eAAO,MAAM,4BAA4B,EAAE,kBAAkB,CAAC,oBAAoB,CA2BjF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,oBAAoB,CAEvD"}
package/dest/config.js DELETED
@@ -1,64 +0,0 @@
1
- import { booleanConfigHelper, getConfigFromMappings, getDefaultConfig, numberConfigHelper } from '@aztec/foundation/config';
2
- export const slashingProtectionConfigMappings = {
3
- enabled: {
4
- env: 'SLASHING_PROTECTION_ENABLED',
5
- description: 'Whether slashing protection is enabled',
6
- ...booleanConfigHelper(true)
7
- },
8
- nodeId: {
9
- env: 'SLASHING_PROTECTION_NODE_ID',
10
- description: 'The unique identifier for this node',
11
- defaultValue: ''
12
- },
13
- pollingIntervalMs: {
14
- env: 'SLASHING_PROTECTION_POLLING_INTERVAL_MS',
15
- description: 'The number of ms to wait between polls when a duty is being signed',
16
- ...numberConfigHelper(100)
17
- },
18
- signingTimeoutMs: {
19
- env: 'SLASHING_PROTECTION_SIGNING_TIMEOUT_MS',
20
- description: 'The maximum time to wait for a duty being signed to complete',
21
- ...numberConfigHelper(3_000)
22
- },
23
- maxStuckDutiesAgeMs: {
24
- env: 'SLASHING_PROTECTION_MAX_STUCK_DUTIES_AGE_MS',
25
- description: 'The maximum age of a stuck duty in ms',
26
- // hard-coding at current 2 slot duration. This should be set by the validator on init
27
- ...numberConfigHelper(72_000)
28
- }
29
- };
30
- export const defaultSlashingProtectionConfig = getDefaultConfig(slashingProtectionConfigMappings);
31
- export const createHASignerConfigMappings = {
32
- ...slashingProtectionConfigMappings,
33
- databaseUrl: {
34
- env: 'VALIDATOR_HA_DATABASE_URL',
35
- description: 'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)'
36
- },
37
- poolMaxCount: {
38
- env: 'VALIDATOR_HA_POOL_MAX',
39
- description: 'Maximum number of clients in the pool',
40
- ...numberConfigHelper(10)
41
- },
42
- poolMinCount: {
43
- env: 'VALIDATOR_HA_POOL_MIN',
44
- description: 'Minimum number of clients in the pool',
45
- ...numberConfigHelper(0)
46
- },
47
- poolIdleTimeoutMs: {
48
- env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
49
- description: 'Idle timeout in milliseconds',
50
- ...numberConfigHelper(10_000)
51
- },
52
- poolConnectionTimeoutMs: {
53
- env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
54
- description: 'Connection timeout in milliseconds (0 means no timeout)',
55
- ...numberConfigHelper(0)
56
- }
57
- };
58
- /**
59
- * Returns the validator HA signer configuration from environment variables.
60
- * Note: If an environment variable is not set, the default value is used.
61
- * @returns The validator HA signer configuration.
62
- */ export function getConfigEnvVars() {
63
- return getConfigFromMappings(createHASignerConfigMappings);
64
- }