@aztec/validator-ha-signer 4.0.0-nightly.20260115 → 4.0.0-nightly.20260117

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 (42) hide show
  1. package/README.md +42 -37
  2. package/dest/config.d.ts +49 -17
  3. package/dest/config.d.ts.map +1 -1
  4. package/dest/config.js +28 -19
  5. package/dest/db/postgres.d.ts +10 -3
  6. package/dest/db/postgres.d.ts.map +1 -1
  7. package/dest/db/postgres.js +50 -19
  8. package/dest/db/schema.d.ts +11 -7
  9. package/dest/db/schema.d.ts.map +1 -1
  10. package/dest/db/schema.js +19 -7
  11. package/dest/db/types.d.ts +75 -23
  12. package/dest/db/types.d.ts.map +1 -1
  13. package/dest/db/types.js +34 -0
  14. package/dest/errors.d.ts +9 -5
  15. package/dest/errors.d.ts.map +1 -1
  16. package/dest/errors.js +7 -4
  17. package/dest/factory.d.ts +6 -14
  18. package/dest/factory.d.ts.map +1 -1
  19. package/dest/factory.js +6 -11
  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 +9 -3
  24. package/dest/slashing_protection_service.d.ts.map +1 -1
  25. package/dest/slashing_protection_service.js +21 -9
  26. package/dest/types.d.ts +78 -14
  27. package/dest/types.d.ts.map +1 -1
  28. package/dest/types.js +21 -1
  29. package/dest/validator_ha_signer.d.ts +7 -11
  30. package/dest/validator_ha_signer.d.ts.map +1 -1
  31. package/dest/validator_ha_signer.js +25 -29
  32. package/package.json +6 -5
  33. package/src/config.ts +59 -50
  34. package/src/db/postgres.ts +57 -17
  35. package/src/db/schema.ts +19 -7
  36. package/src/db/types.ts +105 -21
  37. package/src/errors.ts +7 -2
  38. package/src/factory.ts +8 -13
  39. package/src/migrations.ts +17 -1
  40. package/src/slashing_protection_service.ts +46 -12
  41. package/src/types.ts +116 -19
  42. package/src/validator_ha_signer.ts +32 -39
@@ -6,7 +6,7 @@
6
6
  */ import { createLogger } from '@aztec/foundation/log';
7
7
  import { RunningPromise } from '@aztec/foundation/promise';
8
8
  import { sleep } from '@aztec/foundation/sleep';
9
- import { DutyStatus } from './db/types.js';
9
+ import { DutyStatus, getBlockIndexFromDutyIdentifier } from './db/types.js';
10
10
  import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
11
11
  /**
12
12
  * Slashing Protection Service
@@ -28,6 +28,7 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
28
28
  log;
29
29
  pollingIntervalMs;
30
30
  signingTimeoutMs;
31
+ maxStuckDutiesAgeMs;
31
32
  cleanupRunningPromise;
32
33
  constructor(db, config){
33
34
  this.db = db;
@@ -35,7 +36,9 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
35
36
  this.log = createLogger('slashing-protection');
36
37
  this.pollingIntervalMs = config.pollingIntervalMs;
37
38
  this.signingTimeoutMs = config.signingTimeoutMs;
38
- this.cleanupRunningPromise = new RunningPromise(this.cleanupStuckDuties.bind(this), this.log, this.config.maxStuckDutiesAgeMs);
39
+ // Default to 144s (2x 72s Aztec slot duration) if not explicitly configured
40
+ this.maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? 144_000;
41
+ this.cleanupRunningPromise = new RunningPromise(this.cleanupStuckDuties.bind(this), this.log, this.maxStuckDutiesAgeMs);
39
42
  }
40
43
  /**
41
44
  * Check if a duty can be performed and acquire the lock if so.
@@ -81,9 +84,9 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
81
84
  existingNodeId: record.nodeId,
82
85
  attemptingNodeId: nodeId
83
86
  });
84
- throw new SlashingProtectionError(slot, dutyType, record.messageHash, messageHash);
87
+ throw new SlashingProtectionError(slot, dutyType, record.blockIndexWithinCheckpoint, record.messageHash, messageHash, record.nodeId);
85
88
  }
86
- throw new DutyAlreadySignedError(slot, dutyType, record.nodeId);
89
+ throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, record.nodeId);
87
90
  } else if (record.status === DutyStatus.SIGNING) {
88
91
  // Another node is currently signing - check for timeout
89
92
  if (Date.now() - startTime > this.signingTimeoutMs) {
@@ -92,7 +95,7 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
92
95
  timeoutMs: this.signingTimeoutMs,
93
96
  signingNodeId: record.nodeId
94
97
  });
95
- throw new DutyAlreadySignedError(slot, dutyType, 'unknown (timeout)');
98
+ throw new DutyAlreadySignedError(slot, dutyType, record.blockIndexWithinCheckpoint, 'unknown (timeout)');
96
99
  }
97
100
  // Wait and poll
98
101
  this.log.debug(`Waiting for signing to complete for duty ${dutyType} at slot ${slot}`, {
@@ -114,7 +117,8 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
114
117
  * @returns true if the update succeeded, false if token didn't match
115
118
  */ async recordSuccess(params) {
116
119
  const { validatorAddress, slot, dutyType, signature, nodeId, lockToken } = params;
117
- const success = await this.db.updateDutySigned(validatorAddress, slot, dutyType, signature.toString(), lockToken);
120
+ const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
121
+ const success = await this.db.updateDutySigned(validatorAddress, slot, dutyType, signature.toString(), lockToken, blockIndexWithinCheckpoint);
118
122
  if (success) {
119
123
  this.log.info(`Recorded successful signing for duty ${dutyType} at slot ${slot}`, {
120
124
  validatorAddress: validatorAddress.toString(),
@@ -136,7 +140,8 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
136
140
  * @returns true if the delete succeeded, false if token didn't match
137
141
  */ async deleteDuty(params) {
138
142
  const { validatorAddress, slot, dutyType, lockToken } = params;
139
- const success = await this.db.deleteDuty(validatorAddress, slot, dutyType, lockToken);
143
+ const blockIndexWithinCheckpoint = getBlockIndexFromDutyIdentifier(params);
144
+ const success = await this.db.deleteDuty(validatorAddress, slot, dutyType, lockToken, blockIndexWithinCheckpoint);
140
145
  if (success) {
141
146
  this.log.info(`Deleted duty ${dutyType} at slot ${slot} to allow retry`, {
142
147
  validatorAddress: validatorAddress.toString()
@@ -171,13 +176,20 @@ import { DutyAlreadySignedError, SlashingProtectionError } from './errors.js';
171
176
  });
172
177
  }
173
178
  /**
179
+ * Close the database connection.
180
+ * Should be called after stop() during graceful shutdown.
181
+ */ async close() {
182
+ await this.db.close();
183
+ this.log.info('Slashing protection database connection closed');
184
+ }
185
+ /**
174
186
  * Cleanup own stuck duties
175
187
  */ async cleanupStuckDuties() {
176
- const numDuties = await this.db.cleanupOwnStuckDuties(this.config.nodeId, this.config.maxStuckDutiesAgeMs);
188
+ const numDuties = await this.db.cleanupOwnStuckDuties(this.config.nodeId, this.maxStuckDutiesAgeMs);
177
189
  if (numDuties > 0) {
178
190
  this.log.info(`Cleaned up ${numDuties} stuck duties`, {
179
191
  nodeId: this.config.nodeId,
180
- maxStuckDutiesAgeMs: this.config.maxStuckDutiesAgeMs
192
+ maxStuckDutiesAgeMs: this.maxStuckDutiesAgeMs
181
193
  });
182
194
  }
183
195
  }
package/dest/types.d.ts CHANGED
@@ -1,9 +1,10 @@
1
+ import { BlockNumber, type CheckpointNumber, type SlotNumber } from '@aztec/foundation/branded-types';
1
2
  import type { EthAddress } from '@aztec/foundation/eth-address';
2
3
  import type { Pool } from 'pg';
3
- import type { CreateHASignerConfig, SlashingProtectionConfig } from './config.js';
4
- import type { CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyType, RecordSuccessParams, ValidatorDutyRecord } from './db/types.js';
5
- export type { CheckAndRecordParams, CreateHASignerConfig, DeleteDutyParams, DutyIdentifier, RecordSuccessParams, SlashingProtectionConfig, ValidatorDutyRecord, };
6
- export { DutyStatus, DutyType } from './db/types.js';
4
+ import type { ValidatorHASignerConfig } from './config.js';
5
+ import { type BlockProposalDutyIdentifier, type CheckAndRecordParams, type DeleteDutyParams, type DutyIdentifier, DutyType, type OtherDutyIdentifier, type RecordSuccessParams, type ValidatorDutyRecord } from './db/types.js';
6
+ export type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, OtherDutyIdentifier, RecordSuccessParams, ValidatorDutyRecord, ValidatorHASignerConfig, };
7
+ export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
7
8
  /**
8
9
  * Result of tryInsertOrGetExisting operation
9
10
  */
@@ -24,16 +25,74 @@ export interface CreateHASignerDeps {
24
25
  pool?: Pool;
25
26
  }
26
27
  /**
27
- * Context required for slashing protection during signing operations
28
+ * Base context for signing operations
28
29
  */
29
- export interface SigningContext {
30
+ interface BaseSigningContext {
30
31
  /** Slot number for this duty */
31
- slot: bigint;
32
- /** Block number for this duty */
33
- blockNumber: bigint;
34
- /** Type of duty being performed */
35
- dutyType: DutyType;
32
+ slot: SlotNumber;
33
+ /**
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.
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: number;
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;
55
+ }
56
+ /**
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;
36
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)
94
+ */
95
+ export type SigningContext = HAProtectedSigningContext | NoHAProtectionSigningContext;
37
96
  /**
38
97
  * Database interface for slashing protection operations
39
98
  * This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
@@ -57,7 +116,7 @@ export interface SlashingProtectionDatabase {
57
116
  *
58
117
  * @returns true if the update succeeded, false if token didn't match or duty not found
59
118
  */
60
- updateDutySigned(validatorAddress: EthAddress, slot: bigint, dutyType: DutyType, signature: string, lockToken: string): Promise<boolean>;
119
+ updateDutySigned(validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, signature: string, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
61
120
  /**
62
121
  * Delete a duty record.
63
122
  * Only succeeds if the lockToken matches (caller must be the one who created the duty).
@@ -65,11 +124,16 @@ export interface SlashingProtectionDatabase {
65
124
  *
66
125
  * @returns true if the delete succeeded, false if token didn't match or duty not found
67
126
  */
68
- deleteDuty(validatorAddress: EthAddress, slot: bigint, dutyType: DutyType, lockToken: string): Promise<boolean>;
127
+ deleteDuty(validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
69
128
  /**
70
129
  * Cleanup own stuck duties
71
130
  * @returns the number of duties cleaned up
72
131
  */
73
132
  cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number>;
133
+ /**
134
+ * Close the database connection.
135
+ * Should be called during graceful shutdown.
136
+ */
137
+ close(): Promise<void>;
74
138
  }
75
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEtBQUssRUFBRSxVQUFVLEVBQUUsTUFBTSwrQkFBK0IsQ0FBQztBQUVoRSxPQUFPLEtBQUssRUFBRSxJQUFJLEVBQUUsTUFBTSxJQUFJLENBQUM7QUFFL0IsT0FBTyxLQUFLLEVBQUUsb0JBQW9CLEVBQUUsd0JBQXdCLEVBQUUsTUFBTSxhQUFhLENBQUM7QUFDbEYsT0FBTyxLQUFLLEVBQ1Ysb0JBQW9CLEVBQ3BCLGdCQUFnQixFQUNoQixjQUFjLEVBQ2QsUUFBUSxFQUNSLG1CQUFtQixFQUNuQixtQkFBbUIsRUFDcEIsTUFBTSxlQUFlLENBQUM7QUFFdkIsWUFBWSxFQUNWLG9CQUFvQixFQUNwQixvQkFBb0IsRUFDcEIsZ0JBQWdCLEVBQ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'./db/types.js';
1
+ import { BlockNumber } from '@aztec/foundation/branded-types';
2
+ import { DutyType } from './db/types.js';
3
+ export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
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,8 +8,8 @@
8
8
  import type { Buffer32 } from '@aztec/foundation/buffer';
9
9
  import type { EthAddress } from '@aztec/foundation/eth-address';
10
10
  import type { Signature } from '@aztec/foundation/eth-signature';
11
- import type { CreateHASignerConfig } from './config.js';
12
- import type { SigningContext, SlashingProtectionDatabase } from './types.js';
11
+ import type { ValidatorHASignerConfig } from './config.js';
12
+ import { type HAProtectedSigningContext, type SlashingProtectionDatabase } from './types.js';
13
13
  /**
14
14
  * Validator High Availability Signer
15
15
  *
@@ -33,7 +33,7 @@ export declare class ValidatorHASigner {
33
33
  private readonly config;
34
34
  private readonly log;
35
35
  private readonly slashingProtection;
36
- constructor(db: SlashingProtectionDatabase, config: CreateHASignerConfig);
36
+ constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig);
37
37
  /**
38
38
  * Sign a message with slashing protection.
39
39
  *
@@ -44,18 +44,14 @@ export declare class ValidatorHASigner {
44
44
  *
45
45
  * @param validatorAddress - The validator's Ethereum address
46
46
  * @param messageHash - The hash to be signed
47
- * @param context - The signing context (slot, block number, duty type)
47
+ * @param context - The signing context (HA-protected duty types only)
48
48
  * @param signFn - Function that performs the actual signing
49
49
  * @returns The signature
50
50
  *
51
51
  * @throws DutyAlreadySignedError if the duty was already signed (expected in HA)
52
52
  * @throws SlashingProtectionError if attempting to sign different data for same slot (expected in HA)
53
53
  */
54
- signWithProtection(validatorAddress: EthAddress, messageHash: Buffer32, context: SigningContext, signFn: (messageHash: Buffer32) => Promise<Signature>): Promise<Signature>;
55
- /**
56
- * Check if slashing protection is enabled
57
- */
58
- get isEnabled(): boolean;
54
+ signWithProtection(validatorAddress: EthAddress, messageHash: Buffer32, context: HAProtectedSigningContext, signFn: (messageHash: Buffer32) => Promise<Signature>): Promise<Signature>;
59
55
  /**
60
56
  * Get the node ID for this signer
61
57
  */
@@ -66,9 +62,9 @@ export declare class ValidatorHASigner {
66
62
  */
67
63
  start(): void;
68
64
  /**
69
- * Stop the HA signer background tasks.
65
+ * Stop the HA signer background tasks and close database connection.
70
66
  * Should be called during graceful shutdown.
71
67
  */
72
68
  stop(): Promise<void>;
73
69
  }
74
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdG9yX2hhX3NpZ25lci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3ZhbGlkYXRvcl9oYV9zaWduZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDekQsT0FBTyxLQUFLLEVBQUUsVUFBVSxFQUFFLE1BQU0sK0JBQStCLENBQUM7QUFDaEUsT0FBTyxLQUFL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SSxNQUFNLElBQUksTUFBTSxDQUVuQjtJQUVEOzs7T0FHRztJQUNILEtBQUssU0FFSjtJQUVEOzs7T0FHRztJQUNHLElBQUksa0JBR1Q7Q0FDRiJ9
@@ -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,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAGjE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAExD,OAAO,KAAK,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,YAAY,CAAC;AAE7E;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,iBAAiB;IAM1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAwC;IAE3E,YACE,EAAE,EAAE,0BAA0B,EACb,MAAM,EAAE,oBAAoB,EAgB9C;IAED;;;;;;;;;;;;;;;;OAgBG;IACG,kBAAkB,CACtB,gBAAgB,EAAE,UAAU,EAC5B,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,cAAc,EACvB,MAAM,EAAE,CAAC,WAAW,EAAE,QAAQ,KAAK,OAAO,CAAC,SAAS,CAAC,GACpD,OAAO,CAAC,SAAS,CAAC,CAmDpB;IAED;;OAEG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH,KAAK,SAEJ;IAED;;;OAGG;IACG,IAAI,kBAET;CACF"}
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,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,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;IAM1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA4B;IAE/D,YACE,EAAE,EAAE,0BAA0B,EACb,MAAM,EAAE,uBAAuB,EAgBjD;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,CA6CpB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACH,KAAK,SAEJ;IAED;;;OAGG;IACG,IAAI,kBAGT;CACF"}
@@ -5,7 +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 } from './db/types.js';
8
9
  import { SlashingProtectionService } from './slashing_protection_service.js';
10
+ import { getBlockNumberFromSigningContext } from './types.js';
9
11
  /**
10
12
  * Validator High Availability Signer
11
13
  *
@@ -31,7 +33,7 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
31
33
  constructor(db, config){
32
34
  this.config = config;
33
35
  this.log = createLogger('validator-ha-signer');
34
- if (!config.enabled) {
36
+ if (!config.haSigningEnabled) {
35
37
  // this shouldn't happen, the validator should use different signer for non-HA setups
36
38
  throw new Error('Validator HA Signer is not enabled in config');
37
39
  }
@@ -53,31 +55,33 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
53
55
  *
54
56
  * @param validatorAddress - The validator's Ethereum address
55
57
  * @param messageHash - The hash to be signed
56
- * @param context - The signing context (slot, block number, duty type)
58
+ * @param context - The signing context (HA-protected duty types only)
57
59
  * @param signFn - Function that performs the actual signing
58
60
  * @returns The signature
59
61
  *
60
62
  * @throws DutyAlreadySignedError if the duty was already signed (expected in HA)
61
63
  * @throws SlashingProtectionError if attempting to sign different data for same slot (expected in HA)
62
64
  */ async signWithProtection(validatorAddress, messageHash, context, signFn) {
63
- // If slashing protection is disabled, just sign directly
64
- if (!this.slashingProtection) {
65
- this.log.info('Signing without slashing protection enabled', {
66
- validatorAddress: validatorAddress.toString(),
67
- nodeId: this.config.nodeId,
68
- dutyType: context.dutyType,
65
+ let dutyIdentifier;
66
+ if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
67
+ dutyIdentifier = {
68
+ validatorAddress,
69
69
  slot: context.slot,
70
- blockNumber: context.blockNumber
71
- });
72
- return await signFn(messageHash);
70
+ blockIndexWithinCheckpoint: context.blockIndexWithinCheckpoint,
71
+ dutyType: context.dutyType
72
+ };
73
+ } else {
74
+ dutyIdentifier = {
75
+ validatorAddress,
76
+ slot: context.slot,
77
+ dutyType: context.dutyType
78
+ };
73
79
  }
74
- const { slot, blockNumber, dutyType } = context;
75
80
  // Acquire lock and get the token for ownership verification
81
+ const blockNumber = getBlockNumberFromSigningContext(context);
76
82
  const lockToken = await this.slashingProtection.checkAndRecord({
77
- validatorAddress,
78
- slot,
83
+ ...dutyIdentifier,
79
84
  blockNumber,
80
- dutyType,
81
85
  messageHash: messageHash.toString(),
82
86
  nodeId: this.config.nodeId
83
87
  });
@@ -88,18 +92,14 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
88
92
  } catch (error) {
89
93
  // Delete duty to allow retry (only succeeds if we own the lock)
90
94
  await this.slashingProtection.deleteDuty({
91
- validatorAddress,
92
- slot,
93
- dutyType,
95
+ ...dutyIdentifier,
94
96
  lockToken
95
97
  });
96
98
  throw error;
97
99
  }
98
100
  // Record success (only succeeds if we own the lock)
99
101
  await this.slashingProtection.recordSuccess({
100
- validatorAddress,
101
- slot,
102
- dutyType,
102
+ ...dutyIdentifier,
103
103
  signature,
104
104
  nodeId: this.config.nodeId,
105
105
  lockToken
@@ -107,11 +107,6 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
107
107
  return signature;
108
108
  }
109
109
  /**
110
- * Check if slashing protection is enabled
111
- */ get isEnabled() {
112
- return this.slashingProtection !== undefined;
113
- }
114
- /**
115
110
  * Get the node ID for this signer
116
111
  */ get nodeId() {
117
112
  return this.config.nodeId;
@@ -120,12 +115,13 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
120
115
  * Start the HA signer background tasks (cleanup of stuck duties).
121
116
  * Should be called after construction and before signing operations.
122
117
  */ start() {
123
- this.slashingProtection?.start();
118
+ this.slashingProtection.start();
124
119
  }
125
120
  /**
126
- * Stop the HA signer background tasks.
121
+ * Stop the HA signer background tasks and close database connection.
127
122
  * Should be called during graceful shutdown.
128
123
  */ async stop() {
129
- await this.slashingProtection?.stop();
124
+ await this.slashingProtection.stop();
125
+ await this.slashingProtection.close();
130
126
  }
131
127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aztec/validator-ha-signer",
3
- "version": "4.0.0-nightly.20260115",
3
+ "version": "4.0.0-nightly.20260117",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./config": "./dest/config.js",
@@ -10,7 +10,8 @@
10
10
  "./migrations": "./dest/migrations.js",
11
11
  "./slashing-protection-service": "./dest/slashing_protection_service.js",
12
12
  "./types": "./dest/types.js",
13
- "./validator-ha-signer": "./dest/validator_ha_signer.js"
13
+ "./validator-ha-signer": "./dest/validator_ha_signer.js",
14
+ "./test": "./dest/test/pglite_pool.js"
14
15
  },
15
16
  "typedocOptions": {
16
17
  "entryPoints": [
@@ -73,11 +74,11 @@
73
74
  ]
74
75
  },
75
76
  "dependencies": {
76
- "@aztec/foundation": "4.0.0-nightly.20260115",
77
- "@aztec/node-keystore": "4.0.0-nightly.20260115",
77
+ "@aztec/foundation": "4.0.0-nightly.20260117",
78
78
  "node-pg-migrate": "^8.0.4",
79
79
  "pg": "^8.11.3",
80
- "tslib": "^2.4.0"
80
+ "tslib": "^2.4.0",
81
+ "zod": "^3.23.8"
81
82
  },
82
83
  "devDependencies": {
83
84
  "@electric-sql/pglite": "^0.3.14",
package/src/config.ts CHANGED
@@ -4,66 +4,34 @@ import {
4
4
  getConfigFromMappings,
5
5
  getDefaultConfig,
6
6
  numberConfigHelper,
7
+ optionalNumberConfigHelper,
7
8
  } from '@aztec/foundation/config';
9
+ import type { ZodFor } from '@aztec/foundation/schemas';
10
+
11
+ import { z } from 'zod';
8
12
 
9
13
  /**
10
- * Configuration for the slashing protection service
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.
11
18
  */
12
- export interface SlashingProtectionConfig {
13
- /** Whether slashing protection is enabled */
14
- enabled: boolean;
19
+ export interface ValidatorHASignerConfig {
20
+ /** Whether HA signing / slashing protection is enabled */
21
+ haSigningEnabled: boolean;
15
22
  /** Unique identifier for this node */
16
23
  nodeId: string;
17
24
  /** How long to wait between polls when a duty is being signed (ms) */
18
25
  pollingIntervalMs: number;
19
26
  /** Maximum time to wait for a duty being signed to complete (ms) */
20
27
  signingTimeoutMs: number;
21
- /** Maximum age of a stuck duty in ms */
22
- maxStuckDutiesAgeMs: number;
23
- }
24
-
25
- export const slashingProtectionConfigMappings: ConfigMappingsType<SlashingProtectionConfig> = {
26
- enabled: {
27
- env: 'SLASHING_PROTECTION_ENABLED',
28
- description: 'Whether slashing protection is enabled',
29
- ...booleanConfigHelper(true),
30
- },
31
- nodeId: {
32
- env: 'SLASHING_PROTECTION_NODE_ID',
33
- description: 'The unique identifier for this node',
34
- defaultValue: '',
35
- },
36
- pollingIntervalMs: {
37
- env: 'SLASHING_PROTECTION_POLLING_INTERVAL_MS',
38
- description: 'The number of ms to wait between polls when a duty is being signed',
39
- ...numberConfigHelper(100),
40
- },
41
- signingTimeoutMs: {
42
- env: 'SLASHING_PROTECTION_SIGNING_TIMEOUT_MS',
43
- description: 'The maximum time to wait for a duty being signed to complete',
44
- ...numberConfigHelper(3_000),
45
- },
46
- maxStuckDutiesAgeMs: {
47
- env: 'SLASHING_PROTECTION_MAX_STUCK_DUTIES_AGE_MS',
48
- description: 'The maximum age of a stuck duty in ms',
49
- // hard-coding at current 2 slot duration. This should be set by the validator on init
50
- ...numberConfigHelper(72_000),
51
- },
52
- };
53
-
54
- export const defaultSlashingProtectionConfig: SlashingProtectionConfig = getDefaultConfig(
55
- slashingProtectionConfigMappings,
56
- );
57
-
58
- /**
59
- * Configuration for creating an HA signer with PostgreSQL backend
60
- */
61
- export interface CreateHASignerConfig extends SlashingProtectionConfig {
28
+ /** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
29
+ maxStuckDutiesAgeMs?: number;
62
30
  /**
63
31
  * PostgreSQL connection string
64
32
  * Format: postgresql://user:password@host:port/database
65
33
  */
66
- databaseUrl: string;
34
+ databaseUrl?: string;
67
35
  /**
68
36
  * PostgreSQL connection pool configuration
69
37
  */
@@ -77,8 +45,32 @@ export interface CreateHASignerConfig extends SlashingProtectionConfig {
77
45
  poolConnectionTimeoutMs?: number;
78
46
  }
79
47
 
80
- export const createHASignerConfigMappings: ConfigMappingsType<CreateHASignerConfig> = {
81
- ...slashingProtectionConfigMappings,
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
+ },
82
74
  databaseUrl: {
83
75
  env: 'VALIDATOR_HA_DATABASE_URL',
84
76
  description:
@@ -106,11 +98,28 @@ export const createHASignerConfigMappings: ConfigMappingsType<CreateHASignerConf
106
98
  },
107
99
  };
108
100
 
101
+ export const defaultValidatorHASignerConfig: ValidatorHASignerConfig = getDefaultConfig(
102
+ validatorHASignerConfigMappings,
103
+ );
104
+
109
105
  /**
110
106
  * Returns the validator HA signer configuration from environment variables.
111
107
  * Note: If an environment variable is not set, the default value is used.
112
108
  * @returns The validator HA signer configuration.
113
109
  */
114
- export function getConfigEnvVars(): CreateHASignerConfig {
115
- return getConfigFromMappings<CreateHASignerConfig>(createHASignerConfigMappings);
110
+ export function getConfigEnvVars(): ValidatorHASignerConfig {
111
+ return getConfigFromMappings<ValidatorHASignerConfig>(validatorHASignerConfigMappings);
116
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>;