@aztec/validator-ha-signer 0.0.1-commit.0208eb9

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 (58) hide show
  1. package/README.md +187 -0
  2. package/dest/config.d.ts +101 -0
  3. package/dest/config.d.ts.map +1 -0
  4. package/dest/config.js +92 -0
  5. package/dest/db/index.d.ts +4 -0
  6. package/dest/db/index.d.ts.map +1 -0
  7. package/dest/db/index.js +3 -0
  8. package/dest/db/migrations/1_initial-schema.d.ts +9 -0
  9. package/dest/db/migrations/1_initial-schema.d.ts.map +1 -0
  10. package/dest/db/migrations/1_initial-schema.js +20 -0
  11. package/dest/db/postgres.d.ts +84 -0
  12. package/dest/db/postgres.d.ts.map +1 -0
  13. package/dest/db/postgres.js +210 -0
  14. package/dest/db/schema.d.ts +95 -0
  15. package/dest/db/schema.d.ts.map +1 -0
  16. package/dest/db/schema.js +229 -0
  17. package/dest/db/test_helper.d.ts +10 -0
  18. package/dest/db/test_helper.d.ts.map +1 -0
  19. package/dest/db/test_helper.js +14 -0
  20. package/dest/db/types.d.ts +166 -0
  21. package/dest/db/types.d.ts.map +1 -0
  22. package/dest/db/types.js +49 -0
  23. package/dest/errors.d.ts +34 -0
  24. package/dest/errors.d.ts.map +1 -0
  25. package/dest/errors.js +34 -0
  26. package/dest/factory.d.ts +42 -0
  27. package/dest/factory.d.ts.map +1 -0
  28. package/dest/factory.js +70 -0
  29. package/dest/migrations.d.ts +15 -0
  30. package/dest/migrations.d.ts.map +1 -0
  31. package/dest/migrations.js +53 -0
  32. package/dest/slashing_protection_service.d.ts +84 -0
  33. package/dest/slashing_protection_service.d.ts.map +1 -0
  34. package/dest/slashing_protection_service.js +225 -0
  35. package/dest/test/pglite_pool.d.ts +92 -0
  36. package/dest/test/pglite_pool.d.ts.map +1 -0
  37. package/dest/test/pglite_pool.js +210 -0
  38. package/dest/types.d.ts +152 -0
  39. package/dest/types.d.ts.map +1 -0
  40. package/dest/types.js +21 -0
  41. package/dest/validator_ha_signer.d.ts +71 -0
  42. package/dest/validator_ha_signer.d.ts.map +1 -0
  43. package/dest/validator_ha_signer.js +132 -0
  44. package/package.json +106 -0
  45. package/src/config.ts +149 -0
  46. package/src/db/index.ts +3 -0
  47. package/src/db/migrations/1_initial-schema.ts +26 -0
  48. package/src/db/postgres.ts +284 -0
  49. package/src/db/schema.ts +266 -0
  50. package/src/db/test_helper.ts +17 -0
  51. package/src/db/types.ts +206 -0
  52. package/src/errors.ts +47 -0
  53. package/src/factory.ts +82 -0
  54. package/src/migrations.ts +75 -0
  55. package/src/slashing_protection_service.ts +287 -0
  56. package/src/test/pglite_pool.ts +256 -0
  57. package/src/types.ts +226 -0
  58. package/src/validator_ha_signer.ts +162 -0
@@ -0,0 +1,152 @@
1
+ import { BlockNumber, type CheckpointNumber, type IndexWithinCheckpoint, type SlotNumber } from '@aztec/foundation/branded-types';
2
+ import type { EthAddress } from '@aztec/foundation/eth-address';
3
+ import type { Pool } from 'pg';
4
+ import type { ValidatorHASignerConfig } from './config.js';
5
+ import { type BlockProposalDutyIdentifier, type CheckAndRecordParams, type DeleteDutyParams, type DutyIdentifier, type DutyRow, DutyType, type OtherDutyIdentifier, type RecordSuccessParams, type ValidatorDutyRecord } from './db/types.js';
6
+ export type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyRow, OtherDutyIdentifier, RecordSuccessParams, ValidatorDutyRecord, ValidatorHASignerConfig, };
7
+ export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
8
+ /**
9
+ * Result of tryInsertOrGetExisting operation
10
+ */
11
+ export interface TryInsertOrGetResult {
12
+ /** True if we inserted a new record, false if we got an existing record */
13
+ isNew: boolean;
14
+ /** The record (either newly inserted or existing) */
15
+ record: ValidatorDutyRecord;
16
+ }
17
+ /**
18
+ * deps for creating an HA signer
19
+ */
20
+ export interface CreateHASignerDeps {
21
+ /**
22
+ * Optional PostgreSQL connection pool
23
+ * If provided, databaseUrl and poolConfig are ignored
24
+ */
25
+ pool?: Pool;
26
+ }
27
+ /**
28
+ * Base context for signing operations
29
+ */
30
+ interface BaseSigningContext {
31
+ /** Slot number for this duty */
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: IndexWithinCheckpoint;
47
+ dutyType: DutyType.BLOCK_PROPOSAL;
48
+ }
49
+ /**
50
+ * Signing context for non-block-proposal duties that require HA protection.
51
+ * blockIndexWithinCheckpoint is not applicable (internally always -1).
52
+ */
53
+ export interface OtherSigningContext extends BaseSigningContext {
54
+ dutyType: DutyType.CHECKPOINT_PROPOSAL | DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS;
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;
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;
96
+ /**
97
+ * Database interface for slashing protection operations
98
+ * This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
99
+ *
100
+ * The interface is designed around 3 core operations:
101
+ * 1. tryInsertOrGetExisting - Atomically insert or get existing record (eliminates race conditions)
102
+ * 2. updateDutySigned - Update to signed status on success
103
+ * 3. deleteDuty - Delete a duty record on failure
104
+ */
105
+ export interface SlashingProtectionDatabase {
106
+ /**
107
+ * Atomically try to insert a new duty record, or get the existing one if present.
108
+ *
109
+ * @returns { isNew: true, record } if we successfully inserted and acquired the lock
110
+ * @returns { isNew: false, record } if a record already exists (caller should handle based on status)
111
+ */
112
+ tryInsertOrGetExisting(params: CheckAndRecordParams): Promise<TryInsertOrGetResult>;
113
+ /**
114
+ * Update a duty to 'signed' status with the signature.
115
+ * Only succeeds if the lockToken matches (caller must be the one who created the duty).
116
+ *
117
+ * @returns true if the update succeeded, false if token didn't match or duty not found
118
+ */
119
+ updateDutySigned(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, signature: string, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
120
+ /**
121
+ * Delete a duty record.
122
+ * Only succeeds if the lockToken matches (caller must be the one who created the duty).
123
+ * Used when signing fails to allow another node/attempt to retry.
124
+ *
125
+ * @returns true if the delete succeeded, false if token didn't match or duty not found
126
+ */
127
+ deleteDuty(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
128
+ /**
129
+ * Cleanup own stuck duties
130
+ * @returns the number of duties cleaned up
131
+ */
132
+ cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number>;
133
+ /**
134
+ * Cleanup duties with outdated rollup address.
135
+ * Removes all duties where the rollup address doesn't match the current one.
136
+ * Used after a rollup upgrade to clean up duties for the old rollup.
137
+ * @returns the number of duties cleaned up
138
+ */
139
+ cleanupOutdatedRollupDuties(currentRollupAddress: EthAddress): Promise<number>;
140
+ /**
141
+ * Cleanup old signed duties.
142
+ * Removes only signed duties older than the specified age.
143
+ * @returns the number of duties cleaned up
144
+ */
145
+ cleanupOldDuties(maxAgeMs: number): Promise<number>;
146
+ /**
147
+ * Close the database connection.
148
+ * Should be called during graceful shutdown.
149
+ */
150
+ close(): Promise<void>;
151
+ }
152
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsV0FBVyxFQUNYLEtBQUssZ0JBQWdCLEVBQ3JCLEtBQUsscUJBQXFCLEVBQzFCLEtBQUssVUFBVSxFQUNoQixNQUFNLGlDQUFpQyxDQUFDO0FBQ3pDLE9BQU8sS0FBSyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQ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AU,EAChB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,MAAM,GACjC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB;;;;;;OAMG;IACH,UAAU,CACR,aAAa,EAAE,UAAU,EACzB,gBAAgB,EAAE,UAAU,EAC5B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,MAAM,EACjB,0BAA0B,EAAE,MAAM,GACjC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEpB;;;OAGG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEzE;;;;;OAKG;IACH,2BAA2B,CAAC,oBAAoB,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE/E;;;;OAIG;IACH,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAEpD;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB"}
package/dest/types.js ADDED
@@ -0,0 +1,21 @@
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
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Validator High Availability Signer
3
+ *
4
+ * Wraps signing operations with distributed locking and slashing protection.
5
+ * This ensures that even with multiple validator nodes running, only one
6
+ * node will sign for a given duty (slot + duty type).
7
+ */
8
+ import type { Buffer32 } from '@aztec/foundation/buffer';
9
+ import { EthAddress } from '@aztec/foundation/eth-address';
10
+ import type { Signature } from '@aztec/foundation/eth-signature';
11
+ import type { ValidatorHASignerConfig } from './config.js';
12
+ import { type HAProtectedSigningContext, type SlashingProtectionDatabase } from './types.js';
13
+ /**
14
+ * Validator High Availability Signer
15
+ *
16
+ * Provides signing capabilities with distributed locking for validators
17
+ * in a high-availability setup.
18
+ *
19
+ * Usage:
20
+ * ```
21
+ * const signer = new ValidatorHASigner(db, config);
22
+ *
23
+ * // Sign with slashing protection
24
+ * const signature = await signer.signWithProtection(
25
+ * validatorAddress,
26
+ * messageHash,
27
+ * { slot: 100n, blockNumber: 50n, dutyType: 'BLOCK_PROPOSAL' },
28
+ * async (root) => localSigner.signMessage(root),
29
+ * );
30
+ * ```
31
+ */
32
+ export declare class ValidatorHASigner {
33
+ private readonly config;
34
+ private readonly log;
35
+ private readonly slashingProtection;
36
+ private readonly rollupAddress;
37
+ constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig);
38
+ /**
39
+ * Sign a message with slashing protection.
40
+ *
41
+ * This method:
42
+ * 1. Acquires a distributed lock for (validator, slot, dutyType)
43
+ * 2. Calls the provided signing function
44
+ * 3. Records the result (success or failure)
45
+ *
46
+ * @param validatorAddress - The validator's Ethereum address
47
+ * @param messageHash - The hash to be signed
48
+ * @param context - The signing context (HA-protected duty types only)
49
+ * @param signFn - Function that performs the actual signing
50
+ * @returns The signature
51
+ *
52
+ * @throws DutyAlreadySignedError if the duty was already signed (expected in HA)
53
+ * @throws SlashingProtectionError if attempting to sign different data for same slot (expected in HA)
54
+ */
55
+ signWithProtection(validatorAddress: EthAddress, messageHash: Buffer32, context: HAProtectedSigningContext, signFn: (messageHash: Buffer32) => Promise<Signature>): Promise<Signature>;
56
+ /**
57
+ * Get the node ID for this signer
58
+ */
59
+ get nodeId(): string;
60
+ /**
61
+ * Start the HA signer background tasks (cleanup of stuck duties).
62
+ * Should be called after construction and before signing operations.
63
+ */
64
+ start(): Promise<void>;
65
+ /**
66
+ * Stop the HA signer background tasks and close database connection.
67
+ * Should be called during graceful shutdown.
68
+ */
69
+ stop(): Promise<void>;
70
+ }
71
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdG9yX2hhX3NpZ25lci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3ZhbGlkYXRvcl9oYV9zaWduZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDekQsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQzNELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBR2pFLE9BQU8sS0FBSyxFQUFFLHVCQUF1QixFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRzNELE9BQU8sRUFDTCxLQUFLLHlCQUF5QixFQUM5QixLQUFLLDBCQUEwQixFQUVoQyxNQUFNLFlBQVksQ0FBQztBQUVwQjs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBa0JHO0FBQ0g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AAC;AAEpB;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,iBAAiB;IAO1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IANzB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAS;IAC7B,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA4B;IAC/D,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAa;IAE3C,YACE,EAAE,EAAE,0BAA0B,EACb,MAAM,EAAE,uBAAuB,EAkBjD;IAED;;;;;;;;;;;;;;;;OAgBG;IACG,kBAAkB,CACtB,gBAAgB,EAAE,UAAU,EAC5B,WAAW,EAAE,QAAQ,EACrB,OAAO,EAAE,yBAAyB,EAClC,MAAM,EAAE,CAAC,WAAW,EAAE,QAAQ,KAAK,OAAO,CAAC,SAAS,CAAC,GACpD,OAAO,CAAC,SAAS,CAAC,CA+CpB;IAED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACG,KAAK,kBAEV;IAED;;;OAGG;IACG,IAAI,kBAGT;CACF"}
@@ -0,0 +1,132 @@
1
+ /**
2
+ * Validator High Availability Signer
3
+ *
4
+ * Wraps signing operations with distributed locking and slashing protection.
5
+ * This ensures that even with multiple validator nodes running, only one
6
+ * node will sign for a given duty (slot + duty type).
7
+ */ import { createLogger } from '@aztec/foundation/log';
8
+ import { DutyType } from './db/types.js';
9
+ import { SlashingProtectionService } from './slashing_protection_service.js';
10
+ import { getBlockNumberFromSigningContext } from './types.js';
11
+ /**
12
+ * Validator High Availability Signer
13
+ *
14
+ * Provides signing capabilities with distributed locking for validators
15
+ * in a high-availability setup.
16
+ *
17
+ * Usage:
18
+ * ```
19
+ * const signer = new ValidatorHASigner(db, config);
20
+ *
21
+ * // Sign with slashing protection
22
+ * const signature = await signer.signWithProtection(
23
+ * validatorAddress,
24
+ * messageHash,
25
+ * { slot: 100n, blockNumber: 50n, dutyType: 'BLOCK_PROPOSAL' },
26
+ * async (root) => localSigner.signMessage(root),
27
+ * );
28
+ * ```
29
+ */ export class ValidatorHASigner {
30
+ config;
31
+ log;
32
+ slashingProtection;
33
+ rollupAddress;
34
+ constructor(db, config){
35
+ this.config = config;
36
+ this.log = createLogger('validator-ha-signer');
37
+ if (!config.haSigningEnabled) {
38
+ // this shouldn't happen, the validator should use different signer for non-HA setups
39
+ throw new Error('Validator HA Signer is not enabled in config');
40
+ }
41
+ if (!config.nodeId || config.nodeId === '') {
42
+ throw new Error('NODE_ID is required for high-availability setups');
43
+ }
44
+ this.rollupAddress = config.l1Contracts.rollupAddress;
45
+ this.slashingProtection = new SlashingProtectionService(db, config);
46
+ this.log.info('Validator HA Signer initialized with slashing protection', {
47
+ nodeId: config.nodeId,
48
+ rollupAddress: this.rollupAddress.toString()
49
+ });
50
+ }
51
+ /**
52
+ * Sign a message with slashing protection.
53
+ *
54
+ * This method:
55
+ * 1. Acquires a distributed lock for (validator, slot, dutyType)
56
+ * 2. Calls the provided signing function
57
+ * 3. Records the result (success or failure)
58
+ *
59
+ * @param validatorAddress - The validator's Ethereum address
60
+ * @param messageHash - The hash to be signed
61
+ * @param context - The signing context (HA-protected duty types only)
62
+ * @param signFn - Function that performs the actual signing
63
+ * @returns The signature
64
+ *
65
+ * @throws DutyAlreadySignedError if the duty was already signed (expected in HA)
66
+ * @throws SlashingProtectionError if attempting to sign different data for same slot (expected in HA)
67
+ */ async signWithProtection(validatorAddress, messageHash, context, signFn) {
68
+ let dutyIdentifier;
69
+ if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
70
+ dutyIdentifier = {
71
+ rollupAddress: this.rollupAddress,
72
+ validatorAddress,
73
+ slot: context.slot,
74
+ blockIndexWithinCheckpoint: context.blockIndexWithinCheckpoint,
75
+ dutyType: context.dutyType
76
+ };
77
+ } else {
78
+ dutyIdentifier = {
79
+ rollupAddress: this.rollupAddress,
80
+ validatorAddress,
81
+ slot: context.slot,
82
+ dutyType: context.dutyType
83
+ };
84
+ }
85
+ // Acquire lock and get the token for ownership verification
86
+ const blockNumber = getBlockNumberFromSigningContext(context);
87
+ const lockToken = await this.slashingProtection.checkAndRecord({
88
+ ...dutyIdentifier,
89
+ blockNumber,
90
+ messageHash: messageHash.toString(),
91
+ nodeId: this.config.nodeId
92
+ });
93
+ // Perform signing
94
+ let signature;
95
+ try {
96
+ signature = await signFn(messageHash);
97
+ } catch (error) {
98
+ // Delete duty to allow retry (only succeeds if we own the lock)
99
+ await this.slashingProtection.deleteDuty({
100
+ ...dutyIdentifier,
101
+ lockToken
102
+ });
103
+ throw error;
104
+ }
105
+ // Record success (only succeeds if we own the lock)
106
+ await this.slashingProtection.recordSuccess({
107
+ ...dutyIdentifier,
108
+ signature,
109
+ nodeId: this.config.nodeId,
110
+ lockToken
111
+ });
112
+ return signature;
113
+ }
114
+ /**
115
+ * Get the node ID for this signer
116
+ */ get nodeId() {
117
+ return this.config.nodeId;
118
+ }
119
+ /**
120
+ * Start the HA signer background tasks (cleanup of stuck duties).
121
+ * Should be called after construction and before signing operations.
122
+ */ async start() {
123
+ await this.slashingProtection.start();
124
+ }
125
+ /**
126
+ * Stop the HA signer background tasks and close database connection.
127
+ * Should be called during graceful shutdown.
128
+ */ async stop() {
129
+ await this.slashingProtection.stop();
130
+ await this.slashingProtection.close();
131
+ }
132
+ }
package/package.json ADDED
@@ -0,0 +1,106 @@
1
+ {
2
+ "name": "@aztec/validator-ha-signer",
3
+ "version": "0.0.1-commit.0208eb9",
4
+ "type": "module",
5
+ "exports": {
6
+ "./config": "./dest/config.js",
7
+ "./db": "./dest/db/index.js",
8
+ "./errors": "./dest/errors.js",
9
+ "./factory": "./dest/factory.js",
10
+ "./migrations": "./dest/migrations.js",
11
+ "./slashing-protection-service": "./dest/slashing_protection_service.js",
12
+ "./types": "./dest/types.js",
13
+ "./validator-ha-signer": "./dest/validator_ha_signer.js",
14
+ "./test": "./dest/test/pglite_pool.js"
15
+ },
16
+ "typedocOptions": {
17
+ "entryPoints": [
18
+ "./src/config.ts",
19
+ "./src/db/index.ts",
20
+ "./src/errors.ts",
21
+ "./src/factory.ts",
22
+ "./src/migrations.ts",
23
+ "./src/slashing_protection_service.ts",
24
+ "./src/types.ts",
25
+ "./src/validator_ha_signer.ts"
26
+ ],
27
+ "name": "Validator High-Availability Signer",
28
+ "tsconfig": "./tsconfig.json"
29
+ },
30
+ "scripts": {
31
+ "build": "yarn clean && ../scripts/tsc.sh",
32
+ "build:dev": "../scripts/tsc.sh --watch",
33
+ "clean": "rm -rf ./dest .tsbuildinfo",
34
+ "test": "NODE_NO_WARNINGS=1 node --experimental-vm-modules ../node_modules/.bin/jest --passWithNoTests --maxWorkers=${JEST_MAX_WORKERS:-8}"
35
+ },
36
+ "inherits": [
37
+ "../package.common.json"
38
+ ],
39
+ "jest": {
40
+ "moduleNameMapper": {
41
+ "^(\\.{1,2}/.*)\\.[cm]?js$": "$1"
42
+ },
43
+ "testRegex": "./src/.*\\.test\\.(js|mjs|ts)$",
44
+ "rootDir": "./src",
45
+ "transform": {
46
+ "^.+\\.tsx?$": [
47
+ "@swc/jest",
48
+ {
49
+ "jsc": {
50
+ "parser": {
51
+ "syntax": "typescript",
52
+ "decorators": true
53
+ },
54
+ "transform": {
55
+ "decoratorVersion": "2022-03"
56
+ }
57
+ }
58
+ }
59
+ ]
60
+ },
61
+ "extensionsToTreatAsEsm": [
62
+ ".ts"
63
+ ],
64
+ "reporters": [
65
+ "default"
66
+ ],
67
+ "testTimeout": 120000,
68
+ "setupFiles": [
69
+ "../../foundation/src/jest/setup.mjs"
70
+ ],
71
+ "testEnvironment": "../../foundation/src/jest/env.mjs",
72
+ "setupFilesAfterEnv": [
73
+ "../../foundation/src/jest/setupAfterEnv.mjs"
74
+ ]
75
+ },
76
+ "dependencies": {
77
+ "@aztec/ethereum": "0.0.1-commit.0208eb9",
78
+ "@aztec/foundation": "0.0.1-commit.0208eb9",
79
+ "node-pg-migrate": "^8.0.4",
80
+ "pg": "^8.11.3",
81
+ "tslib": "^2.4.0",
82
+ "zod": "^3.23.8"
83
+ },
84
+ "devDependencies": {
85
+ "@electric-sql/pglite": "^0.3.14",
86
+ "@jest/globals": "^30.0.0",
87
+ "@types/jest": "^30.0.0",
88
+ "@types/node": "^22.15.17",
89
+ "@types/node-pg-migrate": "^2.3.1",
90
+ "@types/pg": "^8.10.9",
91
+ "@typescript/native-preview": "7.0.0-dev.20260113.1",
92
+ "jest": "^30.0.0",
93
+ "jest-mock-extended": "^4.0.0",
94
+ "ts-node": "^10.9.1",
95
+ "typescript": "^5.3.3"
96
+ },
97
+ "types": "./dest/types.d.ts",
98
+ "files": [
99
+ "dest",
100
+ "src",
101
+ "!*.test.*"
102
+ ],
103
+ "engines": {
104
+ "node": ">=20.10"
105
+ }
106
+ }
package/src/config.ts ADDED
@@ -0,0 +1,149 @@
1
+ import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
2
+ import {
3
+ type ConfigMappingsType,
4
+ booleanConfigHelper,
5
+ getConfigFromMappings,
6
+ getDefaultConfig,
7
+ numberConfigHelper,
8
+ optionalNumberConfigHelper,
9
+ } from '@aztec/foundation/config';
10
+ import { EthAddress } from '@aztec/foundation/eth-address';
11
+ import type { ZodFor } from '@aztec/foundation/schemas';
12
+
13
+ import { z } from 'zod';
14
+
15
+ /**
16
+ * Configuration for the Validator HA Signer
17
+ *
18
+ * This config is used for distributed locking and slashing protection
19
+ * when running multiple validator nodes in a high-availability setup.
20
+ */
21
+ export interface ValidatorHASignerConfig {
22
+ /** Whether HA signing / slashing protection is enabled */
23
+ haSigningEnabled: boolean;
24
+ /** L1 contract addresses (rollup address required) */
25
+ l1Contracts: Pick<L1ContractAddresses, 'rollupAddress'>;
26
+ /** Unique identifier for this node */
27
+ nodeId: string;
28
+ /** How long to wait between polls when a duty is being signed (ms) */
29
+ pollingIntervalMs: number;
30
+ /** Maximum time to wait for a duty being signed to complete (ms) */
31
+ signingTimeoutMs: number;
32
+ /** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
33
+ maxStuckDutiesAgeMs?: number;
34
+ /** Optional: clean up old duties after this many hours (disabled if not set) */
35
+ cleanupOldDutiesAfterHours?: number;
36
+ /**
37
+ * PostgreSQL connection string
38
+ * Format: postgresql://user:password@host:port/database
39
+ */
40
+ databaseUrl?: string;
41
+ /**
42
+ * PostgreSQL connection pool configuration
43
+ */
44
+ /** Maximum number of clients in the pool (default: 10) */
45
+ poolMaxCount?: number;
46
+ /** Minimum number of clients in the pool (default: 0) */
47
+ poolMinCount?: number;
48
+ /** Idle timeout in milliseconds (default: 10000) */
49
+ poolIdleTimeoutMs?: number;
50
+ /** Connection timeout in milliseconds (default: 0, no timeout) */
51
+ poolConnectionTimeoutMs?: number;
52
+ }
53
+
54
+ export const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASignerConfig> = {
55
+ haSigningEnabled: {
56
+ env: 'VALIDATOR_HA_SIGNING_ENABLED',
57
+ description: 'Whether HA signing / slashing protection is enabled',
58
+ ...booleanConfigHelper(false),
59
+ },
60
+ l1Contracts: {
61
+ description: 'L1 contract addresses (rollup address required)',
62
+ nested: {
63
+ rollupAddress: {
64
+ description: 'The Ethereum address of the rollup contract (must be set programmatically)',
65
+ parseEnv: (val: string) => EthAddress.fromString(val),
66
+ },
67
+ },
68
+ },
69
+ nodeId: {
70
+ env: 'VALIDATOR_HA_NODE_ID',
71
+ description: 'The unique identifier for this node',
72
+ defaultValue: '',
73
+ },
74
+ pollingIntervalMs: {
75
+ env: 'VALIDATOR_HA_POLLING_INTERVAL_MS',
76
+ description: 'The number of ms to wait between polls when a duty is being signed',
77
+ ...numberConfigHelper(100),
78
+ },
79
+ signingTimeoutMs: {
80
+ env: 'VALIDATOR_HA_SIGNING_TIMEOUT_MS',
81
+ description: 'The maximum time to wait for a duty being signed to complete',
82
+ ...numberConfigHelper(3_000),
83
+ },
84
+ maxStuckDutiesAgeMs: {
85
+ env: 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS',
86
+ description: 'The maximum age of a stuck duty in ms (defaults to 2x Aztec slot duration)',
87
+ ...optionalNumberConfigHelper(),
88
+ },
89
+ cleanupOldDutiesAfterHours: {
90
+ env: 'VALIDATOR_HA_OLD_DUTIES_MAX_AGE_H',
91
+ description: 'Optional: clean up old duties after this many hours (disabled if not set)',
92
+ ...optionalNumberConfigHelper(),
93
+ },
94
+ databaseUrl: {
95
+ env: 'VALIDATOR_HA_DATABASE_URL',
96
+ description:
97
+ 'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)',
98
+ },
99
+ poolMaxCount: {
100
+ env: 'VALIDATOR_HA_POOL_MAX',
101
+ description: 'Maximum number of clients in the pool',
102
+ ...numberConfigHelper(10),
103
+ },
104
+ poolMinCount: {
105
+ env: 'VALIDATOR_HA_POOL_MIN',
106
+ description: 'Minimum number of clients in the pool',
107
+ ...numberConfigHelper(0),
108
+ },
109
+ poolIdleTimeoutMs: {
110
+ env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
111
+ description: 'Idle timeout in milliseconds',
112
+ ...numberConfigHelper(10_000),
113
+ },
114
+ poolConnectionTimeoutMs: {
115
+ env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
116
+ description: 'Connection timeout in milliseconds (0 means no timeout)',
117
+ ...numberConfigHelper(0),
118
+ },
119
+ };
120
+
121
+ export const defaultValidatorHASignerConfig: ValidatorHASignerConfig = getDefaultConfig(
122
+ validatorHASignerConfigMappings,
123
+ );
124
+
125
+ /**
126
+ * Returns the validator HA signer configuration from environment variables.
127
+ * Note: If an environment variable is not set, the default value is used.
128
+ * @returns The validator HA signer configuration.
129
+ */
130
+ export function getConfigEnvVars(): ValidatorHASignerConfig {
131
+ return getConfigFromMappings<ValidatorHASignerConfig>(validatorHASignerConfigMappings);
132
+ }
133
+
134
+ export const ValidatorHASignerConfigSchema = z.object({
135
+ haSigningEnabled: z.boolean(),
136
+ l1Contracts: z.object({
137
+ rollupAddress: z.instanceof(EthAddress),
138
+ }),
139
+ nodeId: z.string(),
140
+ pollingIntervalMs: z.number().min(0),
141
+ signingTimeoutMs: z.number().min(0),
142
+ maxStuckDutiesAgeMs: z.number().min(0).optional(),
143
+ cleanupOldDutiesAfterHours: z.number().min(0).optional(),
144
+ databaseUrl: z.string().optional(),
145
+ poolMaxCount: z.number().min(0).optional(),
146
+ poolMinCount: z.number().min(0).optional(),
147
+ poolIdleTimeoutMs: z.number().min(0).optional(),
148
+ poolConnectionTimeoutMs: z.number().min(0).optional(),
149
+ }) satisfies ZodFor<ValidatorHASignerConfig>;
@@ -0,0 +1,3 @@
1
+ export * from './types.js';
2
+ export * from './schema.js';
3
+ export * from './postgres.js';