@aztec/validator-ha-signer 0.0.1-commit.7d4e6cd → 0.0.1-commit.87a0206
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.
- package/README.md +42 -37
- package/dest/config.d.ts +71 -17
- package/dest/config.d.ts.map +1 -1
- package/dest/config.js +47 -19
- package/dest/db/postgres.d.ts +34 -5
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +80 -20
- package/dest/db/schema.d.ts +19 -9
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +46 -18
- package/dest/db/types.d.ts +81 -24
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +34 -0
- package/dest/errors.d.ts +9 -5
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +7 -4
- package/dest/factory.d.ts +6 -14
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +6 -11
- package/dest/migrations.d.ts +1 -1
- package/dest/migrations.d.ts.map +1 -1
- package/dest/migrations.js +13 -2
- package/dest/slashing_protection_service.d.ts +16 -6
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +58 -17
- package/dest/test/pglite_pool.d.ts +92 -0
- package/dest/test/pglite_pool.d.ts.map +1 -0
- package/dest/test/pglite_pool.js +210 -0
- package/dest/types.d.ts +91 -14
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +21 -1
- package/dest/validator_ha_signer.d.ts +10 -13
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +32 -31
- package/package.json +9 -8
- package/src/config.ts +83 -50
- package/src/db/postgres.ts +101 -19
- package/src/db/schema.ts +48 -18
- package/src/db/types.ts +111 -22
- package/src/errors.ts +7 -2
- package/src/factory.ts +8 -13
- package/src/migrations.ts +17 -1
- package/src/slashing_protection_service.ts +94 -23
- package/src/test/pglite_pool.ts +256 -0
- package/src/types.ts +140 -19
- package/src/validator_ha_signer.ts +39 -41
package/dest/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { BlockNumber, type CheckpointNumber, type IndexWithinCheckpoint, 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 {
|
|
4
|
-
import type
|
|
5
|
-
export type {
|
|
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, 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';
|
|
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
|
-
*
|
|
28
|
+
* Base context for signing operations
|
|
28
29
|
*/
|
|
29
|
-
|
|
30
|
+
interface BaseSigningContext {
|
|
30
31
|
/** Slot number for this duty */
|
|
31
|
-
slot:
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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;
|
|
36
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;
|
|
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:
|
|
119
|
+
updateDutySigned(rollupAddress: EthAddress, 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,29 @@ 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:
|
|
127
|
+
deleteDuty(rollupAddress: EthAddress, 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
|
+
* 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>;
|
|
74
151
|
}
|
|
75
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
152
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsV0FBVyxFQUNYLEtBQUssZ0JBQWdCLE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VUsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7SUFFL0U7Ozs7T0FJRztJQUNILGdCQUFnQixDQUFDLFFBQVEsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBRXBEOzs7T0FHRztJQUNILEtBQUssSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7Q0FDeEIifQ==
|
package/dest/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,UAAU,EAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAEhE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAE/B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EACL,KAAK,2BAA2B,EAChC,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,OAAO,EACZ,QAAQ,EACR,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACzB,MAAM,eAAe,CAAC;AAEvB,YAAY,EACV,2BAA2B,EAC3B,oBAAoB,EACpB,gBAAgB,EAChB,cAAc,EACd,OAAO,EACP,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,GACxB,CAAC;AACF,O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|
+
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
|
+
}
|
|
@@ -6,10 +6,10 @@
|
|
|
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
|
|
9
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
10
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
11
|
-
import type {
|
|
12
|
-
import type
|
|
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,8 @@ export declare class ValidatorHASigner {
|
|
|
33
33
|
private readonly config;
|
|
34
34
|
private readonly log;
|
|
35
35
|
private readonly slashingProtection;
|
|
36
|
-
|
|
36
|
+
private readonly rollupAddress;
|
|
37
|
+
constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig);
|
|
37
38
|
/**
|
|
38
39
|
* Sign a message with slashing protection.
|
|
39
40
|
*
|
|
@@ -44,18 +45,14 @@ export declare class ValidatorHASigner {
|
|
|
44
45
|
*
|
|
45
46
|
* @param validatorAddress - The validator's Ethereum address
|
|
46
47
|
* @param messageHash - The hash to be signed
|
|
47
|
-
* @param context - The signing context (
|
|
48
|
+
* @param context - The signing context (HA-protected duty types only)
|
|
48
49
|
* @param signFn - Function that performs the actual signing
|
|
49
50
|
* @returns The signature
|
|
50
51
|
*
|
|
51
52
|
* @throws DutyAlreadySignedError if the duty was already signed (expected in HA)
|
|
52
53
|
* @throws SlashingProtectionError if attempting to sign different data for same slot (expected in HA)
|
|
53
54
|
*/
|
|
54
|
-
signWithProtection(validatorAddress: EthAddress, messageHash: Buffer32, context:
|
|
55
|
-
/**
|
|
56
|
-
* Check if slashing protection is enabled
|
|
57
|
-
*/
|
|
58
|
-
get isEnabled(): boolean;
|
|
55
|
+
signWithProtection(validatorAddress: EthAddress, messageHash: Buffer32, context: HAProtectedSigningContext, signFn: (messageHash: Buffer32) => Promise<Signature>): Promise<Signature>;
|
|
59
56
|
/**
|
|
60
57
|
* Get the node ID for this signer
|
|
61
58
|
*/
|
|
@@ -64,11 +61,11 @@ export declare class ValidatorHASigner {
|
|
|
64
61
|
* Start the HA signer background tasks (cleanup of stuck duties).
|
|
65
62
|
* Should be called after construction and before signing operations.
|
|
66
63
|
*/
|
|
67
|
-
start(): void
|
|
64
|
+
start(): Promise<void>;
|
|
68
65
|
/**
|
|
69
|
-
* Stop the HA signer background tasks.
|
|
66
|
+
* Stop the HA signer background tasks and close database connection.
|
|
70
67
|
* Should be called during graceful shutdown.
|
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BQVUsRUFDNUIsV0FBVyxFQUFFLFFBQVEsRUFDckIsT0FBTyxFQUFFLHlCQUF5QixFQUNsQyxNQUFNLEVBQUUsQ0FBQyxXQUFXLEVBQUUsUUFBUSxLQUFLLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FDcEQsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQStDcEI7SUFFRDs7T0FFRztJQUNILElBQUksTUFBTSxJQUFJLE1BQU0sQ0FFbkI7SUFFRDs7O09BR0c7SUFDRyxLQUFLLGtCQUVWO0lBRUQ7OztPQUdHO0lBQ0csSUFBSSxrQkFHVDtDQUNGIn0=
|
|
@@ -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,
|
|
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,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,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;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"}
|
|
@@ -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
|
*
|
|
@@ -28,19 +30,22 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
28
30
|
config;
|
|
29
31
|
log;
|
|
30
32
|
slashingProtection;
|
|
33
|
+
rollupAddress;
|
|
31
34
|
constructor(db, config){
|
|
32
35
|
this.config = config;
|
|
33
36
|
this.log = createLogger('validator-ha-signer');
|
|
34
|
-
if (!config.
|
|
37
|
+
if (!config.haSigningEnabled) {
|
|
35
38
|
// this shouldn't happen, the validator should use different signer for non-HA setups
|
|
36
39
|
throw new Error('Validator HA Signer is not enabled in config');
|
|
37
40
|
}
|
|
38
41
|
if (!config.nodeId || config.nodeId === '') {
|
|
39
42
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
40
43
|
}
|
|
44
|
+
this.rollupAddress = config.l1Contracts.rollupAddress;
|
|
41
45
|
this.slashingProtection = new SlashingProtectionService(db, config);
|
|
42
46
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
43
|
-
nodeId: config.nodeId
|
|
47
|
+
nodeId: config.nodeId,
|
|
48
|
+
rollupAddress: this.rollupAddress.toString()
|
|
44
49
|
});
|
|
45
50
|
}
|
|
46
51
|
/**
|
|
@@ -53,31 +58,35 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
53
58
|
*
|
|
54
59
|
* @param validatorAddress - The validator's Ethereum address
|
|
55
60
|
* @param messageHash - The hash to be signed
|
|
56
|
-
* @param context - The signing context (
|
|
61
|
+
* @param context - The signing context (HA-protected duty types only)
|
|
57
62
|
* @param signFn - Function that performs the actual signing
|
|
58
63
|
* @returns The signature
|
|
59
64
|
*
|
|
60
65
|
* @throws DutyAlreadySignedError if the duty was already signed (expected in HA)
|
|
61
66
|
* @throws SlashingProtectionError if attempting to sign different data for same slot (expected in HA)
|
|
62
67
|
*/ async signWithProtection(validatorAddress, messageHash, context, signFn) {
|
|
63
|
-
|
|
64
|
-
if (
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
dutyType: context.dutyType,
|
|
68
|
+
let dutyIdentifier;
|
|
69
|
+
if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
|
|
70
|
+
dutyIdentifier = {
|
|
71
|
+
rollupAddress: this.rollupAddress,
|
|
72
|
+
validatorAddress,
|
|
69
73
|
slot: context.slot,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
+
};
|
|
73
84
|
}
|
|
74
|
-
const { slot, blockNumber, dutyType } = context;
|
|
75
85
|
// Acquire lock and get the token for ownership verification
|
|
86
|
+
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
76
87
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
77
|
-
|
|
78
|
-
slot,
|
|
88
|
+
...dutyIdentifier,
|
|
79
89
|
blockNumber,
|
|
80
|
-
dutyType,
|
|
81
90
|
messageHash: messageHash.toString(),
|
|
82
91
|
nodeId: this.config.nodeId
|
|
83
92
|
});
|
|
@@ -88,18 +97,14 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
88
97
|
} catch (error) {
|
|
89
98
|
// Delete duty to allow retry (only succeeds if we own the lock)
|
|
90
99
|
await this.slashingProtection.deleteDuty({
|
|
91
|
-
|
|
92
|
-
slot,
|
|
93
|
-
dutyType,
|
|
100
|
+
...dutyIdentifier,
|
|
94
101
|
lockToken
|
|
95
102
|
});
|
|
96
103
|
throw error;
|
|
97
104
|
}
|
|
98
105
|
// Record success (only succeeds if we own the lock)
|
|
99
106
|
await this.slashingProtection.recordSuccess({
|
|
100
|
-
|
|
101
|
-
slot,
|
|
102
|
-
dutyType,
|
|
107
|
+
...dutyIdentifier,
|
|
103
108
|
signature,
|
|
104
109
|
nodeId: this.config.nodeId,
|
|
105
110
|
lockToken
|
|
@@ -107,11 +112,6 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
107
112
|
return signature;
|
|
108
113
|
}
|
|
109
114
|
/**
|
|
110
|
-
* Check if slashing protection is enabled
|
|
111
|
-
*/ get isEnabled() {
|
|
112
|
-
return this.slashingProtection !== undefined;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
115
|
* Get the node ID for this signer
|
|
116
116
|
*/ get nodeId() {
|
|
117
117
|
return this.config.nodeId;
|
|
@@ -119,13 +119,14 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
119
119
|
/**
|
|
120
120
|
* Start the HA signer background tasks (cleanup of stuck duties).
|
|
121
121
|
* Should be called after construction and before signing operations.
|
|
122
|
-
*/ start() {
|
|
123
|
-
this.slashingProtection
|
|
122
|
+
*/ async start() {
|
|
123
|
+
await this.slashingProtection.start();
|
|
124
124
|
}
|
|
125
125
|
/**
|
|
126
|
-
* Stop the HA signer background tasks.
|
|
126
|
+
* Stop the HA signer background tasks and close database connection.
|
|
127
127
|
* Should be called during graceful shutdown.
|
|
128
128
|
*/ async stop() {
|
|
129
|
-
await this.slashingProtection
|
|
129
|
+
await this.slashingProtection.stop();
|
|
130
|
+
await this.slashingProtection.close();
|
|
130
131
|
}
|
|
131
132
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-ha-signer",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.87a0206",
|
|
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,21 +74,21 @@
|
|
|
73
74
|
]
|
|
74
75
|
},
|
|
75
76
|
"dependencies": {
|
|
76
|
-
"@aztec/
|
|
77
|
-
"@aztec/
|
|
77
|
+
"@aztec/ethereum": "0.0.1-commit.87a0206",
|
|
78
|
+
"@aztec/foundation": "0.0.1-commit.87a0206",
|
|
78
79
|
"node-pg-migrate": "^8.0.4",
|
|
79
80
|
"pg": "^8.11.3",
|
|
80
|
-
"tslib": "^2.4.0"
|
|
81
|
+
"tslib": "^2.4.0",
|
|
82
|
+
"zod": "^3.23.8"
|
|
81
83
|
},
|
|
82
84
|
"devDependencies": {
|
|
83
|
-
"@electric-sql/pglite": "^0.
|
|
85
|
+
"@electric-sql/pglite": "^0.3.14",
|
|
84
86
|
"@jest/globals": "^30.0.0",
|
|
85
|
-
"@middle-management/pglite-pg-adapter": "^0.0.3",
|
|
86
87
|
"@types/jest": "^30.0.0",
|
|
87
88
|
"@types/node": "^22.15.17",
|
|
88
89
|
"@types/node-pg-migrate": "^2.3.1",
|
|
89
90
|
"@types/pg": "^8.10.9",
|
|
90
|
-
"@typescript/native-preview": "7.0.0-dev.
|
|
91
|
+
"@typescript/native-preview": "7.0.0-dev.20260113.1",
|
|
91
92
|
"jest": "^30.0.0",
|
|
92
93
|
"jest-mock-extended": "^4.0.0",
|
|
93
94
|
"ts-node": "^10.9.1",
|
package/src/config.ts
CHANGED
|
@@ -1,69 +1,43 @@
|
|
|
1
|
+
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
1
2
|
import {
|
|
2
3
|
type ConfigMappingsType,
|
|
3
4
|
booleanConfigHelper,
|
|
4
5
|
getConfigFromMappings,
|
|
5
6
|
getDefaultConfig,
|
|
6
7
|
numberConfigHelper,
|
|
8
|
+
optionalNumberConfigHelper,
|
|
7
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';
|
|
8
14
|
|
|
9
15
|
/**
|
|
10
|
-
* Configuration for the
|
|
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.
|
|
11
20
|
*/
|
|
12
|
-
export interface
|
|
13
|
-
/** Whether slashing protection is enabled */
|
|
14
|
-
|
|
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'>;
|
|
15
26
|
/** Unique identifier for this node */
|
|
16
27
|
nodeId: string;
|
|
17
28
|
/** How long to wait between polls when a duty is being signed (ms) */
|
|
18
29
|
pollingIntervalMs: number;
|
|
19
30
|
/** Maximum time to wait for a duty being signed to complete (ms) */
|
|
20
31
|
signingTimeoutMs: number;
|
|
21
|
-
/** Maximum age of a stuck duty in ms */
|
|
22
|
-
maxStuckDutiesAgeMs
|
|
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 {
|
|
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;
|
|
62
36
|
/**
|
|
63
37
|
* PostgreSQL connection string
|
|
64
38
|
* Format: postgresql://user:password@host:port/database
|
|
65
39
|
*/
|
|
66
|
-
databaseUrl
|
|
40
|
+
databaseUrl?: string;
|
|
67
41
|
/**
|
|
68
42
|
* PostgreSQL connection pool configuration
|
|
69
43
|
*/
|
|
@@ -77,8 +51,46 @@ export interface CreateHASignerConfig extends SlashingProtectionConfig {
|
|
|
77
51
|
poolConnectionTimeoutMs?: number;
|
|
78
52
|
}
|
|
79
53
|
|
|
80
|
-
export const
|
|
81
|
-
|
|
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
|
+
},
|
|
82
94
|
databaseUrl: {
|
|
83
95
|
env: 'VALIDATOR_HA_DATABASE_URL',
|
|
84
96
|
description:
|
|
@@ -106,11 +118,32 @@ export const createHASignerConfigMappings: ConfigMappingsType<CreateHASignerConf
|
|
|
106
118
|
},
|
|
107
119
|
};
|
|
108
120
|
|
|
121
|
+
export const defaultValidatorHASignerConfig: ValidatorHASignerConfig = getDefaultConfig(
|
|
122
|
+
validatorHASignerConfigMappings,
|
|
123
|
+
);
|
|
124
|
+
|
|
109
125
|
/**
|
|
110
126
|
* Returns the validator HA signer configuration from environment variables.
|
|
111
127
|
* Note: If an environment variable is not set, the default value is used.
|
|
112
128
|
* @returns The validator HA signer configuration.
|
|
113
129
|
*/
|
|
114
|
-
export function getConfigEnvVars():
|
|
115
|
-
return getConfigFromMappings<
|
|
130
|
+
export function getConfigEnvVars(): ValidatorHASignerConfig {
|
|
131
|
+
return getConfigFromMappings<ValidatorHASignerConfig>(validatorHASignerConfigMappings);
|
|
116
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>;
|