@aztec/validator-ha-signer 0.0.1-commit.f504929 → 0.0.1-commit.f81dbcf
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/dest/config.d.ts +101 -0
- package/dest/config.d.ts.map +1 -0
- package/dest/config.js +92 -0
- package/dest/db/types.d.ts +15 -3
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +15 -5
- package/dest/factory.d.ts +2 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +1 -11
- package/dest/slashing_protection_service.d.ts +3 -12
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +6 -17
- package/dest/types.d.ts +72 -15
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +20 -3
- package/dest/validator_ha_signer.d.ts +4 -12
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +4 -16
- package/package.json +5 -7
- package/src/config.ts +149 -0
- package/src/db/types.ts +14 -4
- package/src/factory.ts +2 -13
- package/src/slashing_protection_service.ts +6 -27
- package/src/types.ts +107 -30
- package/src/validator_ha_signer.ts +7 -33
- package/dest/metrics.d.ts +0 -51
- package/dest/metrics.d.ts.map +0 -1
- package/dest/metrics.js +0 -103
- package/src/metrics.ts +0 -138
package/dest/types.d.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
|
+
import { BlockNumber, type CheckpointNumber, type IndexWithinCheckpoint, type SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
-
import { DutyType, type HAProtectedSigningContext, type SigningContext, type ValidatorHASignerConfig, getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib, isHAProtectedContext } from '@aztec/stdlib/ha-signing';
|
|
5
|
-
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
6
3
|
import type { Pool } from 'pg';
|
|
7
|
-
import type {
|
|
8
|
-
|
|
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, };
|
|
9
7
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
10
|
-
export { isHAProtectedContext };
|
|
11
|
-
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
12
8
|
/**
|
|
13
9
|
* Result of tryInsertOrGetExisting operation
|
|
14
10
|
*/
|
|
@@ -27,15 +23,76 @@ export interface CreateHASignerDeps {
|
|
|
27
23
|
* If provided, databaseUrl and poolConfig are ignored
|
|
28
24
|
*/
|
|
29
25
|
pool?: Pool;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Base context for signing operations
|
|
29
|
+
*/
|
|
30
|
+
interface BaseSigningContext {
|
|
31
|
+
/** Slot number for this duty */
|
|
32
|
+
slot: SlotNumber;
|
|
30
33
|
/**
|
|
31
|
-
*
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Optional date provider for timestamps
|
|
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.
|
|
36
37
|
*/
|
|
37
|
-
|
|
38
|
+
blockNumber: BlockNumber | CheckpointNumber;
|
|
38
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;
|
|
39
96
|
/**
|
|
40
97
|
* Database interface for slashing protection operations
|
|
41
98
|
* This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
|
|
@@ -92,4 +149,4 @@ export interface SlashingProtectionDatabase {
|
|
|
92
149
|
*/
|
|
93
150
|
close(): Promise<void>;
|
|
94
151
|
}
|
|
95
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
152
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3NyYy90eXBlcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQ0wsV0FBVyxFQUNYLEtBQUssZ0JBQWdCLEVBQ3JCLEtBQUsscUJBQXFCLEVBQzFCLEtBQUssVUFBVSxFQUNoQixNQ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7T0FJRztJQUNILGdCQUFnQixDQUFDLFFBQVEsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBRXBEOzs7T0FHRztJQUNILEtBQUssSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7Q0FDeEIifQ==
|
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,
|
|
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,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,+BAA+B,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAE3G;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,2EAA2E;IAC3E,KAAK,EAAE,OAAO,CAAC;IACf,qDAAqD;IACrD,M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AW,0BAA0B;IACzC;;;;;OAKG;IACH,sBAAsB,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAEpF;;;;;OAKG;IACH,gBAAgB,CACd,aAAa,EAAE,UAAU,EACzB,gBAAgB,EAAE,UAAU,EAC5B,IAAI,EAAE,UAAU,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
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockNumber } from '@aztec/foundation/branded-types';
|
|
2
|
+
import { DutyType } from './db/types.js';
|
|
2
3
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
3
|
-
|
|
4
|
-
|
|
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,14 +8,8 @@
|
|
|
8
8
|
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
9
9
|
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
10
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
11
|
-
import type {
|
|
12
|
-
import { type HAProtectedSigningContext, type
|
|
13
|
-
import type { HASignerMetrics } from './metrics.js';
|
|
14
|
-
import type { SlashingProtectionDatabase } from './types.js';
|
|
15
|
-
export interface ValidatorHASignerDeps {
|
|
16
|
-
metrics: HASignerMetrics;
|
|
17
|
-
dateProvider: DateProvider;
|
|
18
|
-
}
|
|
11
|
+
import type { ValidatorHASignerConfig } from './config.js';
|
|
12
|
+
import { type HAProtectedSigningContext, type SlashingProtectionDatabase } from './types.js';
|
|
19
13
|
/**
|
|
20
14
|
* Validator High Availability Signer
|
|
21
15
|
*
|
|
@@ -40,9 +34,7 @@ export declare class ValidatorHASigner {
|
|
|
40
34
|
private readonly log;
|
|
41
35
|
private readonly slashingProtection;
|
|
42
36
|
private readonly rollupAddress;
|
|
43
|
-
|
|
44
|
-
private readonly metrics;
|
|
45
|
-
constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig, deps: ValidatorHASignerDeps);
|
|
37
|
+
constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig);
|
|
46
38
|
/**
|
|
47
39
|
* Sign a message with slashing protection.
|
|
48
40
|
*
|
|
@@ -76,4 +68,4 @@ export declare class ValidatorHASigner {
|
|
|
76
68
|
*/
|
|
77
69
|
stop(): Promise<void>;
|
|
78
70
|
}
|
|
79
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
71
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdG9yX2hhX3NpZ25lci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3ZhbGlkYXRvcl9oYV9zaWduZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDekQsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQzNELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBR2pFLE9BQU8sS0FBSyxFQUFFLHVCQUF1QixFQUFFLE1BQU0sYUFBYSxDQUFDO0FBRzNELE9BQU8sRUFDTCxLQUFLLHlCQUF5QixFQUM5QixLQUFLLDBCQUEwQixFQUVoQyxNQUFNLFlBQVksQ0FBQztBQUVwQjs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dBa0JHO0FBQ0gscUJBQWEsaUJBQWlCO0lBTzFCLE9BQU8sQ0FBQyxRQUFRLENBQUMsTUFBTTtJQU56QixPQUFPLENBQUMsUUFBUSxDQUFDLEdBQUcsQ0FBUztJQUM3QixPQUFPLENBQUMsUUFBUSxDQUFDLGtCQUFrQixDQUE0QjtJQUMvRCxPQUFPLENBQUMsUUFBUSxDQUFDLGFBQWEsQ0FBYTtJQUUzQyxZQUNFLEVBQUUsRUFBRSwwQkFBMEIsRUFDYixNQUFNLEVBQUUsdUJBQXVCLEVBa0JqRDtJQUVEOzs7Ozs7Ozs7Ozs7Ozs7O09BZ0JHO0lBQ0csa0JBQWtCLENBQ3RCLGdCQUFnQixFQUFFLFVBQVUsRUFDNUIsV0FBVyxFQUFFLFFBQVEsRUFDckIsT0FBTyxFQUFFLHlCQUF5QixFQUNsQyxNQUFNLEVBQUUsQ0FBQyxXQUFXLEVBQUUsUUFBUSxLQUFLLE9BQU8sQ0FBQyxTQUFTLENBQUMsR0FDcEQsT0FBTyxDQUFDLFNBQVMsQ0FBQyxDQStDcEI7SUFFRDs7T0FFRztJQUNILElBQUksTUFBTSxJQUFJLE1BQU0sQ0FFbkI7SUFFRDs7O09BR0c7SUFDRyxLQUFLLGtCQUVWO0lBRUQ7OztPQUdHO0lBQ0csSUFBSSxrQkFHVDtDQUNGIn0=
|
|
@@ -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,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;
|
|
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,8 +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
|
|
8
|
+
import { DutyType } from './db/types.js';
|
|
9
9
|
import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
10
|
+
import { getBlockNumberFromSigningContext } from './types.js';
|
|
10
11
|
/**
|
|
11
12
|
* Validator High Availability Signer
|
|
12
13
|
*
|
|
@@ -30,13 +31,9 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
30
31
|
log;
|
|
31
32
|
slashingProtection;
|
|
32
33
|
rollupAddress;
|
|
33
|
-
|
|
34
|
-
metrics;
|
|
35
|
-
constructor(db, config, deps){
|
|
34
|
+
constructor(db, config){
|
|
36
35
|
this.config = config;
|
|
37
36
|
this.log = createLogger('validator-ha-signer');
|
|
38
|
-
this.metrics = deps.metrics;
|
|
39
|
-
this.dateProvider = deps.dateProvider;
|
|
40
37
|
if (!config.haSigningEnabled) {
|
|
41
38
|
// this shouldn't happen, the validator should use different signer for non-HA setups
|
|
42
39
|
throw new Error('Validator HA Signer is not enabled in config');
|
|
@@ -45,10 +42,7 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
45
42
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
46
43
|
}
|
|
47
44
|
this.rollupAddress = config.l1Contracts.rollupAddress;
|
|
48
|
-
this.slashingProtection = new SlashingProtectionService(db, config
|
|
49
|
-
metrics: deps.metrics,
|
|
50
|
-
dateProvider: deps.dateProvider
|
|
51
|
-
});
|
|
45
|
+
this.slashingProtection = new SlashingProtectionService(db, config);
|
|
52
46
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
53
47
|
nodeId: config.nodeId,
|
|
54
48
|
rollupAddress: this.rollupAddress.toString()
|
|
@@ -71,8 +65,6 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
71
65
|
* @throws DutyAlreadySignedError if the duty was already signed (expected in HA)
|
|
72
66
|
* @throws SlashingProtectionError if attempting to sign different data for same slot (expected in HA)
|
|
73
67
|
*/ async signWithProtection(validatorAddress, messageHash, context, signFn) {
|
|
74
|
-
const startTime = this.dateProvider.now();
|
|
75
|
-
const dutyType = context.dutyType;
|
|
76
68
|
let dutyIdentifier;
|
|
77
69
|
if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
|
|
78
70
|
dutyIdentifier = {
|
|
@@ -91,7 +83,6 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
91
83
|
};
|
|
92
84
|
}
|
|
93
85
|
// Acquire lock and get the token for ownership verification
|
|
94
|
-
// DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
|
|
95
86
|
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
96
87
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
97
88
|
...dutyIdentifier,
|
|
@@ -109,7 +100,6 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
109
100
|
...dutyIdentifier,
|
|
110
101
|
lockToken
|
|
111
102
|
});
|
|
112
|
-
this.metrics.recordSigningError(dutyType);
|
|
113
103
|
throw error;
|
|
114
104
|
}
|
|
115
105
|
// Record success (only succeeds if we own the lock)
|
|
@@ -119,8 +109,6 @@ import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
|
119
109
|
nodeId: this.config.nodeId,
|
|
120
110
|
lockToken
|
|
121
111
|
});
|
|
122
|
-
const duration = this.dateProvider.now() - startTime;
|
|
123
|
-
this.metrics.recordSigningSuccess(dutyType, duration);
|
|
124
112
|
return signature;
|
|
125
113
|
}
|
|
126
114
|
/**
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/validator-ha-signer",
|
|
3
|
-
"version": "0.0.1-commit.
|
|
3
|
+
"version": "0.0.1-commit.f81dbcf",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
+
"./config": "./dest/config.js",
|
|
6
7
|
"./db": "./dest/db/index.js",
|
|
7
8
|
"./errors": "./dest/errors.js",
|
|
8
9
|
"./factory": "./dest/factory.js",
|
|
9
|
-
"./metrics": "./dest/metrics.js",
|
|
10
10
|
"./migrations": "./dest/migrations.js",
|
|
11
11
|
"./slashing-protection-service": "./dest/slashing_protection_service.js",
|
|
12
12
|
"./types": "./dest/types.js",
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
},
|
|
16
16
|
"typedocOptions": {
|
|
17
17
|
"entryPoints": [
|
|
18
|
+
"./src/config.ts",
|
|
18
19
|
"./src/db/index.ts",
|
|
19
20
|
"./src/errors.ts",
|
|
20
21
|
"./src/factory.ts",
|
|
21
|
-
"./src/metrics.ts",
|
|
22
22
|
"./src/migrations.ts",
|
|
23
23
|
"./src/slashing_protection_service.ts",
|
|
24
24
|
"./src/types.ts",
|
|
@@ -74,10 +74,8 @@
|
|
|
74
74
|
]
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
78
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
79
|
-
"@aztec/stdlib": "0.0.1-commit.f504929",
|
|
80
|
-
"@aztec/telemetry-client": "0.0.1-commit.f504929",
|
|
77
|
+
"@aztec/ethereum": "0.0.1-commit.f81dbcf",
|
|
78
|
+
"@aztec/foundation": "0.0.1-commit.f81dbcf",
|
|
81
79
|
"node-pg-migrate": "^8.0.4",
|
|
82
80
|
"pg": "^8.11.3",
|
|
83
81
|
"tslib": "^2.4.0",
|
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>;
|
package/src/db/types.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { BlockNumber, CheckpointNumber, IndexWithinCheckpoint, SlotNumber } from '@aztec/foundation/branded-types';
|
|
2
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
3
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
4
|
-
import { DutyType } from '@aztec/stdlib/ha-signing';
|
|
5
4
|
|
|
6
5
|
/**
|
|
7
6
|
* Row type from PostgreSQL query
|
|
@@ -30,6 +29,20 @@ export interface InsertOrGetRow extends DutyRow {
|
|
|
30
29
|
is_new: boolean;
|
|
31
30
|
}
|
|
32
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Type of validator duty being performed
|
|
34
|
+
*/
|
|
35
|
+
export enum DutyType {
|
|
36
|
+
BLOCK_PROPOSAL = 'BLOCK_PROPOSAL',
|
|
37
|
+
CHECKPOINT_PROPOSAL = 'CHECKPOINT_PROPOSAL',
|
|
38
|
+
ATTESTATION = 'ATTESTATION',
|
|
39
|
+
ATTESTATIONS_AND_SIGNERS = 'ATTESTATIONS_AND_SIGNERS',
|
|
40
|
+
GOVERNANCE_VOTE = 'GOVERNANCE_VOTE',
|
|
41
|
+
SLASHING_VOTE = 'SLASHING_VOTE',
|
|
42
|
+
AUTH_REQUEST = 'AUTH_REQUEST',
|
|
43
|
+
TXS = 'TXS',
|
|
44
|
+
}
|
|
45
|
+
|
|
33
46
|
/**
|
|
34
47
|
* Status of a duty in the database
|
|
35
48
|
*/
|
|
@@ -38,9 +51,6 @@ export enum DutyStatus {
|
|
|
38
51
|
SIGNED = 'signed',
|
|
39
52
|
}
|
|
40
53
|
|
|
41
|
-
// Re-export DutyType from stdlib
|
|
42
|
-
export { DutyType };
|
|
43
|
-
|
|
44
54
|
/**
|
|
45
55
|
* Record of a validator duty in the database
|
|
46
56
|
*/
|
package/src/factory.ts
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Factory functions for creating validator HA signers
|
|
3
3
|
*/
|
|
4
|
-
import { DateProvider } from '@aztec/foundation/timer';
|
|
5
|
-
import type { ValidatorHASignerConfig } from '@aztec/stdlib/ha-signing';
|
|
6
|
-
import { getTelemetryClient } from '@aztec/telemetry-client';
|
|
7
|
-
|
|
8
4
|
import { Pool } from 'pg';
|
|
9
5
|
|
|
6
|
+
import type { ValidatorHASignerConfig } from './config.js';
|
|
10
7
|
import { PostgresSlashingProtectionDatabase } from './db/postgres.js';
|
|
11
|
-
import { HASignerMetrics } from './metrics.js';
|
|
12
8
|
import type { CreateHASignerDeps, SlashingProtectionDatabase } from './types.js';
|
|
13
9
|
import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
14
10
|
|
|
@@ -59,10 +55,6 @@ export async function createHASigner(
|
|
|
59
55
|
if (!databaseUrl) {
|
|
60
56
|
throw new Error('databaseUrl is required for createHASigner');
|
|
61
57
|
}
|
|
62
|
-
|
|
63
|
-
const telemetryClient = deps?.telemetryClient ?? getTelemetryClient();
|
|
64
|
-
const dateProvider = deps?.dateProvider ?? new DateProvider();
|
|
65
|
-
|
|
66
58
|
// Create connection pool (or use provided pool)
|
|
67
59
|
let pool: Pool;
|
|
68
60
|
if (!deps?.pool) {
|
|
@@ -83,11 +75,8 @@ export async function createHASigner(
|
|
|
83
75
|
// Verify database schema is initialized and version matches
|
|
84
76
|
await db.initialize();
|
|
85
77
|
|
|
86
|
-
// Create metrics
|
|
87
|
-
const metrics = new HASignerMetrics(telemetryClient, signerConfig.nodeId);
|
|
88
|
-
|
|
89
78
|
// Create signer
|
|
90
|
-
const signer = new ValidatorHASigner(db, { ...signerConfig, databaseUrl }
|
|
79
|
+
const signer = new ValidatorHASigner(db, { ...signerConfig, databaseUrl });
|
|
91
80
|
|
|
92
81
|
return { signer, db };
|
|
93
82
|
}
|