@aztec/validator-ha-signer 0.0.1-commit.d431d1c → 0.0.1-commit.d939eb5aa

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 (54) hide show
  1. package/README.md +10 -2
  2. package/dest/db/index.d.ts +2 -1
  3. package/dest/db/index.d.ts.map +1 -1
  4. package/dest/db/index.js +1 -0
  5. package/dest/db/lmdb.d.ts +66 -0
  6. package/dest/db/lmdb.d.ts.map +1 -0
  7. package/dest/db/lmdb.js +189 -0
  8. package/dest/db/migrations/1_initial-schema.d.ts +4 -2
  9. package/dest/db/migrations/1_initial-schema.d.ts.map +1 -1
  10. package/dest/db/migrations/1_initial-schema.js +34 -4
  11. package/dest/db/migrations/2_add-checkpoint-number.d.ts +7 -0
  12. package/dest/db/migrations/2_add-checkpoint-number.d.ts.map +1 -0
  13. package/dest/db/migrations/2_add-checkpoint-number.js +17 -0
  14. package/dest/db/postgres.d.ts +20 -4
  15. package/dest/db/postgres.d.ts.map +1 -1
  16. package/dest/db/postgres.js +46 -17
  17. package/dest/db/schema.d.ts +18 -11
  18. package/dest/db/schema.d.ts.map +1 -1
  19. package/dest/db/schema.js +45 -23
  20. package/dest/db/types.d.ts +52 -22
  21. package/dest/db/types.d.ts.map +1 -1
  22. package/dest/db/types.js +31 -15
  23. package/dest/factory.d.ts +39 -4
  24. package/dest/factory.d.ts.map +1 -1
  25. package/dest/factory.js +75 -5
  26. package/dest/metrics.d.ts +51 -0
  27. package/dest/metrics.d.ts.map +1 -0
  28. package/dest/metrics.js +103 -0
  29. package/dest/slashing_protection_service.d.ts +19 -6
  30. package/dest/slashing_protection_service.d.ts.map +1 -1
  31. package/dest/slashing_protection_service.js +57 -17
  32. package/dest/types.d.ts +33 -72
  33. package/dest/types.d.ts.map +1 -1
  34. package/dest/types.js +4 -20
  35. package/dest/validator_ha_signer.d.ts +15 -6
  36. package/dest/validator_ha_signer.d.ts.map +1 -1
  37. package/dest/validator_ha_signer.js +26 -11
  38. package/package.json +10 -5
  39. package/src/db/index.ts +1 -0
  40. package/src/db/lmdb.ts +265 -0
  41. package/src/db/migrations/1_initial-schema.ts +35 -4
  42. package/src/db/migrations/2_add-checkpoint-number.ts +19 -0
  43. package/src/db/postgres.ts +47 -12
  44. package/src/db/schema.ts +47 -23
  45. package/src/db/types.ts +72 -20
  46. package/src/factory.ts +93 -4
  47. package/src/metrics.ts +138 -0
  48. package/src/slashing_protection_service.ts +79 -21
  49. package/src/types.ts +56 -103
  50. package/src/validator_ha_signer.ts +44 -15
  51. package/dest/config.d.ts +0 -79
  52. package/dest/config.d.ts.map +0 -1
  53. package/dest/config.js +0 -73
  54. package/src/config.ts +0 -125
package/src/types.ts CHANGED
@@ -1,36 +1,51 @@
1
- import {
2
- BlockNumber,
3
- type CheckpointNumber,
4
- type IndexWithinCheckpoint,
5
- type SlotNumber,
6
- } from '@aztec/foundation/branded-types';
1
+ import { SlotNumber } from '@aztec/foundation/branded-types';
7
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import { DateProvider } from '@aztec/foundation/timer';
4
+ import {
5
+ type AttestationSigningContext,
6
+ type CheckpointProposalSigningContext,
7
+ DutyType,
8
+ type HAProtectedSigningContext,
9
+ type SigningContext,
10
+ type ValidatorHASignerConfig,
11
+ getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib,
12
+ getCheckpointNumberFromSigningContext as getCheckpointNumberFromSigningContextFromStdlib,
13
+ isHAProtectedContext,
14
+ } from '@aztec/stdlib/ha-signing';
15
+ import type { TelemetryClient } from '@aztec/telemetry-client';
8
16
 
9
17
  import type { Pool } from 'pg';
10
18
 
11
- import type { ValidatorHASignerConfig } from './config.js';
12
- import {
13
- type BlockProposalDutyIdentifier,
14
- type CheckAndRecordParams,
15
- type DeleteDutyParams,
16
- type DutyIdentifier,
17
- DutyType,
18
- type OtherDutyIdentifier,
19
- type RecordSuccessParams,
20
- type ValidatorDutyRecord,
19
+ import type {
20
+ BlockProposalDutyIdentifier,
21
+ CheckAndRecordParams,
22
+ DeleteDutyParams,
23
+ DutyIdentifier,
24
+ DutyRow,
25
+ OtherDutyIdentifier,
26
+ RecordSuccessParams,
27
+ ValidatorDutyRecord,
21
28
  } from './db/types.js';
22
29
 
23
30
  export type {
31
+ AttestationSigningContext,
24
32
  BlockProposalDutyIdentifier,
25
33
  CheckAndRecordParams,
34
+ CheckpointProposalSigningContext,
26
35
  DeleteDutyParams,
27
36
  DutyIdentifier,
37
+ DutyRow,
38
+ HAProtectedSigningContext,
28
39
  OtherDutyIdentifier,
29
40
  RecordSuccessParams,
41
+ SigningContext,
30
42
  ValidatorDutyRecord,
31
43
  ValidatorHASignerConfig,
32
44
  };
33
45
  export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
46
+ export { isHAProtectedContext };
47
+ export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
48
+ export { getCheckpointNumberFromSigningContextFromStdlib as getCheckpointNumberFromSigningContext };
34
49
 
35
50
  /**
36
51
  * Result of tryInsertOrGetExisting operation
@@ -51,99 +66,20 @@ export interface CreateHASignerDeps {
51
66
  * If provided, databaseUrl and poolConfig are ignored
52
67
  */
53
68
  pool?: Pool;
54
- }
55
-
56
- /**
57
- * Base context for signing operations
58
- */
59
- interface BaseSigningContext {
60
- /** Slot number for this duty */
61
- slot: SlotNumber;
62
69
  /**
63
- * Block or checkpoint number for this duty.
64
- * For block proposals, this is the block number.
65
- * For checkpoint proposals, this is the checkpoint number.
70
+ * Optional telemetry client for metrics
66
71
  */
67
- blockNumber: BlockNumber | CheckpointNumber;
68
- }
69
-
70
- /**
71
- * Signing context for block proposals.
72
- * blockIndexWithinCheckpoint is REQUIRED and must be >= 0.
73
- */
74
- export interface BlockProposalSigningContext extends BaseSigningContext {
75
- /** Block index within checkpoint (0, 1, 2...). Required for block proposals. */
76
- blockIndexWithinCheckpoint: IndexWithinCheckpoint;
77
- dutyType: DutyType.BLOCK_PROPOSAL;
78
- }
79
-
80
- /**
81
- * Signing context for non-block-proposal duties that require HA protection.
82
- * blockIndexWithinCheckpoint is not applicable (internally always -1).
83
- */
84
- export interface OtherSigningContext extends BaseSigningContext {
85
- dutyType: DutyType.CHECKPOINT_PROPOSAL | DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS;
86
- }
87
-
88
- /**
89
- * Signing context for governance/slashing votes which only need slot for HA protection.
90
- * blockNumber is not applicable (internally always 0).
91
- */
92
- export interface VoteSigningContext {
93
- slot: SlotNumber;
94
- dutyType: DutyType.GOVERNANCE_VOTE | DutyType.SLASHING_VOTE;
95
- }
96
-
97
- /**
98
- * Signing context for duties which don't require slot/blockNumber
99
- * as they don't need HA protection (AUTH_REQUEST, TXS).
100
- */
101
- export interface NoHAProtectionSigningContext {
102
- dutyType: DutyType.AUTH_REQUEST | DutyType.TXS;
103
- }
104
-
105
- /**
106
- * Signing contexts that require HA protection (excludes AUTH_REQUEST).
107
- * Used by the HA signer's signWithProtection method.
108
- */
109
- export type HAProtectedSigningContext = BlockProposalSigningContext | OtherSigningContext | VoteSigningContext;
110
-
111
- /**
112
- * Type guard to check if a SigningContext requires HA protection.
113
- * Returns true for contexts that need HA protection, false for AUTH_REQUEST and TXS.
114
- */
115
- export function isHAProtectedContext(context: SigningContext): context is HAProtectedSigningContext {
116
- return context.dutyType !== DutyType.AUTH_REQUEST && context.dutyType !== DutyType.TXS;
117
- }
118
-
119
- /**
120
- * Gets the block number from a signing context.
121
- * - Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE): returns BlockNumber(0)
122
- * - Other duties: returns the blockNumber from the context
123
- */
124
- export function getBlockNumberFromSigningContext(context: HAProtectedSigningContext): BlockNumber | CheckpointNumber {
125
- // Check for duty types that have blockNumber
126
- if (
127
- context.dutyType === DutyType.BLOCK_PROPOSAL ||
128
- context.dutyType === DutyType.CHECKPOINT_PROPOSAL ||
129
- context.dutyType === DutyType.ATTESTATION ||
130
- context.dutyType === DutyType.ATTESTATIONS_AND_SIGNERS
131
- ) {
132
- return context.blockNumber;
133
- }
134
- // Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE) don't have blockNumber
135
- return BlockNumber(0);
72
+ telemetryClient?: TelemetryClient;
73
+ /**
74
+ * Optional date provider for timestamps
75
+ */
76
+ dateProvider?: DateProvider;
136
77
  }
137
78
 
138
79
  /**
139
- * Context required for slashing protection during signing operations.
140
- * Uses discriminated union to enforce type safety:
141
- * - BLOCK_PROPOSAL duties MUST have blockIndexWithinCheckpoint >= 0
142
- * - Other duty types do NOT have blockIndexWithinCheckpoint (internally -1)
143
- * - Vote duties only need slot (blockNumber is internally 0)
144
- * - AUTH_REQUEST and TXS duties don't need slot/blockNumber (no HA protection needed)
80
+ * deps for creating a local signing protection signer
145
81
  */
146
- export type SigningContext = HAProtectedSigningContext | NoHAProtectionSigningContext;
82
+ export type CreateLocalSignerWithProtectionDeps = Omit<CreateHASignerDeps, 'pool'>;
147
83
 
148
84
  /**
149
85
  * Database interface for slashing protection operations
@@ -170,6 +106,7 @@ export interface SlashingProtectionDatabase {
170
106
  * @returns true if the update succeeded, false if token didn't match or duty not found
171
107
  */
172
108
  updateDutySigned(
109
+ rollupAddress: EthAddress,
173
110
  validatorAddress: EthAddress,
174
111
  slot: SlotNumber,
175
112
  dutyType: DutyType,
@@ -186,6 +123,7 @@ export interface SlashingProtectionDatabase {
186
123
  * @returns true if the delete succeeded, false if token didn't match or duty not found
187
124
  */
188
125
  deleteDuty(
126
+ rollupAddress: EthAddress,
189
127
  validatorAddress: EthAddress,
190
128
  slot: SlotNumber,
191
129
  dutyType: DutyType,
@@ -199,6 +137,21 @@ export interface SlashingProtectionDatabase {
199
137
  */
200
138
  cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number>;
201
139
 
140
+ /**
141
+ * Cleanup duties with outdated rollup address.
142
+ * Removes all duties where the rollup address doesn't match the current one.
143
+ * Used after a rollup upgrade to clean up duties for the old rollup.
144
+ * @returns the number of duties cleaned up
145
+ */
146
+ cleanupOutdatedRollupDuties(currentRollupAddress: EthAddress): Promise<number>;
147
+
148
+ /**
149
+ * Cleanup old signed duties.
150
+ * Removes only signed duties older than the specified age.
151
+ * @returns the number of duties cleaned up
152
+ */
153
+ cleanupOldDuties(maxAgeMs: number): Promise<number>;
154
+
202
155
  /**
203
156
  * Close the database connection.
204
157
  * Should be called during graceful shutdown.
@@ -6,18 +6,27 @@
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
-
13
- import type { ValidatorHASignerConfig } from './config.js';
14
- import { type DutyIdentifier, DutyType } from './db/types.js';
15
- import { SlashingProtectionService } from './slashing_protection_service.js';
12
+ import type { DateProvider } from '@aztec/foundation/timer';
16
13
  import {
14
+ type BaseSignerConfig,
15
+ DutyType,
17
16
  type HAProtectedSigningContext,
18
- type SlashingProtectionDatabase,
19
17
  getBlockNumberFromSigningContext,
20
- } from './types.js';
18
+ getCheckpointNumberFromSigningContext,
19
+ } from '@aztec/stdlib/ha-signing';
20
+
21
+ import type { DutyIdentifier } from './db/types.js';
22
+ import type { HASignerMetrics } from './metrics.js';
23
+ import { SlashingProtectionService } from './slashing_protection_service.js';
24
+ import type { SlashingProtectionDatabase } from './types.js';
25
+
26
+ export interface ValidatorHASignerDeps {
27
+ metrics: HASignerMetrics;
28
+ dateProvider: DateProvider;
29
+ }
21
30
 
22
31
  /**
23
32
  * Validator High Availability Signer
@@ -41,24 +50,32 @@ import {
41
50
  export class ValidatorHASigner {
42
51
  private readonly log: Logger;
43
52
  private readonly slashingProtection: SlashingProtectionService;
53
+ private readonly rollupAddress: EthAddress;
54
+
55
+ private readonly dateProvider: DateProvider;
56
+ private readonly metrics: HASignerMetrics;
44
57
 
45
58
  constructor(
46
59
  db: SlashingProtectionDatabase,
47
- private readonly config: ValidatorHASignerConfig,
60
+ private readonly config: BaseSignerConfig,
61
+ deps: ValidatorHASignerDeps,
48
62
  ) {
49
63
  this.log = createLogger('validator-ha-signer');
50
64
 
51
- if (!config.haSigningEnabled) {
52
- // this shouldn't happen, the validator should use different signer for non-HA setups
53
- throw new Error('Validator HA Signer is not enabled in config');
54
- }
65
+ this.metrics = deps.metrics;
66
+ this.dateProvider = deps.dateProvider;
55
67
 
56
68
  if (!config.nodeId || config.nodeId === '') {
57
69
  throw new Error('NODE_ID is required for high-availability setups');
58
70
  }
59
- this.slashingProtection = new SlashingProtectionService(db, config);
71
+ this.rollupAddress = config.l1Contracts.rollupAddress;
72
+ this.slashingProtection = new SlashingProtectionService(db, config, {
73
+ metrics: deps.metrics,
74
+ dateProvider: deps.dateProvider,
75
+ });
60
76
  this.log.info('Validator HA Signer initialized with slashing protection', {
61
77
  nodeId: config.nodeId,
78
+ rollupAddress: this.rollupAddress.toString(),
62
79
  });
63
80
  }
64
81
 
@@ -85,9 +102,13 @@ export class ValidatorHASigner {
85
102
  context: HAProtectedSigningContext,
86
103
  signFn: (messageHash: Buffer32) => Promise<Signature>,
87
104
  ): Promise<Signature> {
105
+ const startTime = this.dateProvider.now();
106
+ const dutyType = context.dutyType;
107
+
88
108
  let dutyIdentifier: DutyIdentifier;
89
109
  if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
90
110
  dutyIdentifier = {
111
+ rollupAddress: this.rollupAddress,
91
112
  validatorAddress,
92
113
  slot: context.slot,
93
114
  blockIndexWithinCheckpoint: context.blockIndexWithinCheckpoint,
@@ -95,6 +116,7 @@ export class ValidatorHASigner {
95
116
  };
96
117
  } else {
97
118
  dutyIdentifier = {
119
+ rollupAddress: this.rollupAddress,
98
120
  validatorAddress,
99
121
  slot: context.slot,
100
122
  dutyType: context.dutyType,
@@ -102,10 +124,13 @@ export class ValidatorHASigner {
102
124
  }
103
125
 
104
126
  // Acquire lock and get the token for ownership verification
127
+ // DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
105
128
  const blockNumber = getBlockNumberFromSigningContext(context);
129
+ const checkpointNumber = getCheckpointNumberFromSigningContext(context);
106
130
  const lockToken = await this.slashingProtection.checkAndRecord({
107
131
  ...dutyIdentifier,
108
132
  blockNumber,
133
+ checkpointNumber,
109
134
  messageHash: messageHash.toString(),
110
135
  nodeId: this.config.nodeId,
111
136
  });
@@ -117,6 +142,7 @@ export class ValidatorHASigner {
117
142
  } catch (error: any) {
118
143
  // Delete duty to allow retry (only succeeds if we own the lock)
119
144
  await this.slashingProtection.deleteDuty({ ...dutyIdentifier, lockToken });
145
+ this.metrics.recordSigningError(dutyType);
120
146
  throw error;
121
147
  }
122
148
 
@@ -128,6 +154,9 @@ export class ValidatorHASigner {
128
154
  lockToken,
129
155
  });
130
156
 
157
+ const duration = this.dateProvider.now() - startTime;
158
+ this.metrics.recordSigningSuccess(dutyType, duration);
159
+
131
160
  return signature;
132
161
  }
133
162
 
@@ -142,8 +171,8 @@ export class ValidatorHASigner {
142
171
  * Start the HA signer background tasks (cleanup of stuck duties).
143
172
  * Should be called after construction and before signing operations.
144
173
  */
145
- start() {
146
- this.slashingProtection.start();
174
+ async start() {
175
+ await this.slashingProtection.start();
147
176
  }
148
177
 
149
178
  /**
package/dest/config.d.ts DELETED
@@ -1,79 +0,0 @@
1
- import { type ConfigMappingsType } from '@aztec/foundation/config';
2
- import { z } from 'zod';
3
- /**
4
- * Configuration for the Validator HA Signer
5
- *
6
- * This config is used for distributed locking and slashing protection
7
- * when running multiple validator nodes in a high-availability setup.
8
- */
9
- export interface ValidatorHASignerConfig {
10
- /** Whether HA signing / slashing protection is enabled */
11
- haSigningEnabled: boolean;
12
- /** Unique identifier for this node */
13
- nodeId: string;
14
- /** How long to wait between polls when a duty is being signed (ms) */
15
- pollingIntervalMs: number;
16
- /** Maximum time to wait for a duty being signed to complete (ms) */
17
- signingTimeoutMs: number;
18
- /** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
19
- maxStuckDutiesAgeMs?: number;
20
- /**
21
- * PostgreSQL connection string
22
- * Format: postgresql://user:password@host:port/database
23
- */
24
- databaseUrl?: string;
25
- /**
26
- * PostgreSQL connection pool configuration
27
- */
28
- /** Maximum number of clients in the pool (default: 10) */
29
- poolMaxCount?: number;
30
- /** Minimum number of clients in the pool (default: 0) */
31
- poolMinCount?: number;
32
- /** Idle timeout in milliseconds (default: 10000) */
33
- poolIdleTimeoutMs?: number;
34
- /** Connection timeout in milliseconds (default: 0, no timeout) */
35
- poolConnectionTimeoutMs?: number;
36
- }
37
- export declare const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASignerConfig>;
38
- export declare const defaultValidatorHASignerConfig: ValidatorHASignerConfig;
39
- /**
40
- * Returns the validator HA signer configuration from environment variables.
41
- * Note: If an environment variable is not set, the default value is used.
42
- * @returns The validator HA signer configuration.
43
- */
44
- export declare function getConfigEnvVars(): ValidatorHASignerConfig;
45
- export declare const ValidatorHASignerConfigSchema: z.ZodObject<{
46
- haSigningEnabled: z.ZodBoolean;
47
- nodeId: z.ZodString;
48
- pollingIntervalMs: z.ZodNumber;
49
- signingTimeoutMs: z.ZodNumber;
50
- maxStuckDutiesAgeMs: z.ZodOptional<z.ZodNumber>;
51
- databaseUrl: z.ZodOptional<z.ZodString>;
52
- poolMaxCount: z.ZodOptional<z.ZodNumber>;
53
- poolMinCount: z.ZodOptional<z.ZodNumber>;
54
- poolIdleTimeoutMs: z.ZodOptional<z.ZodNumber>;
55
- poolConnectionTimeoutMs: z.ZodOptional<z.ZodNumber>;
56
- }, "strip", z.ZodTypeAny, {
57
- haSigningEnabled: boolean;
58
- nodeId: string;
59
- pollingIntervalMs: number;
60
- signingTimeoutMs: number;
61
- maxStuckDutiesAgeMs?: number | undefined;
62
- databaseUrl?: string | undefined;
63
- poolMaxCount?: number | undefined;
64
- poolMinCount?: number | undefined;
65
- poolIdleTimeoutMs?: number | undefined;
66
- poolConnectionTimeoutMs?: number | undefined;
67
- }, {
68
- haSigningEnabled: boolean;
69
- nodeId: string;
70
- pollingIntervalMs: number;
71
- signingTimeoutMs: number;
72
- maxStuckDutiesAgeMs?: number | undefined;
73
- databaseUrl?: string | undefined;
74
- poolMaxCount?: number | undefined;
75
- poolMinCount?: number | undefined;
76
- poolIdleTimeoutMs?: number | undefined;
77
- poolConnectionTimeoutMs?: number | undefined;
78
- }>;
79
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFDTCxLQUFLLGtCQUFrQixFQU14QixNQUFNLDBCQUEwQixDQUFDO0FBR2xDLE9BQU8sRUFBRSxDQUFDLEVBQUUsTUFBTSxLQUFLLENBQUM7QUFFeEI7Ozs7O0dBS0c7QUFDSCxNQUFNLFdBQVcsdUJBQXVCO0lBQ3RDLDBEQUEwRDtJQUMxRCxnQkFBZ0IsRUFBRSxPQUFPLENBQUM7SUFDMUIsc0NBQXNDO0lBQ3RDLE1BQU0sRUFBRSxNQUFNLENBQUM7SUFDZixzRUFBc0U7SUFDdEUsaUJBQWlCLEVBQUUsTUFBTSxDQUFDO0lBQzFCLG9FQUFvRTtJQUNwRSxnQkFBZ0IsRUFBRSxNQUFNLENBQUM7SUFDekIsa0dBQWtHO0lBQ2xHLG1CQUFtQixDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQzdCOzs7T0FHRztJQUNILFdBQVcsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUNyQjs7T0FFRztJQUNILDBEQUEwRDtJQUMxRCxZQUFZLENBQUMsRUFBRSxNQUFNLENBQUM7SUFDdEIseURBQXlEO0lBQ3pELFlBQVksQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUN0QixvREFBb0Q7SUFDcEQsaUJBQWlCLENBQUMsRUFBRSxNQUFNLENBQUM7SUFDM0Isa0VBQWtFO0lBQ2xFLHVCQUF1QixDQUFDLEVBQUUsTUFBTSxDQUFDO0NBQ2xDO0FBRUQsZUFBTyxNQUFNLCtCQUErQixFQUFFLGtCQUFrQixDQUFDLHVCQUF1QixDQW1EdkYsQ0FBQztBQUVGLGVBQU8sTUFBTSw4QkFBOEIsRUFBRSx1QkFFNUMsQ0FBQztBQUVGOzs7O0dBSUc7QUFDSCx3QkFBZ0IsZ0JBQWdCLElBQUksdUJBQXVCLENBRTFEO0FBRUQsZUFBTyxNQUFNLDZCQUE2Qjs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0VBV0UsQ0FBQyJ9
@@ -1 +0,0 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAMxB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IACtC,0DAA0D;IAC1D,gBAAgB,EAAE,OAAO,CAAC;IAC1B,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,gBAAgB,EAAE,MAAM,CAAC;IACzB,kGAAkG;IAClG,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;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,+BAA+B,EAAE,kBAAkB,CAAC,uBAAuB,CAmDvF,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,uBAE5C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,uBAAuB,CAE1D;AAED,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWE,CAAC"}
package/dest/config.js DELETED
@@ -1,73 +0,0 @@
1
- import { booleanConfigHelper, getConfigFromMappings, getDefaultConfig, numberConfigHelper, optionalNumberConfigHelper } from '@aztec/foundation/config';
2
- import { z } from 'zod';
3
- export const validatorHASignerConfigMappings = {
4
- haSigningEnabled: {
5
- env: 'VALIDATOR_HA_SIGNING_ENABLED',
6
- description: 'Whether HA signing / slashing protection is enabled',
7
- ...booleanConfigHelper(false)
8
- },
9
- nodeId: {
10
- env: 'VALIDATOR_HA_NODE_ID',
11
- description: 'The unique identifier for this node',
12
- defaultValue: ''
13
- },
14
- pollingIntervalMs: {
15
- env: 'VALIDATOR_HA_POLLING_INTERVAL_MS',
16
- description: 'The number of ms to wait between polls when a duty is being signed',
17
- ...numberConfigHelper(100)
18
- },
19
- signingTimeoutMs: {
20
- env: 'VALIDATOR_HA_SIGNING_TIMEOUT_MS',
21
- description: 'The maximum time to wait for a duty being signed to complete',
22
- ...numberConfigHelper(3_000)
23
- },
24
- maxStuckDutiesAgeMs: {
25
- env: 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS',
26
- description: 'The maximum age of a stuck duty in ms (defaults to 2x Aztec slot duration)',
27
- ...optionalNumberConfigHelper()
28
- },
29
- databaseUrl: {
30
- env: 'VALIDATOR_HA_DATABASE_URL',
31
- description: 'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)'
32
- },
33
- poolMaxCount: {
34
- env: 'VALIDATOR_HA_POOL_MAX',
35
- description: 'Maximum number of clients in the pool',
36
- ...numberConfigHelper(10)
37
- },
38
- poolMinCount: {
39
- env: 'VALIDATOR_HA_POOL_MIN',
40
- description: 'Minimum number of clients in the pool',
41
- ...numberConfigHelper(0)
42
- },
43
- poolIdleTimeoutMs: {
44
- env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
45
- description: 'Idle timeout in milliseconds',
46
- ...numberConfigHelper(10_000)
47
- },
48
- poolConnectionTimeoutMs: {
49
- env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
50
- description: 'Connection timeout in milliseconds (0 means no timeout)',
51
- ...numberConfigHelper(0)
52
- }
53
- };
54
- export const defaultValidatorHASignerConfig = getDefaultConfig(validatorHASignerConfigMappings);
55
- /**
56
- * Returns the validator HA signer configuration from environment variables.
57
- * Note: If an environment variable is not set, the default value is used.
58
- * @returns The validator HA signer configuration.
59
- */ export function getConfigEnvVars() {
60
- return getConfigFromMappings(validatorHASignerConfigMappings);
61
- }
62
- export const ValidatorHASignerConfigSchema = z.object({
63
- haSigningEnabled: z.boolean(),
64
- nodeId: z.string(),
65
- pollingIntervalMs: z.number().min(0),
66
- signingTimeoutMs: z.number().min(0),
67
- maxStuckDutiesAgeMs: z.number().min(0).optional(),
68
- databaseUrl: z.string().optional(),
69
- poolMaxCount: z.number().min(0).optional(),
70
- poolMinCount: z.number().min(0).optional(),
71
- poolIdleTimeoutMs: z.number().min(0).optional(),
72
- poolConnectionTimeoutMs: z.number().min(0).optional()
73
- });
package/src/config.ts DELETED
@@ -1,125 +0,0 @@
1
- import {
2
- type ConfigMappingsType,
3
- booleanConfigHelper,
4
- getConfigFromMappings,
5
- getDefaultConfig,
6
- numberConfigHelper,
7
- optionalNumberConfigHelper,
8
- } from '@aztec/foundation/config';
9
- import type { ZodFor } from '@aztec/foundation/schemas';
10
-
11
- import { z } from 'zod';
12
-
13
- /**
14
- * Configuration for the Validator HA Signer
15
- *
16
- * This config is used for distributed locking and slashing protection
17
- * when running multiple validator nodes in a high-availability setup.
18
- */
19
- export interface ValidatorHASignerConfig {
20
- /** Whether HA signing / slashing protection is enabled */
21
- haSigningEnabled: boolean;
22
- /** Unique identifier for this node */
23
- nodeId: string;
24
- /** How long to wait between polls when a duty is being signed (ms) */
25
- pollingIntervalMs: number;
26
- /** Maximum time to wait for a duty being signed to complete (ms) */
27
- signingTimeoutMs: number;
28
- /** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
29
- maxStuckDutiesAgeMs?: number;
30
- /**
31
- * PostgreSQL connection string
32
- * Format: postgresql://user:password@host:port/database
33
- */
34
- databaseUrl?: string;
35
- /**
36
- * PostgreSQL connection pool configuration
37
- */
38
- /** Maximum number of clients in the pool (default: 10) */
39
- poolMaxCount?: number;
40
- /** Minimum number of clients in the pool (default: 0) */
41
- poolMinCount?: number;
42
- /** Idle timeout in milliseconds (default: 10000) */
43
- poolIdleTimeoutMs?: number;
44
- /** Connection timeout in milliseconds (default: 0, no timeout) */
45
- poolConnectionTimeoutMs?: number;
46
- }
47
-
48
- export const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASignerConfig> = {
49
- haSigningEnabled: {
50
- env: 'VALIDATOR_HA_SIGNING_ENABLED',
51
- description: 'Whether HA signing / slashing protection is enabled',
52
- ...booleanConfigHelper(false),
53
- },
54
- nodeId: {
55
- env: 'VALIDATOR_HA_NODE_ID',
56
- description: 'The unique identifier for this node',
57
- defaultValue: '',
58
- },
59
- pollingIntervalMs: {
60
- env: 'VALIDATOR_HA_POLLING_INTERVAL_MS',
61
- description: 'The number of ms to wait between polls when a duty is being signed',
62
- ...numberConfigHelper(100),
63
- },
64
- signingTimeoutMs: {
65
- env: 'VALIDATOR_HA_SIGNING_TIMEOUT_MS',
66
- description: 'The maximum time to wait for a duty being signed to complete',
67
- ...numberConfigHelper(3_000),
68
- },
69
- maxStuckDutiesAgeMs: {
70
- env: 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS',
71
- description: 'The maximum age of a stuck duty in ms (defaults to 2x Aztec slot duration)',
72
- ...optionalNumberConfigHelper(),
73
- },
74
- databaseUrl: {
75
- env: 'VALIDATOR_HA_DATABASE_URL',
76
- description:
77
- 'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)',
78
- },
79
- poolMaxCount: {
80
- env: 'VALIDATOR_HA_POOL_MAX',
81
- description: 'Maximum number of clients in the pool',
82
- ...numberConfigHelper(10),
83
- },
84
- poolMinCount: {
85
- env: 'VALIDATOR_HA_POOL_MIN',
86
- description: 'Minimum number of clients in the pool',
87
- ...numberConfigHelper(0),
88
- },
89
- poolIdleTimeoutMs: {
90
- env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
91
- description: 'Idle timeout in milliseconds',
92
- ...numberConfigHelper(10_000),
93
- },
94
- poolConnectionTimeoutMs: {
95
- env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
96
- description: 'Connection timeout in milliseconds (0 means no timeout)',
97
- ...numberConfigHelper(0),
98
- },
99
- };
100
-
101
- export const defaultValidatorHASignerConfig: ValidatorHASignerConfig = getDefaultConfig(
102
- validatorHASignerConfigMappings,
103
- );
104
-
105
- /**
106
- * Returns the validator HA signer configuration from environment variables.
107
- * Note: If an environment variable is not set, the default value is used.
108
- * @returns The validator HA signer configuration.
109
- */
110
- export function getConfigEnvVars(): ValidatorHASignerConfig {
111
- return getConfigFromMappings<ValidatorHASignerConfig>(validatorHASignerConfigMappings);
112
- }
113
-
114
- export const ValidatorHASignerConfigSchema = z.object({
115
- haSigningEnabled: z.boolean(),
116
- nodeId: z.string(),
117
- pollingIntervalMs: z.number().min(0),
118
- signingTimeoutMs: z.number().min(0),
119
- maxStuckDutiesAgeMs: z.number().min(0).optional(),
120
- databaseUrl: z.string().optional(),
121
- poolMaxCount: z.number().min(0).optional(),
122
- poolMinCount: z.number().min(0).optional(),
123
- poolIdleTimeoutMs: z.number().min(0).optional(),
124
- poolConnectionTimeoutMs: z.number().min(0).optional(),
125
- }) satisfies ZodFor<ValidatorHASignerConfig>;