@aztec/validator-ha-signer 0.0.1-commit.d6f2b3f94 → 0.0.1-commit.dbf9cec
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 +10 -0
- package/dest/db/postgres.d.ts +1 -1
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +2 -4
- package/dest/db/schema.d.ts +5 -4
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +4 -3
- package/dest/db/types.d.ts +3 -15
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +5 -15
- package/dest/factory.d.ts +2 -2
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +11 -1
- package/dest/metrics.d.ts +51 -0
- package/dest/metrics.d.ts.map +1 -0
- package/dest/metrics.js +103 -0
- package/dest/slashing_protection_service.d.ts +12 -3
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +15 -4
- package/dest/types.d.ts +15 -72
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -20
- package/dest/validator_ha_signer.d.ts +12 -4
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +16 -4
- package/package.json +7 -5
- package/src/db/postgres.ts +2 -4
- package/src/db/schema.ts +4 -3
- package/src/db/types.ts +4 -14
- package/src/factory.ts +13 -2
- package/src/metrics.ts +138 -0
- package/src/slashing_protection_service.ts +25 -4
- package/src/types.ts +30 -107
- package/src/validator_ha_signer.ts +33 -7
- package/dest/config.d.ts +0 -101
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -92
- package/src/config.ts +0 -149
package/dest/types.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { 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';
|
|
3
6
|
import type { Pool } from 'pg';
|
|
4
|
-
import type {
|
|
5
|
-
|
|
6
|
-
export type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyRow, OtherDutyIdentifier, RecordSuccessParams, ValidatorDutyRecord, ValidatorHASignerConfig, };
|
|
7
|
+
import type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyRow, OtherDutyIdentifier, RecordSuccessParams, ValidatorDutyRecord } from './db/types.js';
|
|
8
|
+
export type { BlockProposalDutyIdentifier, CheckAndRecordParams, DeleteDutyParams, DutyIdentifier, DutyRow, HAProtectedSigningContext, OtherDutyIdentifier, RecordSuccessParams, SigningContext, ValidatorDutyRecord, ValidatorHASignerConfig, };
|
|
7
9
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
10
|
+
export { isHAProtectedContext };
|
|
11
|
+
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
8
12
|
/**
|
|
9
13
|
* Result of tryInsertOrGetExisting operation
|
|
10
14
|
*/
|
|
@@ -23,76 +27,15 @@ export interface CreateHASignerDeps {
|
|
|
23
27
|
* If provided, databaseUrl and poolConfig are ignored
|
|
24
28
|
*/
|
|
25
29
|
pool?: Pool;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Base context for signing operations
|
|
29
|
-
*/
|
|
30
|
-
interface BaseSigningContext {
|
|
31
|
-
/** Slot number for this duty */
|
|
32
|
-
slot: SlotNumber;
|
|
33
30
|
/**
|
|
34
|
-
*
|
|
35
|
-
* For block proposals, this is the block number.
|
|
36
|
-
* For checkpoint proposals, this is the checkpoint number.
|
|
31
|
+
* Optional telemetry client for metrics
|
|
37
32
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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;
|
|
33
|
+
telemetryClient?: TelemetryClient;
|
|
34
|
+
/**
|
|
35
|
+
* Optional date provider for timestamps
|
|
36
|
+
*/
|
|
37
|
+
dateProvider?: DateProvider;
|
|
70
38
|
}
|
|
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
39
|
/**
|
|
97
40
|
* Database interface for slashing protection operations
|
|
98
41
|
* This abstraction allows for different database implementations (PostgreSQL, SQLite, etc.)
|
|
@@ -149,4 +92,4 @@ export interface SlashingProtectionDatabase {
|
|
|
149
92
|
*/
|
|
150
93
|
close(): Promise<void>;
|
|
151
94
|
}
|
|
152
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
95
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidHlwZXMuZC50cyIsInNvdXJjZVJvb3QiOiIi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BUSxFQUFFLFFBQVEsRUFDbEIsU0FBUyxFQUFFLE1BQU0sRUFDakIsMEJBQTBCLEVBQUUsTUFBTSxHQUNqQyxPQUFPLENBQUMsT0FBTyxDQUFDLENBQUM7SUFFcEI7OztPQUdHO0lBQ0gscUJBQXFCLENBQUMsTUFBTSxFQUFFLE1BQU0sRUFBRSxRQUFRLEVBQUUsTUFBTSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsQ0FBQztJQUV6RTs7Ozs7T0FLRztJQUNILDJCQUEyQixDQUFDLG9CQUFvQixFQUFFLFVBQVUsR0FBRyxPQUFPLENBQUMsTUFBTSxDQUFDLENBQUM7SUFFL0U7Ozs7T0FJRztJQUNILGdCQUFnQixDQUFDLFFBQVEsRUFBRSxNQUFNLEdBQUcsT0FBTyxDQUFDLE1BQU0sQ0FBQyxDQUFDO0lBRXBEOzs7T0FHRztJQUNILEtBQUssSUFBSSxPQUFPLENBQUMsSUFBSSxDQUFDLENBQUM7Q0FDeEIifQ==
|
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,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,QAAQ,EACR,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,gCAAgC,IAAI,0CAA0C,EAC9E,oBAAoB,EACrB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE/D,OAAO,KAAK,EAAE,IAAI,EAA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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,21 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { DutyType } from './db/types.js';
|
|
1
|
+
import { getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib, isHAProtectedContext } from '@aztec/stdlib/ha-signing';
|
|
3
2
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
}
|
|
3
|
+
export { isHAProtectedContext };
|
|
4
|
+
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
@@ -8,8 +8,14 @@
|
|
|
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
|
|
11
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
12
|
+
import { type HAProtectedSigningContext, type ValidatorHASignerConfig } from '@aztec/stdlib/ha-signing';
|
|
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
|
+
}
|
|
13
19
|
/**
|
|
14
20
|
* Validator High Availability Signer
|
|
15
21
|
*
|
|
@@ -34,7 +40,9 @@ export declare class ValidatorHASigner {
|
|
|
34
40
|
private readonly log;
|
|
35
41
|
private readonly slashingProtection;
|
|
36
42
|
private readonly rollupAddress;
|
|
37
|
-
|
|
43
|
+
private readonly dateProvider;
|
|
44
|
+
private readonly metrics;
|
|
45
|
+
constructor(db: SlashingProtectionDatabase, config: ValidatorHASignerConfig, deps: ValidatorHASignerDeps);
|
|
38
46
|
/**
|
|
39
47
|
* Sign a message with slashing protection.
|
|
40
48
|
*
|
|
@@ -68,4 +76,4 @@ export declare class ValidatorHASigner {
|
|
|
68
76
|
*/
|
|
69
77
|
stop(): Promise<void>;
|
|
70
78
|
}
|
|
71
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
79
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidmFsaWRhdG9yX2hhX3NpZ25lci5kLnRzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vc3JjL3ZhbGlkYXRvcl9oYV9zaWduZXIudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBQ0gsT0FBTyxLQUFLLEVBQUUsUUFBUSxFQUFFLE1BQU0sMEJBQTBCLENBQUM7QUFDekQsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBQzNELE9BQU8sS0FBSyxFQUFFLFNBQVMsRUFBRSxNQUFNLGlDQUFpQyxDQUFDO0FBRWpFLE9BQU8sS0FBSyxFQUFFLFlBQVksRUFBRSxNQUFNLHlCQUF5QixDQUFDO0FBQzVELE9BQU8sRUFFTCxLQUFLLHlCQUF5QixFQUM5QixLQUFLLHVCQUF1QixFQUU3QixNQUFNLDBCQUEwQixDQUFDO0FBR2xDLE9BQU8sS0FBSyxFQUFFLGVBQWUsRUFBRSxNQUFNLGNBQWMsQ0FBQztBQUVwRCxPQUFPLEtBQUssRUFBRSwwQkFBMEIsRUFBRSxNQUFNLFlBQVksQ0FBQztBQUU3RCxNQUFNLFdBQVcscUJBQXFCO0lBQ3BDLE9BQU8sRUFBRSxlQUFlLENBQUM7SUFDekIsWUFBWSxFQUFFLFlBQVksQ0FBQztDQUM1QjtBQUVEOzs7Ozs7Ozs7Ozs7Ozs7Ozs7R0FrQkc7QUFDSCxxQkFBYSxpQkFBaUI7SUFVMUIsT0FBTyxDQUFDLFFBQVEsQ0FBQyxNQUFNO0lBVH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ED;;OAEG;IACH,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED;;;OAGG;IACG,KAAK,kBAEV;IAED;;;OAGG;IACG,IAAI,kBAGT;CACF"}
|
|
@@ -5,9 +5,8 @@
|
|
|
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 '
|
|
8
|
+
import { DutyType, getBlockNumberFromSigningContext } from '@aztec/stdlib/ha-signing';
|
|
9
9
|
import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
10
|
-
import { getBlockNumberFromSigningContext } from './types.js';
|
|
11
10
|
/**
|
|
12
11
|
* Validator High Availability Signer
|
|
13
12
|
*
|
|
@@ -31,9 +30,13 @@ import { getBlockNumberFromSigningContext } from './types.js';
|
|
|
31
30
|
log;
|
|
32
31
|
slashingProtection;
|
|
33
32
|
rollupAddress;
|
|
34
|
-
|
|
33
|
+
dateProvider;
|
|
34
|
+
metrics;
|
|
35
|
+
constructor(db, config, deps){
|
|
35
36
|
this.config = config;
|
|
36
37
|
this.log = createLogger('validator-ha-signer');
|
|
38
|
+
this.metrics = deps.metrics;
|
|
39
|
+
this.dateProvider = deps.dateProvider;
|
|
37
40
|
if (!config.haSigningEnabled) {
|
|
38
41
|
// this shouldn't happen, the validator should use different signer for non-HA setups
|
|
39
42
|
throw new Error('Validator HA Signer is not enabled in config');
|
|
@@ -42,7 +45,10 @@ import { getBlockNumberFromSigningContext } from './types.js';
|
|
|
42
45
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
43
46
|
}
|
|
44
47
|
this.rollupAddress = config.l1Contracts.rollupAddress;
|
|
45
|
-
this.slashingProtection = new SlashingProtectionService(db, config
|
|
48
|
+
this.slashingProtection = new SlashingProtectionService(db, config, {
|
|
49
|
+
metrics: deps.metrics,
|
|
50
|
+
dateProvider: deps.dateProvider
|
|
51
|
+
});
|
|
46
52
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
47
53
|
nodeId: config.nodeId,
|
|
48
54
|
rollupAddress: this.rollupAddress.toString()
|
|
@@ -65,6 +71,8 @@ import { getBlockNumberFromSigningContext } from './types.js';
|
|
|
65
71
|
* @throws DutyAlreadySignedError if the duty was already signed (expected in HA)
|
|
66
72
|
* @throws SlashingProtectionError if attempting to sign different data for same slot (expected in HA)
|
|
67
73
|
*/ async signWithProtection(validatorAddress, messageHash, context, signFn) {
|
|
74
|
+
const startTime = this.dateProvider.now();
|
|
75
|
+
const dutyType = context.dutyType;
|
|
68
76
|
let dutyIdentifier;
|
|
69
77
|
if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
|
|
70
78
|
dutyIdentifier = {
|
|
@@ -83,6 +91,7 @@ import { getBlockNumberFromSigningContext } from './types.js';
|
|
|
83
91
|
};
|
|
84
92
|
}
|
|
85
93
|
// Acquire lock and get the token for ownership verification
|
|
94
|
+
// DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
|
|
86
95
|
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
87
96
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
88
97
|
...dutyIdentifier,
|
|
@@ -100,6 +109,7 @@ import { getBlockNumberFromSigningContext } from './types.js';
|
|
|
100
109
|
...dutyIdentifier,
|
|
101
110
|
lockToken
|
|
102
111
|
});
|
|
112
|
+
this.metrics.recordSigningError(dutyType);
|
|
103
113
|
throw error;
|
|
104
114
|
}
|
|
105
115
|
// Record success (only succeeds if we own the lock)
|
|
@@ -109,6 +119,8 @@ import { getBlockNumberFromSigningContext } from './types.js';
|
|
|
109
119
|
nodeId: this.config.nodeId,
|
|
110
120
|
lockToken
|
|
111
121
|
});
|
|
122
|
+
const duration = this.dateProvider.now() - startTime;
|
|
123
|
+
this.metrics.recordSigningSuccess(dutyType, duration);
|
|
112
124
|
return signature;
|
|
113
125
|
}
|
|
114
126
|
/**
|
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.dbf9cec",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
|
-
"./config": "./dest/config.js",
|
|
7
6
|
"./db": "./dest/db/index.js",
|
|
8
7
|
"./errors": "./dest/errors.js",
|
|
9
8
|
"./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",
|
|
19
18
|
"./src/db/index.ts",
|
|
20
19
|
"./src/errors.ts",
|
|
21
20
|
"./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,8 +74,10 @@
|
|
|
74
74
|
]
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@aztec/ethereum": "0.0.1-commit.
|
|
78
|
-
"@aztec/foundation": "0.0.1-commit.
|
|
77
|
+
"@aztec/ethereum": "0.0.1-commit.dbf9cec",
|
|
78
|
+
"@aztec/foundation": "0.0.1-commit.dbf9cec",
|
|
79
|
+
"@aztec/stdlib": "0.0.1-commit.dbf9cec",
|
|
80
|
+
"@aztec/telemetry-client": "0.0.1-commit.dbf9cec",
|
|
79
81
|
"node-pg-migrate": "^8.0.4",
|
|
80
82
|
"pg": "^8.11.3",
|
|
81
83
|
"tslib": "^2.4.0",
|
package/src/db/postgres.ts
CHANGED
|
@@ -254,8 +254,7 @@ export class PostgresSlashingProtectionDatabase implements SlashingProtectionDat
|
|
|
254
254
|
* @returns the number of duties cleaned up
|
|
255
255
|
*/
|
|
256
256
|
async cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number> {
|
|
257
|
-
const
|
|
258
|
-
const result = await this.pool.query(CLEANUP_OWN_STUCK_DUTIES, [nodeId, cutoff]);
|
|
257
|
+
const result = await this.pool.query(CLEANUP_OWN_STUCK_DUTIES, [nodeId, maxAgeMs]);
|
|
259
258
|
return result.rowCount ?? 0;
|
|
260
259
|
}
|
|
261
260
|
|
|
@@ -277,8 +276,7 @@ export class PostgresSlashingProtectionDatabase implements SlashingProtectionDat
|
|
|
277
276
|
* @returns the number of duties cleaned up
|
|
278
277
|
*/
|
|
279
278
|
async cleanupOldDuties(maxAgeMs: number): Promise<number> {
|
|
280
|
-
const
|
|
281
|
-
const result = await this.pool.query(CLEANUP_OLD_DUTIES, [cutoff]);
|
|
279
|
+
const result = await this.pool.query(CLEANUP_OLD_DUTIES, [maxAgeMs]);
|
|
282
280
|
return result.rowCount ?? 0;
|
|
283
281
|
}
|
|
284
282
|
}
|
package/src/db/schema.ts
CHANGED
|
@@ -203,23 +203,24 @@ WHERE status = 'signed'
|
|
|
203
203
|
|
|
204
204
|
/**
|
|
205
205
|
* Query to clean up old duties (for maintenance)
|
|
206
|
-
* Removes SIGNED duties older than a specified
|
|
206
|
+
* Removes SIGNED duties older than a specified age (in milliseconds)
|
|
207
207
|
*/
|
|
208
208
|
export const CLEANUP_OLD_DUTIES = `
|
|
209
209
|
DELETE FROM validator_duties
|
|
210
210
|
WHERE status = 'signed'
|
|
211
|
-
AND started_at < $1;
|
|
211
|
+
AND started_at < CURRENT_TIMESTAMP - ($1 || ' milliseconds')::INTERVAL;
|
|
212
212
|
`;
|
|
213
213
|
|
|
214
214
|
/**
|
|
215
215
|
* Query to cleanup own stuck duties
|
|
216
216
|
* Removes duties in 'signing' status for a specific node that are older than maxAgeMs
|
|
217
|
+
* Uses DB's CURRENT_TIMESTAMP to avoid clock skew issues between nodes
|
|
217
218
|
*/
|
|
218
219
|
export const CLEANUP_OWN_STUCK_DUTIES = `
|
|
219
220
|
DELETE FROM validator_duties
|
|
220
221
|
WHERE node_id = $1
|
|
221
222
|
AND status = 'signing'
|
|
222
|
-
AND started_at < $2;
|
|
223
|
+
AND started_at < CURRENT_TIMESTAMP - ($2 || ' milliseconds')::INTERVAL;
|
|
223
224
|
`;
|
|
224
225
|
|
|
225
226
|
/**
|
package/src/db/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Row type from PostgreSQL query
|
|
@@ -29,20 +30,6 @@ export interface InsertOrGetRow extends DutyRow {
|
|
|
29
30
|
is_new: boolean;
|
|
30
31
|
}
|
|
31
32
|
|
|
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
|
-
|
|
46
33
|
/**
|
|
47
34
|
* Status of a duty in the database
|
|
48
35
|
*/
|
|
@@ -51,6 +38,9 @@ export enum DutyStatus {
|
|
|
51
38
|
SIGNED = 'signed',
|
|
52
39
|
}
|
|
53
40
|
|
|
41
|
+
// Re-export DutyType from stdlib
|
|
42
|
+
export { DutyType };
|
|
43
|
+
|
|
54
44
|
/**
|
|
55
45
|
* Record of a validator duty in the database
|
|
56
46
|
*/
|
package/src/factory.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
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
|
+
|
|
4
8
|
import { Pool } from 'pg';
|
|
5
9
|
|
|
6
|
-
import type { ValidatorHASignerConfig } from './config.js';
|
|
7
10
|
import { PostgresSlashingProtectionDatabase } from './db/postgres.js';
|
|
11
|
+
import { HASignerMetrics } from './metrics.js';
|
|
8
12
|
import type { CreateHASignerDeps, SlashingProtectionDatabase } from './types.js';
|
|
9
13
|
import { ValidatorHASigner } from './validator_ha_signer.js';
|
|
10
14
|
|
|
@@ -55,6 +59,10 @@ export async function createHASigner(
|
|
|
55
59
|
if (!databaseUrl) {
|
|
56
60
|
throw new Error('databaseUrl is required for createHASigner');
|
|
57
61
|
}
|
|
62
|
+
|
|
63
|
+
const telemetryClient = deps?.telemetryClient ?? getTelemetryClient();
|
|
64
|
+
const dateProvider = deps?.dateProvider ?? new DateProvider();
|
|
65
|
+
|
|
58
66
|
// Create connection pool (or use provided pool)
|
|
59
67
|
let pool: Pool;
|
|
60
68
|
if (!deps?.pool) {
|
|
@@ -75,8 +83,11 @@ export async function createHASigner(
|
|
|
75
83
|
// Verify database schema is initialized and version matches
|
|
76
84
|
await db.initialize();
|
|
77
85
|
|
|
86
|
+
// Create metrics
|
|
87
|
+
const metrics = new HASignerMetrics(telemetryClient, signerConfig.nodeId);
|
|
88
|
+
|
|
78
89
|
// Create signer
|
|
79
|
-
const signer = new ValidatorHASigner(db, { ...signerConfig, databaseUrl });
|
|
90
|
+
const signer = new ValidatorHASigner(db, { ...signerConfig, databaseUrl }, { metrics, dateProvider });
|
|
80
91
|
|
|
81
92
|
return { signer, db };
|
|
82
93
|
}
|
package/src/metrics.ts
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Attributes,
|
|
3
|
+
type Histogram,
|
|
4
|
+
Metrics,
|
|
5
|
+
type TelemetryClient,
|
|
6
|
+
type UpDownCounter,
|
|
7
|
+
createUpDownCounterWithDefault,
|
|
8
|
+
} from '@aztec/telemetry-client';
|
|
9
|
+
|
|
10
|
+
export type HACleanupType = 'stuck' | 'old' | 'outdated_rollup';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Metrics for HA signer tracking signing operations, lock acquisition, and cleanup.
|
|
14
|
+
*/
|
|
15
|
+
export class HASignerMetrics {
|
|
16
|
+
// Signing lifecycle metrics
|
|
17
|
+
private signingDuration: Histogram;
|
|
18
|
+
private signingSuccessCount: UpDownCounter;
|
|
19
|
+
private dutyAlreadySignedCount: UpDownCounter;
|
|
20
|
+
private slashingProtectionCount: UpDownCounter;
|
|
21
|
+
private signingErrorCount: UpDownCounter;
|
|
22
|
+
|
|
23
|
+
// Lock acquisition metrics
|
|
24
|
+
private lockAcquiredCount: UpDownCounter;
|
|
25
|
+
|
|
26
|
+
// Cleanup metrics
|
|
27
|
+
private cleanupStuckDutiesCount: UpDownCounter;
|
|
28
|
+
private cleanupOldDutiesCount: UpDownCounter;
|
|
29
|
+
private cleanupOutdatedRollupDutiesCount: UpDownCounter;
|
|
30
|
+
|
|
31
|
+
constructor(
|
|
32
|
+
client: TelemetryClient,
|
|
33
|
+
private nodeId: string,
|
|
34
|
+
name = 'HASignerMetrics',
|
|
35
|
+
) {
|
|
36
|
+
const meter = client.getMeter(name);
|
|
37
|
+
|
|
38
|
+
// Signing lifecycle
|
|
39
|
+
this.signingDuration = meter.createHistogram(Metrics.HA_SIGNER_SIGNING_DURATION);
|
|
40
|
+
this.signingSuccessCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SIGNING_SUCCESS_COUNT);
|
|
41
|
+
this.dutyAlreadySignedCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_DUTY_ALREADY_SIGNED_COUNT);
|
|
42
|
+
this.slashingProtectionCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SLASHING_PROTECTION_COUNT);
|
|
43
|
+
this.signingErrorCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_SIGNING_ERROR_COUNT);
|
|
44
|
+
|
|
45
|
+
// Lock acquisition
|
|
46
|
+
this.lockAcquiredCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_LOCK_ACQUIRED_COUNT);
|
|
47
|
+
|
|
48
|
+
// Cleanup
|
|
49
|
+
this.cleanupStuckDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_STUCK_DUTIES_COUNT);
|
|
50
|
+
this.cleanupOldDutiesCount = createUpDownCounterWithDefault(meter, Metrics.HA_SIGNER_CLEANUP_OLD_DUTIES_COUNT);
|
|
51
|
+
this.cleanupOutdatedRollupDutiesCount = createUpDownCounterWithDefault(
|
|
52
|
+
meter,
|
|
53
|
+
Metrics.HA_SIGNER_CLEANUP_OUTDATED_ROLLUP_DUTIES_COUNT,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Record a successful signing operation.
|
|
59
|
+
* @param dutyType - The type of duty signed
|
|
60
|
+
* @param durationMs - Duration from start of signWithProtection to completion
|
|
61
|
+
*/
|
|
62
|
+
public recordSigningSuccess(dutyType: string, durationMs: number): void {
|
|
63
|
+
const attributes = {
|
|
64
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
65
|
+
[Attributes.HA_NODE_ID]: this.nodeId,
|
|
66
|
+
};
|
|
67
|
+
this.signingSuccessCount.add(1, attributes);
|
|
68
|
+
this.signingDuration.record(durationMs, attributes);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Record a DutyAlreadySignedError (expected in HA; another node signed first).
|
|
73
|
+
* @param dutyType - The type of duty
|
|
74
|
+
*/
|
|
75
|
+
public recordDutyAlreadySigned(dutyType: string): void {
|
|
76
|
+
const attributes = {
|
|
77
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
78
|
+
[Attributes.HA_NODE_ID]: this.nodeId,
|
|
79
|
+
};
|
|
80
|
+
this.dutyAlreadySignedCount.add(1, attributes);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Record a SlashingProtectionError (attempted to sign different data for same duty).
|
|
85
|
+
* @param dutyType - The type of duty
|
|
86
|
+
*/
|
|
87
|
+
public recordSlashingProtection(dutyType: string): void {
|
|
88
|
+
const attributes = {
|
|
89
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
90
|
+
[Attributes.HA_NODE_ID]: this.nodeId,
|
|
91
|
+
};
|
|
92
|
+
this.slashingProtectionCount.add(1, attributes);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Record a signing function failure (lock will be deleted for retry).
|
|
97
|
+
* @param dutyType - The type of duty
|
|
98
|
+
*/
|
|
99
|
+
public recordSigningError(dutyType: string): void {
|
|
100
|
+
const attributes = {
|
|
101
|
+
[Attributes.HA_DUTY_TYPE]: dutyType,
|
|
102
|
+
[Attributes.HA_NODE_ID]: this.nodeId,
|
|
103
|
+
};
|
|
104
|
+
this.signingErrorCount.add(1, attributes);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Record lock acquisition.
|
|
109
|
+
* @param acquired - Whether a new lock was acquired (true) or existing record found (false)
|
|
110
|
+
*/
|
|
111
|
+
public recordLockAcquire(acquired: boolean): void {
|
|
112
|
+
if (acquired) {
|
|
113
|
+
const attributes = {
|
|
114
|
+
[Attributes.HA_NODE_ID]: this.nodeId,
|
|
115
|
+
};
|
|
116
|
+
this.lockAcquiredCount.add(1, attributes);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Record cleanup metrics.
|
|
122
|
+
* @param type - Type of cleanup
|
|
123
|
+
* @param count - Number of duties cleaned up
|
|
124
|
+
*/
|
|
125
|
+
public recordCleanup(type: HACleanupType, count: number): void {
|
|
126
|
+
const attributes = {
|
|
127
|
+
[Attributes.HA_NODE_ID]: this.nodeId,
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
if (type === 'stuck') {
|
|
131
|
+
this.cleanupStuckDutiesCount.add(count, attributes);
|
|
132
|
+
} else if (type === 'old') {
|
|
133
|
+
this.cleanupOldDutiesCount.add(count, attributes);
|
|
134
|
+
} else if (type === 'outdated_rollup') {
|
|
135
|
+
this.cleanupOutdatedRollupDutiesCount.add(count, attributes);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|