@aztec/validator-ha-signer 0.0.1-commit.fffb133c → 0.0.2-commit.217f559981

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.
@@ -7,6 +7,8 @@
7
7
  import { type Logger, createLogger } from '@aztec/foundation/log';
8
8
  import { RunningPromise } from '@aztec/foundation/promise';
9
9
  import { sleep } from '@aztec/foundation/sleep';
10
+ import type { DateProvider } from '@aztec/foundation/timer';
11
+ import type { ValidatorHASignerConfig } from '@aztec/stdlib/ha-signing';
10
12
 
11
13
  import {
12
14
  type CheckAndRecordParams,
@@ -16,7 +18,13 @@ import {
16
18
  getBlockIndexFromDutyIdentifier,
17
19
  } from './db/types.js';
18
20
  import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
19
- import type { SlashingProtectionDatabase, ValidatorHASignerConfig } from './types.js';
21
+ import type { HASignerMetrics } from './metrics.js';
22
+ import type { SlashingProtectionDatabase } from './types.js';
23
+
24
+ export interface SlashingProtectionServiceDeps {
25
+ metrics: HASignerMetrics;
26
+ dateProvider: DateProvider;
27
+ }
20
28
 
21
29
  /**
22
30
  * Slashing Protection Service
@@ -39,11 +47,16 @@ export class SlashingProtectionService {
39
47
  private readonly signingTimeoutMs: number;
40
48
  private readonly maxStuckDutiesAgeMs: number;
41
49
 
50
+ private readonly metrics: HASignerMetrics;
51
+ private readonly dateProvider: DateProvider;
52
+
42
53
  private cleanupRunningPromise: RunningPromise;
54
+ private lastOldDutiesCleanupAtMs?: number;
43
55
 
44
56
  constructor(
45
57
  private readonly db: SlashingProtectionDatabase,
46
58
  private readonly config: ValidatorHASignerConfig,
59
+ deps: SlashingProtectionServiceDeps,
47
60
  ) {
48
61
  this.log = createLogger('slashing-protection');
49
62
  this.pollingIntervalMs = config.pollingIntervalMs;
@@ -51,11 +64,9 @@ export class SlashingProtectionService {
51
64
  // Default to 144s (2x 72s Aztec slot duration) if not explicitly configured
52
65
  this.maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? 144_000;
53
66
 
54
- this.cleanupRunningPromise = new RunningPromise(
55
- this.cleanupStuckDuties.bind(this),
56
- this.log,
57
- this.maxStuckDutiesAgeMs,
58
- );
67
+ this.cleanupRunningPromise = new RunningPromise(this.cleanup.bind(this), this.log, this.maxStuckDutiesAgeMs);
68
+ this.metrics = deps.metrics;
69
+ this.dateProvider = deps.dateProvider;
59
70
  }
60
71
 
61
72
  /**
@@ -67,7 +78,6 @@ export class SlashingProtectionService {
67
78
  * 2. If insert succeeds, we acquired the lock - return the lockToken
68
79
  * 3. If a record exists, handle based on status:
69
80
  * - SIGNED: Throw appropriate error (already signed or slashing protection)
70
- * - FAILED: Delete the failed record
71
81
  * - SIGNING: Wait and poll until status changes, then handle result
72
82
  *
73
83
  * @returns The lockToken that must be used for recordSuccess/deleteDuty
@@ -76,7 +86,7 @@ export class SlashingProtectionService {
76
86
  */
77
87
  async checkAndRecord(params: CheckAndRecordParams): Promise<string> {
78
88
  const { validatorAddress, slot, dutyType, messageHash, nodeId } = params;
79
- const startTime = Date.now();
89
+ const startTime = this.dateProvider.now();
80
90
 
81
91
  this.log.debug(`Checking duty: ${dutyType} for slot ${slot}`, {
82
92
  validatorAddress: validatorAddress.toString(),
@@ -93,6 +103,7 @@ export class SlashingProtectionService {
93
103
  validatorAddress: validatorAddress.toString(),
94
104
  nodeId,
95
105
  });
106
+ this.metrics.recordLockAcquire(true);
96
107
  return record.lockToken;
97
108
  }
98
109
 
@@ -107,6 +118,7 @@ export class SlashingProtectionService {
107
118
  existingNodeId: record.nodeId,
108
119
  attemptingNodeId: nodeId,
109
120
  });
121
+ this.metrics.recordSlashingProtection(dutyType);
110
122
  throw new SlashingProtectionError(
111
123
  slot,
112
124
  dutyType,
@@ -116,15 +128,17 @@ export class SlashingProtectionService {
116
128
  record.nodeId,
117
129
  );
118
130
  }
131
+ this.metrics.recordDutyAlreadySigned(dutyType);
119
132
  throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, record.nodeId);
120
133
  } else if (record.status === DutyStatus.SIGNING) {
121
134
  // Another node is currently signing - check for timeout
122
- if (Date.now() - startTime > this.signingTimeoutMs) {
135
+ if (this.dateProvider.now() - startTime > this.signingTimeoutMs) {
123
136
  this.log.warn(`Timeout waiting for signing to complete for duty ${dutyType} at slot ${slot}`, {
124
137
  validatorAddress: validatorAddress.toString(),
125
138
  timeoutMs: this.signingTimeoutMs,
126
139
  signingNodeId: record.nodeId,
127
140
  });
141
+ this.metrics.recordDutyAlreadySigned(dutyType);
128
142
  throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, 'unknown (timeout)');
129
143
  }
130
144
 
@@ -149,10 +163,11 @@ export class SlashingProtectionService {
149
163
  * @returns true if the update succeeded, false if token didn't match
150
164
  */
151
165
  async recordSuccess(params: RecordSuccessParams): Promise<boolean> {
152
- const { validatorAddress, slot, dutyType, signature, nodeId, lockToken } = params;
166
+ const { rollupAddress, validatorAddress, slot, dutyType, signature, nodeId, lockToken } = params;
153
167
  const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
154
168
 
155
169
  const success = await this.db.updateDutySigned(
170
+ rollupAddress,
156
171
  validatorAddress,
157
172
  slot,
158
173
  dutyType,
@@ -184,10 +199,17 @@ export class SlashingProtectionService {
184
199
  * @returns true if the delete succeeded, false if token didn't match
185
200
  */
186
201
  async deleteDuty(params: DeleteDutyParams): Promise<boolean> {
187
- const { validatorAddress, slot, dutyType, lockToken } = params;
202
+ const { rollupAddress, validatorAddress, slot, dutyType, lockToken } = params;
188
203
  const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
189
204
 
190
- const success = await this.db.deleteDuty(validatorAddress, slot, dutyType, lockToken, blockIndexWithinCheckpoint);
205
+ const success = await this.db.deleteDuty(
206
+ rollupAddress,
207
+ validatorAddress,
208
+ slot,
209
+ dutyType,
210
+ lockToken,
211
+ blockIndexWithinCheckpoint,
212
+ );
191
213
 
192
214
  if (success) {
193
215
  this.log.info(`Deleted duty ${dutyType} at slot ${slot} to allow retry`, {
@@ -213,7 +235,20 @@ export class SlashingProtectionService {
213
235
  * Start running tasks.
214
236
  * Cleanup runs immediately on start to recover from any previous crashes.
215
237
  */
216
- start() {
238
+ /**
239
+ * Start the background cleanup task.
240
+ * Also performs one-time cleanup of duties with outdated rollup addresses.
241
+ */
242
+ async start() {
243
+ // One-time cleanup at startup: remove duties from previous rollup versions
244
+ const numOutdatedRollupDuties = await this.db.cleanupOutdatedRollupDuties(this.config.l1Contracts.rollupAddress);
245
+ if (numOutdatedRollupDuties > 0) {
246
+ this.log.info(`Cleaned up ${numOutdatedRollupDuties} duties with outdated rollup address at startup`, {
247
+ currentRollupAddress: this.config.l1Contracts.rollupAddress.toString(),
248
+ });
249
+ this.metrics.recordCleanup('outdated_rollup', numOutdatedRollupDuties);
250
+ }
251
+
217
252
  this.cleanupRunningPromise.start();
218
253
  this.log.info('Slashing protection service started', { nodeId: this.config.nodeId });
219
254
  }
@@ -236,15 +271,38 @@ export class SlashingProtectionService {
236
271
  }
237
272
 
238
273
  /**
239
- * Cleanup own stuck duties
274
+ * Periodic cleanup of stuck duties and optionally old signed duties.
275
+ * Runs in the background via RunningPromise.
240
276
  */
241
- private async cleanupStuckDuties() {
242
- const numDuties = await this.db.cleanupOwnStuckDuties(this.config.nodeId, this.maxStuckDutiesAgeMs);
243
- if (numDuties > 0) {
244
- this.log.info(`Cleaned up ${numDuties} stuck duties`, {
277
+ private async cleanup() {
278
+ // 1. Clean up stuck duties (our own node's duties that got stuck in 'signing' status)
279
+ const numStuckDuties = await this.db.cleanupOwnStuckDuties(this.config.nodeId, this.maxStuckDutiesAgeMs);
280
+ if (numStuckDuties > 0) {
281
+ this.log.verbose(`Cleaned up ${numStuckDuties} stuck duties`, {
245
282
  nodeId: this.config.nodeId,
246
283
  maxStuckDutiesAgeMs: this.maxStuckDutiesAgeMs,
247
284
  });
285
+ this.metrics.recordCleanup('stuck', numStuckDuties);
286
+ }
287
+
288
+ // 2. Clean up old signed duties if configured
289
+ // we shouldn't run this as often as stuck duty cleanup.
290
+ if (this.config.cleanupOldDutiesAfterHours !== undefined) {
291
+ const maxAgeMs = this.config.cleanupOldDutiesAfterHours * 60 * 60 * 1000;
292
+ const nowMs = this.dateProvider.now();
293
+ const shouldRun =
294
+ this.lastOldDutiesCleanupAtMs === undefined || nowMs - this.lastOldDutiesCleanupAtMs >= maxAgeMs;
295
+ if (shouldRun) {
296
+ const numOldDuties = await this.db.cleanupOldDuties(maxAgeMs);
297
+ this.lastOldDutiesCleanupAtMs = nowMs;
298
+ if (numOldDuties > 0) {
299
+ this.log.verbose(`Cleaned up ${numOldDuties} old signed duties`, {
300
+ cleanupOldDutiesAfterHours: this.config.cleanupOldDutiesAfterHours,
301
+ maxAgeMs,
302
+ });
303
+ this.metrics.recordCleanup('old', numOldDuties);
304
+ }
305
+ }
248
306
  }
249
307
  }
250
308
  }
package/src/types.ts CHANGED
@@ -1,23 +1,27 @@
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
+ 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';
8
13
 
9
14
  import type { Pool } from 'pg';
10
15
 
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,
16
+ import type {
17
+ BlockProposalDutyIdentifier,
18
+ CheckAndRecordParams,
19
+ DeleteDutyParams,
20
+ DutyIdentifier,
21
+ DutyRow,
22
+ OtherDutyIdentifier,
23
+ RecordSuccessParams,
24
+ ValidatorDutyRecord,
21
25
  } from './db/types.js';
22
26
 
23
27
  export type {
@@ -25,12 +29,17 @@ export type {
25
29
  CheckAndRecordParams,
26
30
  DeleteDutyParams,
27
31
  DutyIdentifier,
32
+ DutyRow,
33
+ HAProtectedSigningContext,
28
34
  OtherDutyIdentifier,
29
35
  RecordSuccessParams,
36
+ SigningContext,
30
37
  ValidatorDutyRecord,
31
38
  ValidatorHASignerConfig,
32
39
  };
33
40
  export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
41
+ export { isHAProtectedContext };
42
+ export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
34
43
 
35
44
  /**
36
45
  * Result of tryInsertOrGetExisting operation
@@ -51,100 +60,16 @@ export interface CreateHASignerDeps {
51
60
  * If provided, databaseUrl and poolConfig are ignored
52
61
  */
53
62
  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
63
  /**
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.
64
+ * Optional telemetry client for metrics
66
65
  */
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);
66
+ telemetryClient?: TelemetryClient;
67
+ /**
68
+ * Optional date provider for timestamps
69
+ */
70
+ dateProvider?: DateProvider;
136
71
  }
137
72
 
138
- /**
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)
145
- */
146
- export type SigningContext = HAProtectedSigningContext | NoHAProtectionSigningContext;
147
-
148
73
  /**
149
74
  * Database interface for slashing protection operations
150
75
  * This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
@@ -170,6 +95,7 @@ export interface SlashingProtectionDatabase {
170
95
  * @returns true if the update succeeded, false if token didn't match or duty not found
171
96
  */
172
97
  updateDutySigned(
98
+ rollupAddress: EthAddress,
173
99
  validatorAddress: EthAddress,
174
100
  slot: SlotNumber,
175
101
  dutyType: DutyType,
@@ -186,6 +112,7 @@ export interface SlashingProtectionDatabase {
186
112
  * @returns true if the delete succeeded, false if token didn't match or duty not found
187
113
  */
188
114
  deleteDuty(
115
+ rollupAddress: EthAddress,
189
116
  validatorAddress: EthAddress,
190
117
  slot: SlotNumber,
191
118
  dutyType: DutyType,
@@ -199,6 +126,21 @@ export interface SlashingProtectionDatabase {
199
126
  */
200
127
  cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number>;
201
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
+
202
144
  /**
203
145
  * Close the database connection.
204
146
  * Should be called during graceful shutdown.
@@ -6,18 +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
-
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
+ DutyType,
17
15
  type HAProtectedSigningContext,
18
- type SlashingProtectionDatabase,
16
+ type ValidatorHASignerConfig,
19
17
  getBlockNumberFromSigningContext,
20
- } from './types.js';
18
+ } from '@aztec/stdlib/ha-signing';
19
+
20
+ import type { DutyIdentifier } from './db/types.js';
21
+ import type { HASignerMetrics } from './metrics.js';
22
+ import { SlashingProtectionService } from './slashing_protection_service.js';
23
+ import type { SlashingProtectionDatabase } from './types.js';
24
+
25
+ export interface ValidatorHASignerDeps {
26
+ metrics: HASignerMetrics;
27
+ dateProvider: DateProvider;
28
+ }
21
29
 
22
30
  /**
23
31
  * Validator High Availability Signer
@@ -41,13 +49,21 @@ import {
41
49
  export class ValidatorHASigner {
42
50
  private readonly log: Logger;
43
51
  private readonly slashingProtection: SlashingProtectionService;
52
+ private readonly rollupAddress: EthAddress;
53
+
54
+ private readonly dateProvider: DateProvider;
55
+ private readonly metrics: HASignerMetrics;
44
56
 
45
57
  constructor(
46
58
  db: SlashingProtectionDatabase,
47
59
  private readonly config: ValidatorHASignerConfig,
60
+ deps: ValidatorHASignerDeps,
48
61
  ) {
49
62
  this.log = createLogger('validator-ha-signer');
50
63
 
64
+ this.metrics = deps.metrics;
65
+ this.dateProvider = deps.dateProvider;
66
+
51
67
  if (!config.haSigningEnabled) {
52
68
  // this shouldn't happen, the validator should use different signer for non-HA setups
53
69
  throw new Error('Validator HA Signer is not enabled in config');
@@ -56,9 +72,14 @@ export class ValidatorHASigner {
56
72
  if (!config.nodeId || config.nodeId === '') {
57
73
  throw new Error('NODE_ID is required for high-availability setups');
58
74
  }
59
- 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
+ });
60
80
  this.log.info('Validator HA Signer initialized with slashing protection', {
61
81
  nodeId: config.nodeId,
82
+ rollupAddress: this.rollupAddress.toString(),
62
83
  });
63
84
  }
64
85
 
@@ -85,9 +106,13 @@ export class ValidatorHASigner {
85
106
  context: HAProtectedSigningContext,
86
107
  signFn: (messageHash: Buffer32) => Promise<Signature>,
87
108
  ): Promise<Signature> {
109
+ const startTime = this.dateProvider.now();
110
+ const dutyType = context.dutyType;
111
+
88
112
  let dutyIdentifier: DutyIdentifier;
89
113
  if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
90
114
  dutyIdentifier = {
115
+ rollupAddress: this.rollupAddress,
91
116
  validatorAddress,
92
117
  slot: context.slot,
93
118
  blockIndexWithinCheckpoint: context.blockIndexWithinCheckpoint,
@@ -95,6 +120,7 @@ export class ValidatorHASigner {
95
120
  };
96
121
  } else {
97
122
  dutyIdentifier = {
123
+ rollupAddress: this.rollupAddress,
98
124
  validatorAddress,
99
125
  slot: context.slot,
100
126
  dutyType: context.dutyType,
@@ -102,6 +128,7 @@ export class ValidatorHASigner {
102
128
  }
103
129
 
104
130
  // Acquire lock and get the token for ownership verification
131
+ // DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
105
132
  const blockNumber = getBlockNumberFromSigningContext(context);
106
133
  const lockToken = await this.slashingProtection.checkAndRecord({
107
134
  ...dutyIdentifier,
@@ -117,6 +144,7 @@ export class ValidatorHASigner {
117
144
  } catch (error: any) {
118
145
  // Delete duty to allow retry (only succeeds if we own the lock)
119
146
  await this.slashingProtection.deleteDuty({ ...dutyIdentifier, lockToken });
147
+ this.metrics.recordSigningError(dutyType);
120
148
  throw error;
121
149
  }
122
150
 
@@ -128,6 +156,9 @@ export class ValidatorHASigner {
128
156
  lockToken,
129
157
  });
130
158
 
159
+ const duration = this.dateProvider.now() - startTime;
160
+ this.metrics.recordSigningSuccess(dutyType, duration);
161
+
131
162
  return signature;
132
163
  }
133
164
 
@@ -142,8 +173,8 @@ export class ValidatorHASigner {
142
173
  * Start the HA signer background tasks (cleanup of stuck duties).
143
174
  * Should be called after construction and before signing operations.
144
175
  */
145
- start() {
146
- this.slashingProtection.start();
176
+ async start() {
177
+ await this.slashingProtection.start();
147
178
  }
148
179
 
149
180
  /**
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"}