@aztec/validator-ha-signer 0.0.1-commit.1142ef1 → 0.0.1-commit.11bf3dd6e
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 +50 -37
- 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 +66 -0
- package/dest/db/lmdb.d.ts.map +1 -0
- package/dest/db/lmdb.js +189 -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 +37 -6
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +88 -28
- package/dest/db/schema.d.ts +22 -11
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +55 -21
- package/dest/db/types.d.ts +116 -34
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +58 -8
- package/dest/errors.d.ts +9 -5
- package/dest/errors.d.ts.map +1 -1
- package/dest/errors.js +7 -4
- package/dest/factory.d.ts +42 -15
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +80 -15
- package/dest/metrics.d.ts +51 -0
- package/dest/metrics.d.ts.map +1 -0
- package/dest/metrics.js +103 -0
- package/dest/migrations.d.ts +1 -1
- package/dest/migrations.d.ts.map +1 -1
- package/dest/migrations.js +13 -2
- package/dest/slashing_protection_service.d.ts +25 -6
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +74 -22
- package/dest/test/pglite_pool.d.ts +92 -0
- package/dest/test/pglite_pool.d.ts.map +1 -0
- package/dest/test/pglite_pool.js +210 -0
- package/dest/types.d.ts +41 -16
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +5 -1
- package/dest/validator_ha_signer.d.ts +18 -13
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +47 -36
- package/package.json +15 -10
- package/src/db/index.ts +1 -0
- package/src/db/lmdb.ts +265 -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 +111 -27
- package/src/db/schema.ts +57 -21
- package/src/db/types.ts +169 -33
- package/src/errors.ts +7 -2
- package/src/factory.ts +99 -15
- package/src/metrics.ts +138 -0
- package/src/migrations.ts +17 -1
- package/src/slashing_protection_service.ts +119 -27
- package/src/test/pglite_pool.ts +256 -0
- package/src/types.ts +71 -16
- package/src/validator_ha_signer.ts +67 -45
- package/dest/config.d.ts +0 -47
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -64
- package/src/config.ts +0 -116
package/src/types.ts
CHANGED
|
@@ -1,27 +1,51 @@
|
|
|
1
|
+
import { SlotNumber } from '@aztec/foundation/branded-types';
|
|
1
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';
|
|
2
16
|
|
|
3
17
|
import type { Pool } from 'pg';
|
|
4
18
|
|
|
5
|
-
import type { CreateHASignerConfig, SlashingProtectionConfig } from './config.js';
|
|
6
19
|
import type {
|
|
20
|
+
BlockProposalDutyIdentifier,
|
|
7
21
|
CheckAndRecordParams,
|
|
8
22
|
DeleteDutyParams,
|
|
9
23
|
DutyIdentifier,
|
|
10
|
-
|
|
24
|
+
DutyRow,
|
|
25
|
+
OtherDutyIdentifier,
|
|
11
26
|
RecordSuccessParams,
|
|
12
27
|
ValidatorDutyRecord,
|
|
13
28
|
} from './db/types.js';
|
|
14
29
|
|
|
15
30
|
export type {
|
|
31
|
+
AttestationSigningContext,
|
|
32
|
+
BlockProposalDutyIdentifier,
|
|
16
33
|
CheckAndRecordParams,
|
|
17
|
-
|
|
34
|
+
CheckpointProposalSigningContext,
|
|
18
35
|
DeleteDutyParams,
|
|
19
36
|
DutyIdentifier,
|
|
37
|
+
DutyRow,
|
|
38
|
+
HAProtectedSigningContext,
|
|
39
|
+
OtherDutyIdentifier,
|
|
20
40
|
RecordSuccessParams,
|
|
21
|
-
|
|
41
|
+
SigningContext,
|
|
22
42
|
ValidatorDutyRecord,
|
|
43
|
+
ValidatorHASignerConfig,
|
|
23
44
|
};
|
|
24
|
-
export { DutyStatus, DutyType } from './db/types.js';
|
|
45
|
+
export { DutyStatus, DutyType, getBlockIndexFromDutyIdentifier, normalizeBlockIndex } from './db/types.js';
|
|
46
|
+
export { isHAProtectedContext };
|
|
47
|
+
export { getBlockNumberFromSigningContextFromStdlib as getBlockNumberFromSigningContext };
|
|
48
|
+
export { getCheckpointNumberFromSigningContextFromStdlib as getCheckpointNumberFromSigningContext };
|
|
25
49
|
|
|
26
50
|
/**
|
|
27
51
|
* Result of tryInsertOrGetExisting operation
|
|
@@ -42,19 +66,20 @@ export interface CreateHASignerDeps {
|
|
|
42
66
|
* If provided, databaseUrl and poolConfig are ignored
|
|
43
67
|
*/
|
|
44
68
|
pool?: Pool;
|
|
69
|
+
/**
|
|
70
|
+
* Optional telemetry client for metrics
|
|
71
|
+
*/
|
|
72
|
+
telemetryClient?: TelemetryClient;
|
|
73
|
+
/**
|
|
74
|
+
* Optional date provider for timestamps
|
|
75
|
+
*/
|
|
76
|
+
dateProvider?: DateProvider;
|
|
45
77
|
}
|
|
46
78
|
|
|
47
79
|
/**
|
|
48
|
-
*
|
|
80
|
+
* deps for creating a local signing protection signer
|
|
49
81
|
*/
|
|
50
|
-
export
|
|
51
|
-
/** Slot number for this duty */
|
|
52
|
-
slot: bigint;
|
|
53
|
-
/** Block number for this duty */
|
|
54
|
-
blockNumber: bigint;
|
|
55
|
-
/** Type of duty being performed */
|
|
56
|
-
dutyType: DutyType;
|
|
57
|
-
}
|
|
82
|
+
export type CreateLocalSignerWithProtectionDeps = Omit<CreateHASignerDeps, 'pool'>;
|
|
58
83
|
|
|
59
84
|
/**
|
|
60
85
|
* Database interface for slashing protection operations
|
|
@@ -81,11 +106,13 @@ export interface SlashingProtectionDatabase {
|
|
|
81
106
|
* @returns true if the update succeeded, false if token didn't match or duty not found
|
|
82
107
|
*/
|
|
83
108
|
updateDutySigned(
|
|
109
|
+
rollupAddress: EthAddress,
|
|
84
110
|
validatorAddress: EthAddress,
|
|
85
|
-
slot:
|
|
111
|
+
slot: SlotNumber,
|
|
86
112
|
dutyType: DutyType,
|
|
87
113
|
signature: string,
|
|
88
114
|
lockToken: string,
|
|
115
|
+
blockIndexWithinCheckpoint: number,
|
|
89
116
|
): Promise<boolean>;
|
|
90
117
|
|
|
91
118
|
/**
|
|
@@ -95,11 +122,39 @@ export interface SlashingProtectionDatabase {
|
|
|
95
122
|
*
|
|
96
123
|
* @returns true if the delete succeeded, false if token didn't match or duty not found
|
|
97
124
|
*/
|
|
98
|
-
deleteDuty(
|
|
125
|
+
deleteDuty(
|
|
126
|
+
rollupAddress: EthAddress,
|
|
127
|
+
validatorAddress: EthAddress,
|
|
128
|
+
slot: SlotNumber,
|
|
129
|
+
dutyType: DutyType,
|
|
130
|
+
lockToken: string,
|
|
131
|
+
blockIndexWithinCheckpoint: number,
|
|
132
|
+
): Promise<boolean>;
|
|
99
133
|
|
|
100
134
|
/**
|
|
101
135
|
* Cleanup own stuck duties
|
|
102
136
|
* @returns the number of duties cleaned up
|
|
103
137
|
*/
|
|
104
138
|
cleanupOwnStuckDuties(nodeId: string, maxAgeMs: number): Promise<number>;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Cleanup duties with outdated rollup address.
|
|
142
|
+
* Removes all duties where the rollup address doesn't match the current one.
|
|
143
|
+
* Used after a rollup upgrade to clean up duties for the old rollup.
|
|
144
|
+
* @returns the number of duties cleaned up
|
|
145
|
+
*/
|
|
146
|
+
cleanupOutdatedRollupDuties(currentRollupAddress: EthAddress): Promise<number>;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Cleanup old signed duties.
|
|
150
|
+
* Removes only signed duties older than the specified age.
|
|
151
|
+
* @returns the number of duties cleaned up
|
|
152
|
+
*/
|
|
153
|
+
cleanupOldDuties(maxAgeMs: number): Promise<number>;
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Close the database connection.
|
|
157
|
+
* Should be called during graceful shutdown.
|
|
158
|
+
*/
|
|
159
|
+
close(): Promise<void>;
|
|
105
160
|
}
|
|
@@ -6,13 +6,27 @@
|
|
|
6
6
|
* node will sign for a given duty (slot + duty type).
|
|
7
7
|
*/
|
|
8
8
|
import type { Buffer32 } from '@aztec/foundation/buffer';
|
|
9
|
-
import
|
|
9
|
+
import { EthAddress } from '@aztec/foundation/eth-address';
|
|
10
10
|
import type { Signature } from '@aztec/foundation/eth-signature';
|
|
11
11
|
import { type Logger, createLogger } from '@aztec/foundation/log';
|
|
12
|
+
import type { DateProvider } from '@aztec/foundation/timer';
|
|
13
|
+
import {
|
|
14
|
+
type BaseSignerConfig,
|
|
15
|
+
DutyType,
|
|
16
|
+
type HAProtectedSigningContext,
|
|
17
|
+
getBlockNumberFromSigningContext,
|
|
18
|
+
getCheckpointNumberFromSigningContext,
|
|
19
|
+
} from '@aztec/stdlib/ha-signing';
|
|
12
20
|
|
|
13
|
-
import type {
|
|
21
|
+
import type { DutyIdentifier } from './db/types.js';
|
|
22
|
+
import type { HASignerMetrics } from './metrics.js';
|
|
14
23
|
import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
15
|
-
import type {
|
|
24
|
+
import type { SlashingProtectionDatabase } from './types.js';
|
|
25
|
+
|
|
26
|
+
export interface ValidatorHASignerDeps {
|
|
27
|
+
metrics: HASignerMetrics;
|
|
28
|
+
dateProvider: DateProvider;
|
|
29
|
+
}
|
|
16
30
|
|
|
17
31
|
/**
|
|
18
32
|
* Validator High Availability Signer
|
|
@@ -35,25 +49,33 @@ import type { SigningContext, SlashingProtectionDatabase } from './types.js';
|
|
|
35
49
|
*/
|
|
36
50
|
export class ValidatorHASigner {
|
|
37
51
|
private readonly log: Logger;
|
|
38
|
-
private readonly slashingProtection: SlashingProtectionService
|
|
52
|
+
private readonly slashingProtection: SlashingProtectionService;
|
|
53
|
+
private readonly rollupAddress: EthAddress;
|
|
54
|
+
|
|
55
|
+
private readonly dateProvider: DateProvider;
|
|
56
|
+
private readonly metrics: HASignerMetrics;
|
|
39
57
|
|
|
40
58
|
constructor(
|
|
41
59
|
db: SlashingProtectionDatabase,
|
|
42
|
-
private readonly config:
|
|
60
|
+
private readonly config: BaseSignerConfig,
|
|
61
|
+
deps: ValidatorHASignerDeps,
|
|
43
62
|
) {
|
|
44
63
|
this.log = createLogger('validator-ha-signer');
|
|
45
64
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
throw new Error('Validator HA Signer is not enabled in config');
|
|
49
|
-
}
|
|
65
|
+
this.metrics = deps.metrics;
|
|
66
|
+
this.dateProvider = deps.dateProvider;
|
|
50
67
|
|
|
51
68
|
if (!config.nodeId || config.nodeId === '') {
|
|
52
69
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
53
70
|
}
|
|
54
|
-
this.
|
|
71
|
+
this.rollupAddress = config.l1Contracts.rollupAddress;
|
|
72
|
+
this.slashingProtection = new SlashingProtectionService(db, config, {
|
|
73
|
+
metrics: deps.metrics,
|
|
74
|
+
dateProvider: deps.dateProvider,
|
|
75
|
+
});
|
|
55
76
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
56
77
|
nodeId: config.nodeId,
|
|
78
|
+
rollupAddress: this.rollupAddress.toString(),
|
|
57
79
|
});
|
|
58
80
|
}
|
|
59
81
|
|
|
@@ -67,7 +89,7 @@ export class ValidatorHASigner {
|
|
|
67
89
|
*
|
|
68
90
|
* @param validatorAddress - The validator's Ethereum address
|
|
69
91
|
* @param messageHash - The hash to be signed
|
|
70
|
-
* @param context - The signing context (
|
|
92
|
+
* @param context - The signing context (HA-protected duty types only)
|
|
71
93
|
* @param signFn - Function that performs the actual signing
|
|
72
94
|
* @returns The signature
|
|
73
95
|
*
|
|
@@ -77,29 +99,38 @@ export class ValidatorHASigner {
|
|
|
77
99
|
async signWithProtection(
|
|
78
100
|
validatorAddress: EthAddress,
|
|
79
101
|
messageHash: Buffer32,
|
|
80
|
-
context:
|
|
102
|
+
context: HAProtectedSigningContext,
|
|
81
103
|
signFn: (messageHash: Buffer32) => Promise<Signature>,
|
|
82
104
|
): Promise<Signature> {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
105
|
+
const startTime = this.dateProvider.now();
|
|
106
|
+
const dutyType = context.dutyType;
|
|
107
|
+
|
|
108
|
+
let dutyIdentifier: DutyIdentifier;
|
|
109
|
+
if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
|
|
110
|
+
dutyIdentifier = {
|
|
111
|
+
rollupAddress: this.rollupAddress,
|
|
112
|
+
validatorAddress,
|
|
113
|
+
slot: context.slot,
|
|
114
|
+
blockIndexWithinCheckpoint: context.blockIndexWithinCheckpoint,
|
|
88
115
|
dutyType: context.dutyType,
|
|
116
|
+
};
|
|
117
|
+
} else {
|
|
118
|
+
dutyIdentifier = {
|
|
119
|
+
rollupAddress: this.rollupAddress,
|
|
120
|
+
validatorAddress,
|
|
89
121
|
slot: context.slot,
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
return await signFn(messageHash);
|
|
122
|
+
dutyType: context.dutyType,
|
|
123
|
+
};
|
|
93
124
|
}
|
|
94
125
|
|
|
95
|
-
const { slot, blockNumber, dutyType } = context;
|
|
96
|
-
|
|
97
126
|
// Acquire lock and get the token for ownership verification
|
|
127
|
+
// DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
|
|
128
|
+
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
129
|
+
const checkpointNumber = getCheckpointNumberFromSigningContext(context);
|
|
98
130
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
99
|
-
|
|
100
|
-
slot,
|
|
131
|
+
...dutyIdentifier,
|
|
101
132
|
blockNumber,
|
|
102
|
-
|
|
133
|
+
checkpointNumber,
|
|
103
134
|
messageHash: messageHash.toString(),
|
|
104
135
|
nodeId: this.config.nodeId,
|
|
105
136
|
});
|
|
@@ -110,33 +141,23 @@ export class ValidatorHASigner {
|
|
|
110
141
|
signature = await signFn(messageHash);
|
|
111
142
|
} catch (error: any) {
|
|
112
143
|
// Delete duty to allow retry (only succeeds if we own the lock)
|
|
113
|
-
await this.slashingProtection.deleteDuty({
|
|
114
|
-
|
|
115
|
-
slot,
|
|
116
|
-
dutyType,
|
|
117
|
-
lockToken,
|
|
118
|
-
});
|
|
144
|
+
await this.slashingProtection.deleteDuty({ ...dutyIdentifier, lockToken });
|
|
145
|
+
this.metrics.recordSigningError(dutyType);
|
|
119
146
|
throw error;
|
|
120
147
|
}
|
|
121
148
|
|
|
122
149
|
// Record success (only succeeds if we own the lock)
|
|
123
150
|
await this.slashingProtection.recordSuccess({
|
|
124
|
-
|
|
125
|
-
slot,
|
|
126
|
-
dutyType,
|
|
151
|
+
...dutyIdentifier,
|
|
127
152
|
signature,
|
|
128
153
|
nodeId: this.config.nodeId,
|
|
129
154
|
lockToken,
|
|
130
155
|
});
|
|
131
156
|
|
|
132
|
-
|
|
133
|
-
|
|
157
|
+
const duration = this.dateProvider.now() - startTime;
|
|
158
|
+
this.metrics.recordSigningSuccess(dutyType, duration);
|
|
134
159
|
|
|
135
|
-
|
|
136
|
-
* Check if slashing protection is enabled
|
|
137
|
-
*/
|
|
138
|
-
get isEnabled(): boolean {
|
|
139
|
-
return this.slashingProtection !== undefined;
|
|
160
|
+
return signature;
|
|
140
161
|
}
|
|
141
162
|
|
|
142
163
|
/**
|
|
@@ -150,15 +171,16 @@ export class ValidatorHASigner {
|
|
|
150
171
|
* Start the HA signer background tasks (cleanup of stuck duties).
|
|
151
172
|
* Should be called after construction and before signing operations.
|
|
152
173
|
*/
|
|
153
|
-
start() {
|
|
154
|
-
this.slashingProtection
|
|
174
|
+
async start() {
|
|
175
|
+
await this.slashingProtection.start();
|
|
155
176
|
}
|
|
156
177
|
|
|
157
178
|
/**
|
|
158
|
-
* Stop the HA signer background tasks.
|
|
179
|
+
* Stop the HA signer background tasks and close database connection.
|
|
159
180
|
* Should be called during graceful shutdown.
|
|
160
181
|
*/
|
|
161
182
|
async stop() {
|
|
162
|
-
await this.slashingProtection
|
|
183
|
+
await this.slashingProtection.stop();
|
|
184
|
+
await this.slashingProtection.close();
|
|
163
185
|
}
|
|
164
186
|
}
|
package/dest/config.d.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { type ConfigMappingsType } from '@aztec/foundation/config';
|
|
2
|
-
/**
|
|
3
|
-
* Configuration for the slashing protection service
|
|
4
|
-
*/
|
|
5
|
-
export interface SlashingProtectionConfig {
|
|
6
|
-
/** Whether slashing protection is enabled */
|
|
7
|
-
enabled: boolean;
|
|
8
|
-
/** Unique identifier for this node */
|
|
9
|
-
nodeId: string;
|
|
10
|
-
/** How long to wait between polls when a duty is being signed (ms) */
|
|
11
|
-
pollingIntervalMs: number;
|
|
12
|
-
/** Maximum time to wait for a duty being signed to complete (ms) */
|
|
13
|
-
signingTimeoutMs: number;
|
|
14
|
-
/** Maximum age of a stuck duty in ms */
|
|
15
|
-
maxStuckDutiesAgeMs: number;
|
|
16
|
-
}
|
|
17
|
-
export declare const slashingProtectionConfigMappings: ConfigMappingsType<SlashingProtectionConfig>;
|
|
18
|
-
export declare const defaultSlashingProtectionConfig: SlashingProtectionConfig;
|
|
19
|
-
/**
|
|
20
|
-
* Configuration for creating an HA signer with PostgreSQL backend
|
|
21
|
-
*/
|
|
22
|
-
export interface CreateHASignerConfig extends SlashingProtectionConfig {
|
|
23
|
-
/**
|
|
24
|
-
* PostgreSQL connection string
|
|
25
|
-
* Format: postgresql://user:password@host:port/database
|
|
26
|
-
*/
|
|
27
|
-
databaseUrl: string;
|
|
28
|
-
/**
|
|
29
|
-
* PostgreSQL connection pool configuration
|
|
30
|
-
*/
|
|
31
|
-
/** Maximum number of clients in the pool (default: 10) */
|
|
32
|
-
poolMaxCount?: number;
|
|
33
|
-
/** Minimum number of clients in the pool (default: 0) */
|
|
34
|
-
poolMinCount?: number;
|
|
35
|
-
/** Idle timeout in milliseconds (default: 10000) */
|
|
36
|
-
poolIdleTimeoutMs?: number;
|
|
37
|
-
/** Connection timeout in milliseconds (default: 0, no timeout) */
|
|
38
|
-
poolConnectionTimeoutMs?: number;
|
|
39
|
-
}
|
|
40
|
-
export declare const createHASignerConfigMappings: ConfigMappingsType<CreateHASignerConfig>;
|
|
41
|
-
/**
|
|
42
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
43
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
44
|
-
* @returns The validator HA signer configuration.
|
|
45
|
-
*/
|
|
46
|
-
export declare function getConfigEnvVars(): CreateHASignerConfig;
|
|
47
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29uZmlnLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvY29uZmlnLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFDTCxLQUFLLGtCQUFrQixFQUt4QixNQUFNLDBCQUEwQixDQUFDO0FBRWxDOztHQUVHO0FBQ0gsTUFBTSxXQUFXLHdCQUF3QjtJQUN2Qyw2Q0FBNkM7SUFDN0MsT0FBTyxFQUFFLE9BQU8sQ0FBQztJQUNqQixzQ0FBc0M7SUFDdEMsTUFBTSxFQUFFLE1BQU0sQ0FBQztJQUNmLHNFQUFzRTtJQUN0RSxpQkFBaUIsRUFBRSxNQUFNLENBQUM7SUFDMUIsb0VBQW9FO0lBQ3BFLGdCQUFnQixFQUFFLE1BQU0sQ0FBQztJQUN6Qix3Q0FBd0M7SUFDeEMsbUJBQW1CLEVBQUUsTUFBTSxDQUFDO0NBQzdCO0FBRUQsZUFBTyxNQUFNLGdDQUFnQyxFQUFFLGtCQUFrQixDQUFDLHdCQUF3QixDQTJCekYsQ0FBQztBQUVGLGVBQU8sTUFBTSwrQkFBK0IsRUFBRSx3QkFFN0MsQ0FBQztBQUVGOztHQUVHO0FBQ0gsTUFBTSxXQUFXLG9CQUFxQixTQUFRLHdCQUF3QjtJQUNwRTs7O09BR0c7SUFDSCxXQUFXLEVBQUUsTUFBTSxDQUFDO0lBQ3BCOztPQUVHO0lBQ0gsMERBQTBEO0lBQzFELFlBQVksQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUN0Qix5REFBeUQ7SUFDekQsWUFBWSxDQUFDLEVBQUUsTUFBTSxDQUFDO0lBQ3RCLG9EQUFvRDtJQUNwRCxpQkFBaUIsQ0FBQyxFQUFFLE1BQU0sQ0FBQztJQUMzQixrRUFBa0U7SUFDbEUsdUJBQXVCLENBQUMsRUFBRSxNQUFNLENBQUM7Q0FDbEM7QUFFRCxlQUFPLE1BQU0sNEJBQTRCLEVBQUUsa0JBQWtCLENBQUMsb0JBQW9CLENBMkJqRixDQUFDO0FBRUY7Ozs7R0FJRztBQUNILHdCQUFnQixnQkFBZ0IsSUFBSSxvQkFBb0IsQ0FFdkQifQ==
|
package/dest/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EAKxB,MAAM,0BAA0B,CAAC;AAElC;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,sCAAsC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,iBAAiB,EAAE,MAAM,CAAC;IAC1B,oEAAoE;IACpE,gBAAgB,EAAE,MAAM,CAAC;IACzB,wCAAwC;IACxC,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,eAAO,MAAM,gCAAgC,EAAE,kBAAkB,CAAC,wBAAwB,CA2BzF,CAAC;AAEF,eAAO,MAAM,+BAA+B,EAAE,wBAE7C,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,wBAAwB;IACpE;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB;;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,4BAA4B,EAAE,kBAAkB,CAAC,oBAAoB,CA2BjF,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,oBAAoB,CAEvD"}
|
package/dest/config.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { booleanConfigHelper, getConfigFromMappings, getDefaultConfig, numberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
-
export const slashingProtectionConfigMappings = {
|
|
3
|
-
enabled: {
|
|
4
|
-
env: 'SLASHING_PROTECTION_ENABLED',
|
|
5
|
-
description: 'Whether slashing protection is enabled',
|
|
6
|
-
...booleanConfigHelper(true)
|
|
7
|
-
},
|
|
8
|
-
nodeId: {
|
|
9
|
-
env: 'SLASHING_PROTECTION_NODE_ID',
|
|
10
|
-
description: 'The unique identifier for this node',
|
|
11
|
-
defaultValue: ''
|
|
12
|
-
},
|
|
13
|
-
pollingIntervalMs: {
|
|
14
|
-
env: 'SLASHING_PROTECTION_POLLING_INTERVAL_MS',
|
|
15
|
-
description: 'The number of ms to wait between polls when a duty is being signed',
|
|
16
|
-
...numberConfigHelper(100)
|
|
17
|
-
},
|
|
18
|
-
signingTimeoutMs: {
|
|
19
|
-
env: 'SLASHING_PROTECTION_SIGNING_TIMEOUT_MS',
|
|
20
|
-
description: 'The maximum time to wait for a duty being signed to complete',
|
|
21
|
-
...numberConfigHelper(3_000)
|
|
22
|
-
},
|
|
23
|
-
maxStuckDutiesAgeMs: {
|
|
24
|
-
env: 'SLASHING_PROTECTION_MAX_STUCK_DUTIES_AGE_MS',
|
|
25
|
-
description: 'The maximum age of a stuck duty in ms',
|
|
26
|
-
// hard-coding at current 2 slot duration. This should be set by the validator on init
|
|
27
|
-
...numberConfigHelper(72_000)
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
export const defaultSlashingProtectionConfig = getDefaultConfig(slashingProtectionConfigMappings);
|
|
31
|
-
export const createHASignerConfigMappings = {
|
|
32
|
-
...slashingProtectionConfigMappings,
|
|
33
|
-
databaseUrl: {
|
|
34
|
-
env: 'VALIDATOR_HA_DATABASE_URL',
|
|
35
|
-
description: 'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)'
|
|
36
|
-
},
|
|
37
|
-
poolMaxCount: {
|
|
38
|
-
env: 'VALIDATOR_HA_POOL_MAX',
|
|
39
|
-
description: 'Maximum number of clients in the pool',
|
|
40
|
-
...numberConfigHelper(10)
|
|
41
|
-
},
|
|
42
|
-
poolMinCount: {
|
|
43
|
-
env: 'VALIDATOR_HA_POOL_MIN',
|
|
44
|
-
description: 'Minimum number of clients in the pool',
|
|
45
|
-
...numberConfigHelper(0)
|
|
46
|
-
},
|
|
47
|
-
poolIdleTimeoutMs: {
|
|
48
|
-
env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
|
|
49
|
-
description: 'Idle timeout in milliseconds',
|
|
50
|
-
...numberConfigHelper(10_000)
|
|
51
|
-
},
|
|
52
|
-
poolConnectionTimeoutMs: {
|
|
53
|
-
env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
|
|
54
|
-
description: 'Connection timeout in milliseconds (0 means no timeout)',
|
|
55
|
-
...numberConfigHelper(0)
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
/**
|
|
59
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
60
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
61
|
-
* @returns The validator HA signer configuration.
|
|
62
|
-
*/ export function getConfigEnvVars() {
|
|
63
|
-
return getConfigFromMappings(createHASignerConfigMappings);
|
|
64
|
-
}
|
package/src/config.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ConfigMappingsType,
|
|
3
|
-
booleanConfigHelper,
|
|
4
|
-
getConfigFromMappings,
|
|
5
|
-
getDefaultConfig,
|
|
6
|
-
numberConfigHelper,
|
|
7
|
-
} from '@aztec/foundation/config';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Configuration for the slashing protection service
|
|
11
|
-
*/
|
|
12
|
-
export interface SlashingProtectionConfig {
|
|
13
|
-
/** Whether slashing protection is enabled */
|
|
14
|
-
enabled: boolean;
|
|
15
|
-
/** Unique identifier for this node */
|
|
16
|
-
nodeId: string;
|
|
17
|
-
/** How long to wait between polls when a duty is being signed (ms) */
|
|
18
|
-
pollingIntervalMs: number;
|
|
19
|
-
/** Maximum time to wait for a duty being signed to complete (ms) */
|
|
20
|
-
signingTimeoutMs: number;
|
|
21
|
-
/** Maximum age of a stuck duty in ms */
|
|
22
|
-
maxStuckDutiesAgeMs: number;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const slashingProtectionConfigMappings: ConfigMappingsType<SlashingProtectionConfig> = {
|
|
26
|
-
enabled: {
|
|
27
|
-
env: 'SLASHING_PROTECTION_ENABLED',
|
|
28
|
-
description: 'Whether slashing protection is enabled',
|
|
29
|
-
...booleanConfigHelper(true),
|
|
30
|
-
},
|
|
31
|
-
nodeId: {
|
|
32
|
-
env: 'SLASHING_PROTECTION_NODE_ID',
|
|
33
|
-
description: 'The unique identifier for this node',
|
|
34
|
-
defaultValue: '',
|
|
35
|
-
},
|
|
36
|
-
pollingIntervalMs: {
|
|
37
|
-
env: 'SLASHING_PROTECTION_POLLING_INTERVAL_MS',
|
|
38
|
-
description: 'The number of ms to wait between polls when a duty is being signed',
|
|
39
|
-
...numberConfigHelper(100),
|
|
40
|
-
},
|
|
41
|
-
signingTimeoutMs: {
|
|
42
|
-
env: 'SLASHING_PROTECTION_SIGNING_TIMEOUT_MS',
|
|
43
|
-
description: 'The maximum time to wait for a duty being signed to complete',
|
|
44
|
-
...numberConfigHelper(3_000),
|
|
45
|
-
},
|
|
46
|
-
maxStuckDutiesAgeMs: {
|
|
47
|
-
env: 'SLASHING_PROTECTION_MAX_STUCK_DUTIES_AGE_MS',
|
|
48
|
-
description: 'The maximum age of a stuck duty in ms',
|
|
49
|
-
// hard-coding at current 2 slot duration. This should be set by the validator on init
|
|
50
|
-
...numberConfigHelper(72_000),
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const defaultSlashingProtectionConfig: SlashingProtectionConfig = getDefaultConfig(
|
|
55
|
-
slashingProtectionConfigMappings,
|
|
56
|
-
);
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Configuration for creating an HA signer with PostgreSQL backend
|
|
60
|
-
*/
|
|
61
|
-
export interface CreateHASignerConfig extends SlashingProtectionConfig {
|
|
62
|
-
/**
|
|
63
|
-
* PostgreSQL connection string
|
|
64
|
-
* Format: postgresql://user:password@host:port/database
|
|
65
|
-
*/
|
|
66
|
-
databaseUrl: string;
|
|
67
|
-
/**
|
|
68
|
-
* PostgreSQL connection pool configuration
|
|
69
|
-
*/
|
|
70
|
-
/** Maximum number of clients in the pool (default: 10) */
|
|
71
|
-
poolMaxCount?: number;
|
|
72
|
-
/** Minimum number of clients in the pool (default: 0) */
|
|
73
|
-
poolMinCount?: number;
|
|
74
|
-
/** Idle timeout in milliseconds (default: 10000) */
|
|
75
|
-
poolIdleTimeoutMs?: number;
|
|
76
|
-
/** Connection timeout in milliseconds (default: 0, no timeout) */
|
|
77
|
-
poolConnectionTimeoutMs?: number;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export const createHASignerConfigMappings: ConfigMappingsType<CreateHASignerConfig> = {
|
|
81
|
-
...slashingProtectionConfigMappings,
|
|
82
|
-
databaseUrl: {
|
|
83
|
-
env: 'VALIDATOR_HA_DATABASE_URL',
|
|
84
|
-
description:
|
|
85
|
-
'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)',
|
|
86
|
-
},
|
|
87
|
-
poolMaxCount: {
|
|
88
|
-
env: 'VALIDATOR_HA_POOL_MAX',
|
|
89
|
-
description: 'Maximum number of clients in the pool',
|
|
90
|
-
...numberConfigHelper(10),
|
|
91
|
-
},
|
|
92
|
-
poolMinCount: {
|
|
93
|
-
env: 'VALIDATOR_HA_POOL_MIN',
|
|
94
|
-
description: 'Minimum number of clients in the pool',
|
|
95
|
-
...numberConfigHelper(0),
|
|
96
|
-
},
|
|
97
|
-
poolIdleTimeoutMs: {
|
|
98
|
-
env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
|
|
99
|
-
description: 'Idle timeout in milliseconds',
|
|
100
|
-
...numberConfigHelper(10_000),
|
|
101
|
-
},
|
|
102
|
-
poolConnectionTimeoutMs: {
|
|
103
|
-
env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
|
|
104
|
-
description: 'Connection timeout in milliseconds (0 means no timeout)',
|
|
105
|
-
...numberConfigHelper(0),
|
|
106
|
-
},
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
111
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
112
|
-
* @returns The validator HA signer configuration.
|
|
113
|
-
*/
|
|
114
|
-
export function getConfigEnvVars(): CreateHASignerConfig {
|
|
115
|
-
return getConfigFromMappings<CreateHASignerConfig>(createHASignerConfigMappings);
|
|
116
|
-
}
|