@aztec/validator-ha-signer 0.0.1-commit.a89ec08 → 0.0.1-commit.aa0c64f
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 +2 -4
- package/dest/db/index.d.ts +2 -1
- package/dest/db/index.d.ts.map +1 -1
- package/dest/db/index.js +1 -0
- package/dest/db/lmdb.d.ts +70 -0
- package/dest/db/lmdb.d.ts.map +1 -0
- package/dest/db/lmdb.js +223 -0
- package/dest/db/migrations/1_initial-schema.d.ts +4 -2
- package/dest/db/migrations/1_initial-schema.d.ts.map +1 -1
- package/dest/db/migrations/1_initial-schema.js +34 -4
- package/dest/db/migrations/2_add-checkpoint-number.d.ts +7 -0
- package/dest/db/migrations/2_add-checkpoint-number.d.ts.map +1 -0
- package/dest/db/migrations/2_add-checkpoint-number.js +17 -0
- package/dest/db/postgres.d.ts +4 -2
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +15 -13
- package/dest/db/schema.d.ts +6 -6
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +9 -4
- package/dest/db/types.d.ts +46 -21
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +31 -15
- package/dest/errors.d.ts +14 -1
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +15 -0
- package/dest/factory.d.ts +28 -8
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +93 -22
- 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 +15 -4
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +26 -12
- package/dest/types.d.ts +18 -70
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +4 -20
- package/dest/validator_ha_signer.d.ts +13 -4
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +48 -15
- package/package.json +11 -7
- package/src/db/index.ts +1 -0
- package/src/db/lmdb.ts +308 -0
- package/src/db/migrations/1_initial-schema.ts +35 -4
- package/src/db/migrations/2_add-checkpoint-number.ts +19 -0
- package/src/db/postgres.ts +15 -11
- package/src/db/schema.ts +9 -4
- package/src/db/types.ts +66 -19
- package/src/errors.ts +21 -0
- package/src/factory.ts +123 -21
- package/src/metrics.ts +138 -0
- package/src/slashing_protection_service.ts +39 -13
- package/src/types.ts +38 -104
- package/src/validator_ha_signer.ts +78 -17
- package/dest/config.d.ts +0 -101
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -92
- package/dest/db/in_memory.d.ts +0 -20
- package/dest/db/in_memory.d.ts.map +0 -1
- package/dest/db/in_memory.js +0 -73
- package/src/config.ts +0 -149
- package/src/db/in_memory.ts +0 -107
package/src/types.ts
CHANGED
|
@@ -1,38 +1,51 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BlockNumber,
|
|
3
|
-
type CheckpointNumber,
|
|
4
|
-
type IndexWithinCheckpoint,
|
|
5
|
-
type SlotNumber,
|
|
6
|
-
} from '@aztec/foundation/branded-types';
|
|
1
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
7
2
|
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
+
import { DateProvider } from '@aztec/foundation/timer';
|
|
4
|
+
import {
|
|
5
|
+
type AttestationSigningContext,
|
|
6
|
+
type CheckpointProposalSigningContext,
|
|
7
|
+
DutyType,
|
|
8
|
+
type HAProtectedSigningContext,
|
|
9
|
+
type SigningContext,
|
|
10
|
+
type ValidatorHASignerConfig,
|
|
11
|
+
getBlockNumberFromSigningContext as getBlockNumberFromSigningContextFromStdlib,
|
|
12
|
+
getCheckpointNumberFromSigningContext as getCheckpointNumberFromSigningContextFromStdlib,
|
|
13
|
+
isHAProtectedContext,
|
|
14
|
+
} from '@aztec/stdlib/ha-signing';
|
|
15
|
+
import type { TelemetryClient } from '@aztec/telemetry-client';
|
|
8
16
|
|
|
9
17
|
import type { Pool } from 'pg';
|
|
10
18
|
|
|
11
|
-
import type {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
type RecordSuccessParams,
|
|
21
|
-
type ValidatorDutyRecord,
|
|
19
|
+
import type {
|
|
20
|
+
BlockProposalDutyIdentifier,
|
|
21
|
+
CheckAndRecordParams,
|
|
22
|
+
DeleteDutyParams,
|
|
23
|
+
DutyIdentifier,
|
|
24
|
+
DutyRow,
|
|
25
|
+
OtherDutyIdentifier,
|
|
26
|
+
RecordSuccessParams,
|
|
27
|
+
ValidatorDutyRecord,
|
|
22
28
|
} from './db/types.js';
|
|
23
29
|
|
|
24
30
|
export type {
|
|
31
|
+
AttestationSigningContext,
|
|
25
32
|
BlockProposalDutyIdentifier,
|
|
26
33
|
CheckAndRecordParams,
|
|
34
|
+
CheckpointProposalSigningContext,
|
|
27
35
|
DeleteDutyParams,
|
|
28
36
|
DutyIdentifier,
|
|
29
37
|
DutyRow,
|
|
38
|
+
HAProtectedSigningContext,
|
|
30
39
|
OtherDutyIdentifier,
|
|
31
40
|
RecordSuccessParams,
|
|
41
|
+
SigningContext,
|
|
32
42
|
ValidatorDutyRecord,
|
|
33
43
|
ValidatorHASignerConfig,
|
|
34
44
|
};
|
|
35
45
|
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
46
|
+
export { isHAProtectedContext };
|
|
47
|
+
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
48
|
+
export { getCheckpointNumberFromSigningContextFromStdlib as getCheckpointNumberFromSigningContext };
|
|
36
49
|
|
|
37
50
|
/**
|
|
38
51
|
* Result of tryInsertOrGetExisting operation
|
|
@@ -53,99 +66,20 @@ export interface CreateHASignerDeps {
|
|
|
53
66
|
* If provided, databaseUrl and poolConfig are ignored
|
|
54
67
|
*/
|
|
55
68
|
pool?: Pool;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Base context for signing operations
|
|
60
|
-
*/
|
|
61
|
-
interface BaseSigningContext {
|
|
62
|
-
/** Slot number for this duty */
|
|
63
|
-
slot: SlotNumber;
|
|
64
69
|
/**
|
|
65
|
-
*
|
|
66
|
-
* For block proposals, this is the block number.
|
|
67
|
-
* For checkpoint proposals, this is the checkpoint number.
|
|
70
|
+
* Optional telemetry client for metrics
|
|
68
71
|
*/
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
* blockIndexWithinCheckpoint is REQUIRED and must be >= 0.
|
|
75
|
-
*/
|
|
76
|
-
export interface BlockProposalSigningContext extends BaseSigningContext {
|
|
77
|
-
/** Block index within checkpoint (0, 1, 2...). Required for block proposals. */
|
|
78
|
-
blockIndexWithinCheckpoint: IndexWithinCheckpoint;
|
|
79
|
-
dutyType: DutyType.BLOCK_PROPOSAL;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Signing context for non-block-proposal duties that require HA protection.
|
|
84
|
-
* blockIndexWithinCheckpoint is not applicable (internally always -1).
|
|
85
|
-
*/
|
|
86
|
-
export interface OtherSigningContext extends BaseSigningContext {
|
|
87
|
-
dutyType: DutyType.CHECKPOINT_PROPOSAL | DutyType.ATTESTATION | DutyType.ATTESTATIONS_AND_SIGNERS;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Signing context for governance/slashing votes which only need slot for HA protection.
|
|
92
|
-
* blockNumber is not applicable (internally always 0).
|
|
93
|
-
*/
|
|
94
|
-
export interface VoteSigningContext {
|
|
95
|
-
slot: SlotNumber;
|
|
96
|
-
dutyType: DutyType.GOVERNANCE_VOTE | DutyType.SLASHING_VOTE;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Signing context for duties which don't require slot/blockNumber
|
|
101
|
-
* as they don't need HA protection (AUTH_REQUEST, TXS).
|
|
102
|
-
*/
|
|
103
|
-
export interface NoHAProtectionSigningContext {
|
|
104
|
-
dutyType: DutyType.AUTH_REQUEST | DutyType.TXS;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Signing contexts that require HA protection (excludes AUTH_REQUEST).
|
|
109
|
-
* Used by the HA signer's signWithProtection method.
|
|
110
|
-
*/
|
|
111
|
-
export type HAProtectedSigningContext = BlockProposalSigningContext | OtherSigningContext | VoteSigningContext;
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Type guard to check if a SigningContext requires HA protection.
|
|
115
|
-
* Returns true for contexts that need HA protection, false for AUTH_REQUEST and TXS.
|
|
116
|
-
*/
|
|
117
|
-
export function isHAProtectedContext(context: SigningContext): context is HAProtectedSigningContext {
|
|
118
|
-
return context.dutyType !== DutyType.AUTH_REQUEST && context.dutyType !== DutyType.TXS;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Gets the block number from a signing context.
|
|
123
|
-
* - Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE): returns BlockNumber(0)
|
|
124
|
-
* - Other duties: returns the blockNumber from the context
|
|
125
|
-
*/
|
|
126
|
-
export function getBlockNumberFromSigningContext(context: HAProtectedSigningContext): BlockNumber | CheckpointNumber {
|
|
127
|
-
// Check for duty types that have blockNumber
|
|
128
|
-
if (
|
|
129
|
-
context.dutyType === DutyType.BLOCK_PROPOSAL ||
|
|
130
|
-
context.dutyType === DutyType.CHECKPOINT_PROPOSAL ||
|
|
131
|
-
context.dutyType === DutyType.ATTESTATION ||
|
|
132
|
-
context.dutyType === DutyType.ATTESTATIONS_AND_SIGNERS
|
|
133
|
-
) {
|
|
134
|
-
return context.blockNumber;
|
|
135
|
-
}
|
|
136
|
-
// Vote duties (GOVERNANCE_VOTE, SLASHING_VOTE) don't have blockNumber
|
|
137
|
-
return BlockNumber(0);
|
|
72
|
+
telemetryClient?: TelemetryClient;
|
|
73
|
+
/**
|
|
74
|
+
* Optional date provider for timestamps
|
|
75
|
+
*/
|
|
76
|
+
dateProvider?: DateProvider;
|
|
138
77
|
}
|
|
139
78
|
|
|
140
79
|
/**
|
|
141
|
-
*
|
|
142
|
-
* Uses discriminated union to enforce type safety:
|
|
143
|
-
* - BLOCK_PROPOSAL duties MUST have blockIndexWithinCheckpoint >= 0
|
|
144
|
-
* - Other duty types do NOT have blockIndexWithinCheckpoint (internally -1)
|
|
145
|
-
* - Vote duties only need slot (blockNumber is internally 0)
|
|
146
|
-
* - AUTH_REQUEST and TXS duties don't need slot/blockNumber (no HA protection needed)
|
|
80
|
+
* deps for creating a local signing protection signer
|
|
147
81
|
*/
|
|
148
|
-
export type
|
|
82
|
+
export type CreateLocalSignerWithProtectionDeps = Omit<CreateHASignerDeps, 'pool'>;
|
|
149
83
|
|
|
150
84
|
/**
|
|
151
85
|
* Database interface for slashing protection operations
|
|
@@ -9,15 +9,28 @@ 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
11
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
12
|
-
|
|
13
|
-
import type { ValidatorHASignerConfig } from './config.js';
|
|
14
|
-
import { type DutyIdentifier, DutyType } from './db/types.js';
|
|
15
|
-
import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
12
|
+
import { type DateProvider, executeTimeout } from '@aztec/foundation/timer';
|
|
16
13
|
import {
|
|
14
|
+
type BaseSignerConfig,
|
|
15
|
+
DutyType,
|
|
17
16
|
type HAProtectedSigningContext,
|
|
18
|
-
type SlashingProtectionDatabase,
|
|
19
17
|
getBlockNumberFromSigningContext,
|
|
20
|
-
|
|
18
|
+
getCheckpointNumberFromSigningContext,
|
|
19
|
+
} from '@aztec/stdlib/ha-signing';
|
|
20
|
+
|
|
21
|
+
import type { DutyIdentifier } from './db/types.js';
|
|
22
|
+
import { SigningLockLostError } from './errors.js';
|
|
23
|
+
import type { HASignerMetrics } from './metrics.js';
|
|
24
|
+
import { DEFAULT_MAX_STUCK_DUTIES_AGE_MS, SlashingProtectionService } from './slashing_protection_service.js';
|
|
25
|
+
import type { SlashingProtectionDatabase } from './types.js';
|
|
26
|
+
|
|
27
|
+
export interface ValidatorHASignerDeps {
|
|
28
|
+
metrics: HASignerMetrics;
|
|
29
|
+
dateProvider: DateProvider;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Default hard timeout (ms) for a single signer call when not configured. */
|
|
33
|
+
const DEFAULT_SIGNER_CALL_TIMEOUT_MS = 30_000;
|
|
21
34
|
|
|
22
35
|
/**
|
|
23
36
|
* Validator High Availability Signer
|
|
@@ -43,25 +56,45 @@ export class ValidatorHASigner {
|
|
|
43
56
|
private readonly slashingProtection: SlashingProtectionService;
|
|
44
57
|
private readonly rollupAddress: EthAddress;
|
|
45
58
|
|
|
59
|
+
private readonly dateProvider: DateProvider;
|
|
60
|
+
private readonly metrics: HASignerMetrics;
|
|
61
|
+
private readonly signerCallTimeoutMs: number;
|
|
62
|
+
|
|
46
63
|
constructor(
|
|
47
64
|
db: SlashingProtectionDatabase,
|
|
48
|
-
private readonly config:
|
|
65
|
+
private readonly config: BaseSignerConfig,
|
|
66
|
+
deps: ValidatorHASignerDeps,
|
|
49
67
|
) {
|
|
50
68
|
this.log = createLogger('validator-ha-signer');
|
|
51
69
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
70
|
+
this.metrics = deps.metrics;
|
|
71
|
+
this.dateProvider = deps.dateProvider;
|
|
72
|
+
|
|
73
|
+
// Clamp the signer-call timeout below half the stuck-duty max age. This maintains the
|
|
74
|
+
// invariant that an in-flight signing always times out and releases its SIGNING row well before
|
|
75
|
+
// stuck-duty cleanup could consider it stuck, so cleanup can never delete a live duty (only
|
|
76
|
+
// signWithProtection writes SIGNING rows, and every path through it is bounded by this timeout).
|
|
77
|
+
// If timers misbehave anyway, the recordSuccess-returns-false throw is the backstop: the duty
|
|
78
|
+
// fails instead of broadcasting an unprotected signature.
|
|
79
|
+
const maxStuckDutiesAgeMs = config.maxStuckDutiesAgeMs ?? DEFAULT_MAX_STUCK_DUTIES_AGE_MS;
|
|
80
|
+
this.signerCallTimeoutMs = Math.min(
|
|
81
|
+
config.signerCallTimeoutMs ?? DEFAULT_SIGNER_CALL_TIMEOUT_MS,
|
|
82
|
+
maxStuckDutiesAgeMs / 2,
|
|
83
|
+
);
|
|
56
84
|
|
|
57
85
|
if (!config.nodeId || config.nodeId === '') {
|
|
58
86
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
59
87
|
}
|
|
60
|
-
this.rollupAddress = config.
|
|
61
|
-
this.slashingProtection = new SlashingProtectionService(db, config
|
|
88
|
+
this.rollupAddress = config.rollupAddress;
|
|
89
|
+
this.slashingProtection = new SlashingProtectionService(db, config, {
|
|
90
|
+
metrics: deps.metrics,
|
|
91
|
+
dateProvider: deps.dateProvider,
|
|
92
|
+
});
|
|
93
|
+
|
|
62
94
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
63
95
|
nodeId: config.nodeId,
|
|
64
96
|
rollupAddress: this.rollupAddress.toString(),
|
|
97
|
+
signerCallTimeoutMs: this.signerCallTimeoutMs,
|
|
65
98
|
});
|
|
66
99
|
}
|
|
67
100
|
|
|
@@ -88,6 +121,9 @@ export class ValidatorHASigner {
|
|
|
88
121
|
context: HAProtectedSigningContext,
|
|
89
122
|
signFn: (messageHash: Buffer32) => Promise<Signature>,
|
|
90
123
|
): Promise<Signature> {
|
|
124
|
+
const startTime = this.dateProvider.now();
|
|
125
|
+
const dutyType = context.dutyType;
|
|
126
|
+
|
|
91
127
|
let dutyIdentifier: DutyIdentifier;
|
|
92
128
|
if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
|
|
93
129
|
dutyIdentifier = {
|
|
@@ -107,31 +143,56 @@ export class ValidatorHASigner {
|
|
|
107
143
|
}
|
|
108
144
|
|
|
109
145
|
// Acquire lock and get the token for ownership verification
|
|
146
|
+
// DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
|
|
110
147
|
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
148
|
+
const checkpointNumber = getCheckpointNumberFromSigningContext(context);
|
|
111
149
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
112
150
|
...dutyIdentifier,
|
|
113
151
|
blockNumber,
|
|
152
|
+
checkpointNumber,
|
|
114
153
|
messageHash: messageHash.toString(),
|
|
115
154
|
nodeId: this.config.nodeId,
|
|
116
155
|
});
|
|
117
156
|
|
|
118
|
-
// Perform signing
|
|
157
|
+
// Perform signing under a hard timeout. If the signer hangs, executeTimeout aborts and rejects;
|
|
158
|
+
// the orphaned signFn promise resolving later is discarded (never broadcast). A timeout takes the
|
|
159
|
+
// same failure path as any signing error: release the lock so the duty can be retried safely.
|
|
119
160
|
let signature: Signature;
|
|
120
161
|
try {
|
|
121
|
-
signature = await
|
|
162
|
+
signature = await executeTimeout(
|
|
163
|
+
() => signFn(messageHash),
|
|
164
|
+
this.signerCallTimeoutMs,
|
|
165
|
+
() =>
|
|
166
|
+
new Error(
|
|
167
|
+
`Signing operation for ${dutyType} at slot ${context.slot} timed out after ` +
|
|
168
|
+
`${this.signerCallTimeoutMs}ms`,
|
|
169
|
+
),
|
|
170
|
+
);
|
|
122
171
|
} catch (error: any) {
|
|
123
172
|
// Delete duty to allow retry (only succeeds if we own the lock)
|
|
124
173
|
await this.slashingProtection.deleteDuty({ ...dutyIdentifier, lockToken });
|
|
174
|
+
this.metrics.recordSigningError(dutyType);
|
|
125
175
|
throw error;
|
|
126
176
|
}
|
|
127
177
|
|
|
128
|
-
// Record success (only succeeds if we own the lock)
|
|
129
|
-
|
|
178
|
+
// Record success (only succeeds if we still own the lock).
|
|
179
|
+
// A false result means our SIGNING row is gone or no longer ours (e.g. deleted by stuck-duty
|
|
180
|
+
// cleanup while signing was slow). We must not broadcast this signature: without a protection
|
|
181
|
+
// record, a later attempt for the same duty with different data would sign freely (slashable).
|
|
182
|
+
// Do not delete the duty here - we no longer own it, and another node may legitimately hold it.
|
|
183
|
+
const recorded = await this.slashingProtection.recordSuccess({
|
|
130
184
|
...dutyIdentifier,
|
|
131
185
|
signature,
|
|
132
186
|
nodeId: this.config.nodeId,
|
|
133
187
|
lockToken,
|
|
134
188
|
});
|
|
189
|
+
if (!recorded) {
|
|
190
|
+
this.metrics.recordSigningError(dutyType);
|
|
191
|
+
throw new SigningLockLostError(context.slot, dutyType, this.config.nodeId);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const duration = this.dateProvider.now() - startTime;
|
|
195
|
+
this.metrics.recordSigningSuccess(dutyType, duration);
|
|
135
196
|
|
|
136
197
|
return signature;
|
|
137
198
|
}
|
package/dest/config.d.ts
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import type { L1ContractAddresses } from '@aztec/ethereum/l1-contract-addresses';
|
|
2
|
-
import { type ConfigMappingsType } from '@aztec/foundation/config';
|
|
3
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
/**
|
|
6
|
-
* Configuration for the Validator HA Signer
|
|
7
|
-
*
|
|
8
|
-
* This config is used for distributed locking and slashing protection
|
|
9
|
-
* when running multiple validator nodes in a high-availability setup.
|
|
10
|
-
*/
|
|
11
|
-
export interface ValidatorHASignerConfig {
|
|
12
|
-
/** Whether HA signing / slashing protection is enabled */
|
|
13
|
-
haSigningEnabled: boolean;
|
|
14
|
-
/** L1 contract addresses (rollup address required) */
|
|
15
|
-
l1Contracts: Pick<L1ContractAddresses, 'rollupAddress'>;
|
|
16
|
-
/** Unique identifier for this node */
|
|
17
|
-
nodeId: string;
|
|
18
|
-
/** How long to wait between polls when a duty is being signed (ms) */
|
|
19
|
-
pollingIntervalMs: number;
|
|
20
|
-
/** Maximum time to wait for a duty being signed to complete (ms) */
|
|
21
|
-
signingTimeoutMs: number;
|
|
22
|
-
/** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
|
|
23
|
-
maxStuckDutiesAgeMs?: number;
|
|
24
|
-
/** Optional: clean up old duties after this many hours (disabled if not set) */
|
|
25
|
-
cleanupOldDutiesAfterHours?: number;
|
|
26
|
-
/**
|
|
27
|
-
* PostgreSQL connection string
|
|
28
|
-
* Format: postgresql://user:password@host:port/database
|
|
29
|
-
*/
|
|
30
|
-
databaseUrl?: string;
|
|
31
|
-
/**
|
|
32
|
-
* PostgreSQL connection pool configuration
|
|
33
|
-
*/
|
|
34
|
-
/** Maximum number of clients in the pool (default: 10) */
|
|
35
|
-
poolMaxCount?: number;
|
|
36
|
-
/** Minimum number of clients in the pool (default: 0) */
|
|
37
|
-
poolMinCount?: number;
|
|
38
|
-
/** Idle timeout in milliseconds (default: 10000) */
|
|
39
|
-
poolIdleTimeoutMs?: number;
|
|
40
|
-
/** Connection timeout in milliseconds (default: 0, no timeout) */
|
|
41
|
-
poolConnectionTimeoutMs?: number;
|
|
42
|
-
}
|
|
43
|
-
export declare const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASignerConfig>;
|
|
44
|
-
export declare const defaultValidatorHASignerConfig: ValidatorHASignerConfig;
|
|
45
|
-
/**
|
|
46
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
47
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
48
|
-
* @returns The validator HA signer configuration.
|
|
49
|
-
*/
|
|
50
|
-
export declare function getConfigEnvVars(): ValidatorHASignerConfig;
|
|
51
|
-
export declare const ValidatorHASignerConfigSchema: z.ZodObject<{
|
|
52
|
-
haSigningEnabled: z.ZodBoolean;
|
|
53
|
-
l1Contracts: z.ZodObject<{
|
|
54
|
-
rollupAddress: z.ZodType<EthAddress, z.ZodTypeDef, EthAddress>;
|
|
55
|
-
}, "strip", z.ZodTypeAny, {
|
|
56
|
-
rollupAddress: EthAddress;
|
|
57
|
-
}, {
|
|
58
|
-
rollupAddress: EthAddress;
|
|
59
|
-
}>;
|
|
60
|
-
nodeId: z.ZodString;
|
|
61
|
-
pollingIntervalMs: z.ZodNumber;
|
|
62
|
-
signingTimeoutMs: z.ZodNumber;
|
|
63
|
-
maxStuckDutiesAgeMs: z.ZodOptional<z.ZodNumber>;
|
|
64
|
-
cleanupOldDutiesAfterHours: z.ZodOptional<z.ZodNumber>;
|
|
65
|
-
databaseUrl: z.ZodOptional<z.ZodString>;
|
|
66
|
-
poolMaxCount: z.ZodOptional<z.ZodNumber>;
|
|
67
|
-
poolMinCount: z.ZodOptional<z.ZodNumber>;
|
|
68
|
-
poolIdleTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
69
|
-
poolConnectionTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
70
|
-
}, "strip", z.ZodTypeAny, {
|
|
71
|
-
haSigningEnabled: boolean;
|
|
72
|
-
l1Contracts: {
|
|
73
|
-
rollupAddress: EthAddress;
|
|
74
|
-
};
|
|
75
|
-
nodeId: string;
|
|
76
|
-
pollingIntervalMs: number;
|
|
77
|
-
signingTimeoutMs: number;
|
|
78
|
-
maxStuckDutiesAgeMs?: number | undefined;
|
|
79
|
-
cleanupOldDutiesAfterHours?: number | undefined;
|
|
80
|
-
databaseUrl?: string | undefined;
|
|
81
|
-
poolMaxCount?: number | undefined;
|
|
82
|
-
poolMinCount?: number | undefined;
|
|
83
|
-
poolIdleTimeoutMs?: number | undefined;
|
|
84
|
-
poolConnectionTimeoutMs?: number | undefined;
|
|
85
|
-
}, {
|
|
86
|
-
haSigningEnabled: boolean;
|
|
87
|
-
l1Contracts: {
|
|
88
|
-
rollupAddress: EthAddress;
|
|
89
|
-
};
|
|
90
|
-
nodeId: string;
|
|
91
|
-
pollingIntervalMs: number;
|
|
92
|
-
signingTimeoutMs: number;
|
|
93
|
-
maxStuckDutiesAgeMs?: number | undefined;
|
|
94
|
-
cleanupOldDutiesAfterHours?: number | undefined;
|
|
95
|
-
databaseUrl?: string | undefined;
|
|
96
|
-
poolMaxCount?: number | undefined;
|
|
97
|
-
poolMinCount?: number | undefined;
|
|
98
|
-
poolIdleTimeoutMs?: number | undefined;
|
|
99
|
-
poolConnectionTimeoutMs?: number | undefined;
|
|
100
|
-
}>;
|
|
101
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sS0FBSyxFQUFFLG1CQUFtQixFQUFFLE1BQU0sdUNBQXVDLENBQUM7QUFDakYsT0FBTyxFQUNMLEtBQUssa0JBQWtCLEVBTXhCLE1BQU0sMEJBQTBCLENBQUM7QUFDbEMsT0FBTyxFQUFFLFVBQVUsRUFBRSxNQUFNLCtCQUErQixDQUFDO0FBRzNELE9BQU8sRUFBRSxDQUFDLEVBQUUsTUFBTSxLQUFLLENBQUM7QUFFeEI7Ozs7O0dBS0c7QUFDSCxNQUFNLFdBQVcsdUJBQXVCO0lBQ3RDLDBEQUEwRDtJQUMxRCxnQkFBZ0IsRUFBRSxPQUFPLENBQUM7SUFDMUIsc0RBQXNEO0lBQ3RELFdBQVcsRUFBRSxJQUFJLENBQUMsbUJBQW1CLEVBQUUsZUFBZSxDQUFDLENBQUM7SUFDeEQsc0NBQXNDO0lBQ3RDLE1BQU0sRUFBRSxNQUFNLENBQUM7SUFDZixzRUFBc0U7SUFDdEUsaUJBQWlCLEVBQUUsTUFBTSxDQUFDO0lBQzFCLG9FQUFvRTtJQUNwRSxnQkFBZ0IsRUFBRSxNQUFNLENBQUM7SUFDekIsa0dBQWtHO0lBQ2xHLG1CQUFtQixDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQzdCLGdGQUFnRjtJQUNoRiwwQkFBMEIsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUNwQzs7O09BR0c7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AAC,CAAC;IACxD,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,gBAAgB,EAAE,MAAM,CAAC;IACzB,kGAAkG;IAClG,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,gFAAgF;IAChF,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kEAAkE;IAClE,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,eAAO,MAAM,+BAA+B,EAAE,kBAAkB,CAAC,uBAAuB,CAiEvF,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,uBAE5C,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,uBAAuB,CAE1D;AAED,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAeE,CAAC"}
|
package/dest/config.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { booleanConfigHelper, getConfigFromMappings, getDefaultConfig, numberConfigHelper, optionalNumberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
-
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
export const validatorHASignerConfigMappings = {
|
|
5
|
-
haSigningEnabled: {
|
|
6
|
-
env: 'VALIDATOR_HA_SIGNING_ENABLED',
|
|
7
|
-
description: 'Whether HA signing / slashing protection is enabled',
|
|
8
|
-
...booleanConfigHelper(false)
|
|
9
|
-
},
|
|
10
|
-
l1Contracts: {
|
|
11
|
-
description: 'L1 contract addresses (rollup address required)',
|
|
12
|
-
nested: {
|
|
13
|
-
rollupAddress: {
|
|
14
|
-
description: 'The Ethereum address of the rollup contract (must be set programmatically)',
|
|
15
|
-
parseEnv: (val)=>EthAddress.fromString(val)
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
nodeId: {
|
|
20
|
-
env: 'VALIDATOR_HA_NODE_ID',
|
|
21
|
-
description: 'The unique identifier for this node',
|
|
22
|
-
defaultValue: ''
|
|
23
|
-
},
|
|
24
|
-
pollingIntervalMs: {
|
|
25
|
-
env: 'VALIDATOR_HA_POLLING_INTERVAL_MS',
|
|
26
|
-
description: 'The number of ms to wait between polls when a duty is being signed',
|
|
27
|
-
...numberConfigHelper(100)
|
|
28
|
-
},
|
|
29
|
-
signingTimeoutMs: {
|
|
30
|
-
env: 'VALIDATOR_HA_SIGNING_TIMEOUT_MS',
|
|
31
|
-
description: 'The maximum time to wait for a duty being signed to complete',
|
|
32
|
-
...numberConfigHelper(3_000)
|
|
33
|
-
},
|
|
34
|
-
maxStuckDutiesAgeMs: {
|
|
35
|
-
env: 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS',
|
|
36
|
-
description: 'The maximum age of a stuck duty in ms (defaults to 2x Aztec slot duration)',
|
|
37
|
-
...optionalNumberConfigHelper()
|
|
38
|
-
},
|
|
39
|
-
cleanupOldDutiesAfterHours: {
|
|
40
|
-
env: 'VALIDATOR_HA_OLD_DUTIES_MAX_AGE_H',
|
|
41
|
-
description: 'Optional: clean up old duties after this many hours (disabled if not set)',
|
|
42
|
-
...optionalNumberConfigHelper()
|
|
43
|
-
},
|
|
44
|
-
databaseUrl: {
|
|
45
|
-
env: 'VALIDATOR_HA_DATABASE_URL',
|
|
46
|
-
description: 'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)'
|
|
47
|
-
},
|
|
48
|
-
poolMaxCount: {
|
|
49
|
-
env: 'VALIDATOR_HA_POOL_MAX',
|
|
50
|
-
description: 'Maximum number of clients in the pool',
|
|
51
|
-
...numberConfigHelper(10)
|
|
52
|
-
},
|
|
53
|
-
poolMinCount: {
|
|
54
|
-
env: 'VALIDATOR_HA_POOL_MIN',
|
|
55
|
-
description: 'Minimum number of clients in the pool',
|
|
56
|
-
...numberConfigHelper(0)
|
|
57
|
-
},
|
|
58
|
-
poolIdleTimeoutMs: {
|
|
59
|
-
env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
|
|
60
|
-
description: 'Idle timeout in milliseconds',
|
|
61
|
-
...numberConfigHelper(10_000)
|
|
62
|
-
},
|
|
63
|
-
poolConnectionTimeoutMs: {
|
|
64
|
-
env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
|
|
65
|
-
description: 'Connection timeout in milliseconds (0 means no timeout)',
|
|
66
|
-
...numberConfigHelper(0)
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
export const defaultValidatorHASignerConfig = getDefaultConfig(validatorHASignerConfigMappings);
|
|
70
|
-
/**
|
|
71
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
72
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
73
|
-
* @returns The validator HA signer configuration.
|
|
74
|
-
*/ export function getConfigEnvVars() {
|
|
75
|
-
return getConfigFromMappings(validatorHASignerConfigMappings);
|
|
76
|
-
}
|
|
77
|
-
export const ValidatorHASignerConfigSchema = z.object({
|
|
78
|
-
haSigningEnabled: z.boolean(),
|
|
79
|
-
l1Contracts: z.object({
|
|
80
|
-
rollupAddress: z.instanceof(EthAddress)
|
|
81
|
-
}),
|
|
82
|
-
nodeId: z.string(),
|
|
83
|
-
pollingIntervalMs: z.number().min(0),
|
|
84
|
-
signingTimeoutMs: z.number().min(0),
|
|
85
|
-
maxStuckDutiesAgeMs: z.number().min(0).optional(),
|
|
86
|
-
cleanupOldDutiesAfterHours: z.number().min(0).optional(),
|
|
87
|
-
databaseUrl: z.string().optional(),
|
|
88
|
-
poolMaxCount: z.number().min(0).optional(),
|
|
89
|
-
poolMinCount: z.number().min(0).optional(),
|
|
90
|
-
poolIdleTimeoutMs: z.number().min(0).optional(),
|
|
91
|
-
poolConnectionTimeoutMs: z.number().min(0).optional()
|
|
92
|
-
});
|
package/dest/db/in_memory.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In-memory implementation of SlashingProtectionDatabase for testing.
|
|
3
|
-
* Used to simulate shared slashing protection in HA test setups without requiring PostgreSQL.
|
|
4
|
-
*/
|
|
5
|
-
import type { SlotNumber } from '@aztec/foundation/branded-types';
|
|
6
|
-
import type { EthAddress } from '@aztec/foundation/eth-address';
|
|
7
|
-
import type { SlashingProtectionDatabase, TryInsertOrGetResult } from '../types.js';
|
|
8
|
-
import type { CheckAndRecordParams, DutyType } from './types.js';
|
|
9
|
-
/** In-memory slashing protection database for testing HA setups. */
|
|
10
|
-
export declare class InMemorySlashingProtectionDatabase implements SlashingProtectionDatabase {
|
|
11
|
-
private duties;
|
|
12
|
-
tryInsertOrGetExisting(params: CheckAndRecordParams): Promise<TryInsertOrGetResult>;
|
|
13
|
-
updateDutySigned(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, signature: string, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
14
|
-
deleteDuty(rollupAddress: EthAddress, validatorAddress: EthAddress, slot: SlotNumber, dutyType: DutyType, lockToken: string, blockIndexWithinCheckpoint: number): Promise<boolean>;
|
|
15
|
-
cleanupOwnStuckDuties(_nodeId: string, _maxAgeMs: number): Promise<number>;
|
|
16
|
-
cleanupOutdatedRollupDuties(_currentRollupAddress: EthAddress): Promise<number>;
|
|
17
|
-
cleanupOldDuties(_maxAgeMs: number): Promise<number>;
|
|
18
|
-
close(): Promise<void>;
|
|
19
|
-
}
|
|
20
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5fbWVtb3J5LmQudH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R,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,CAQlB;IAED,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEzE;IAED,2BAA2B,CAAC,qBAAqB,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAE9E;IAED,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAEnD;IAED,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAGrB;CACF"}
|
package/dest/db/in_memory.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* In-memory implementation of SlashingProtectionDatabase for testing.
|
|
3
|
-
* Used to simulate shared slashing protection in HA test setups without requiring PostgreSQL.
|
|
4
|
-
*/ import { DutyStatus, getBlockIndexFromDutyIdentifier } from './types.js';
|
|
5
|
-
/** Creates a unique key for a duty based on its identifying fields. */ function dutyKey(rollupAddress, validatorAddress, slot, dutyType, blockIndexWithinCheckpoint) {
|
|
6
|
-
return `${rollupAddress}:${validatorAddress}:${slot}:${dutyType}:${blockIndexWithinCheckpoint}`;
|
|
7
|
-
}
|
|
8
|
-
/** In-memory slashing protection database for testing HA setups. */ export class InMemorySlashingProtectionDatabase {
|
|
9
|
-
duties = new Map();
|
|
10
|
-
tryInsertOrGetExisting(params) {
|
|
11
|
-
const blockIndex = getBlockIndexFromDutyIdentifier(params);
|
|
12
|
-
const key = dutyKey(params.rollupAddress, params.validatorAddress, params.slot, params.dutyType, blockIndex);
|
|
13
|
-
const existing = this.duties.get(key);
|
|
14
|
-
if (existing) {
|
|
15
|
-
return Promise.resolve({
|
|
16
|
-
isNew: false,
|
|
17
|
-
record: existing
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
const lockToken = `lock-${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
21
|
-
const record = {
|
|
22
|
-
rollupAddress: params.rollupAddress,
|
|
23
|
-
validatorAddress: params.validatorAddress,
|
|
24
|
-
slot: params.slot,
|
|
25
|
-
blockNumber: params.blockNumber,
|
|
26
|
-
blockIndexWithinCheckpoint: blockIndex,
|
|
27
|
-
dutyType: params.dutyType,
|
|
28
|
-
status: DutyStatus.SIGNING,
|
|
29
|
-
messageHash: params.messageHash,
|
|
30
|
-
nodeId: params.nodeId,
|
|
31
|
-
lockToken,
|
|
32
|
-
startedAt: new Date()
|
|
33
|
-
};
|
|
34
|
-
this.duties.set(key, record);
|
|
35
|
-
return Promise.resolve({
|
|
36
|
-
isNew: true,
|
|
37
|
-
record
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
updateDutySigned(rollupAddress, validatorAddress, slot, dutyType, signature, lockToken, blockIndexWithinCheckpoint) {
|
|
41
|
-
const key = dutyKey(rollupAddress, validatorAddress, slot, dutyType, blockIndexWithinCheckpoint);
|
|
42
|
-
const record = this.duties.get(key);
|
|
43
|
-
if (!record || record.lockToken !== lockToken) {
|
|
44
|
-
return Promise.resolve(false);
|
|
45
|
-
}
|
|
46
|
-
record.status = DutyStatus.SIGNED;
|
|
47
|
-
record.signature = signature;
|
|
48
|
-
record.completedAt = new Date();
|
|
49
|
-
return Promise.resolve(true);
|
|
50
|
-
}
|
|
51
|
-
deleteDuty(rollupAddress, validatorAddress, slot, dutyType, lockToken, blockIndexWithinCheckpoint) {
|
|
52
|
-
const key = dutyKey(rollupAddress, validatorAddress, slot, dutyType, blockIndexWithinCheckpoint);
|
|
53
|
-
const record = this.duties.get(key);
|
|
54
|
-
if (!record || record.lockToken !== lockToken) {
|
|
55
|
-
return Promise.resolve(false);
|
|
56
|
-
}
|
|
57
|
-
this.duties.delete(key);
|
|
58
|
-
return Promise.resolve(true);
|
|
59
|
-
}
|
|
60
|
-
cleanupOwnStuckDuties(_nodeId, _maxAgeMs) {
|
|
61
|
-
return Promise.resolve(0);
|
|
62
|
-
}
|
|
63
|
-
cleanupOutdatedRollupDuties(_currentRollupAddress) {
|
|
64
|
-
return Promise.resolve(0);
|
|
65
|
-
}
|
|
66
|
-
cleanupOldDuties(_maxAgeMs) {
|
|
67
|
-
return Promise.resolve(0);
|
|
68
|
-
}
|
|
69
|
-
close() {
|
|
70
|
-
this.duties.clear();
|
|
71
|
-
return Promise.resolve();
|
|
72
|
-
}
|
|
73
|
-
}
|