@aztec/validator-ha-signer 0.0.1-commit.6d3c34e → 0.0.1-commit.7035c9bd6
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 +188 -0
- package/dest/db/postgres.d.ts +37 -6
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +86 -28
- package/dest/db/schema.d.ts +21 -10
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +49 -20
- package/dest/db/types.d.ts +109 -33
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +57 -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 +40 -16
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +4 -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 +45 -36
- package/package.json +15 -10
- package/src/db/index.ts +1 -0
- package/src/db/lmdb.ts +264 -0
- package/src/db/postgres.ts +109 -27
- package/src/db/schema.ts +51 -20
- package/src/db/types.ts +166 -32
- 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 +65 -16
- package/src/validator_ha_signer.ts +64 -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
|
@@ -6,13 +6,26 @@
|
|
|
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
|
+
} from '@aztec/stdlib/ha-signing';
|
|
12
19
|
|
|
13
|
-
import type {
|
|
20
|
+
import type { DutyIdentifier } from './db/types.js';
|
|
21
|
+
import type { HASignerMetrics } from './metrics.js';
|
|
14
22
|
import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
15
|
-
import type {
|
|
23
|
+
import type { SlashingProtectionDatabase } from './types.js';
|
|
24
|
+
|
|
25
|
+
export interface ValidatorHASignerDeps {
|
|
26
|
+
metrics: HASignerMetrics;
|
|
27
|
+
dateProvider: DateProvider;
|
|
28
|
+
}
|
|
16
29
|
|
|
17
30
|
/**
|
|
18
31
|
* Validator High Availability Signer
|
|
@@ -35,25 +48,33 @@ import type { SigningContext, SlashingProtectionDatabase } from './types.js';
|
|
|
35
48
|
*/
|
|
36
49
|
export class ValidatorHASigner {
|
|
37
50
|
private readonly log: Logger;
|
|
38
|
-
private readonly slashingProtection: SlashingProtectionService
|
|
51
|
+
private readonly slashingProtection: SlashingProtectionService;
|
|
52
|
+
private readonly rollupAddress: EthAddress;
|
|
53
|
+
|
|
54
|
+
private readonly dateProvider: DateProvider;
|
|
55
|
+
private readonly metrics: HASignerMetrics;
|
|
39
56
|
|
|
40
57
|
constructor(
|
|
41
58
|
db: SlashingProtectionDatabase,
|
|
42
|
-
private readonly config:
|
|
59
|
+
private readonly config: BaseSignerConfig,
|
|
60
|
+
deps: ValidatorHASignerDeps,
|
|
43
61
|
) {
|
|
44
62
|
this.log = createLogger('validator-ha-signer');
|
|
45
63
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
throw new Error('Validator HA Signer is not enabled in config');
|
|
49
|
-
}
|
|
64
|
+
this.metrics = deps.metrics;
|
|
65
|
+
this.dateProvider = deps.dateProvider;
|
|
50
66
|
|
|
51
67
|
if (!config.nodeId || config.nodeId === '') {
|
|
52
68
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
53
69
|
}
|
|
54
|
-
this.
|
|
70
|
+
this.rollupAddress = config.l1Contracts.rollupAddress;
|
|
71
|
+
this.slashingProtection = new SlashingProtectionService(db, config, {
|
|
72
|
+
metrics: deps.metrics,
|
|
73
|
+
dateProvider: deps.dateProvider,
|
|
74
|
+
});
|
|
55
75
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
56
76
|
nodeId: config.nodeId,
|
|
77
|
+
rollupAddress: this.rollupAddress.toString(),
|
|
57
78
|
});
|
|
58
79
|
}
|
|
59
80
|
|
|
@@ -67,7 +88,7 @@ export class ValidatorHASigner {
|
|
|
67
88
|
*
|
|
68
89
|
* @param validatorAddress - The validator's Ethereum address
|
|
69
90
|
* @param messageHash - The hash to be signed
|
|
70
|
-
* @param context - The signing context (
|
|
91
|
+
* @param context - The signing context (HA-protected duty types only)
|
|
71
92
|
* @param signFn - Function that performs the actual signing
|
|
72
93
|
* @returns The signature
|
|
73
94
|
*
|
|
@@ -77,29 +98,36 @@ export class ValidatorHASigner {
|
|
|
77
98
|
async signWithProtection(
|
|
78
99
|
validatorAddress: EthAddress,
|
|
79
100
|
messageHash: Buffer32,
|
|
80
|
-
context:
|
|
101
|
+
context: HAProtectedSigningContext,
|
|
81
102
|
signFn: (messageHash: Buffer32) => Promise<Signature>,
|
|
82
103
|
): Promise<Signature> {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
104
|
+
const startTime = this.dateProvider.now();
|
|
105
|
+
const dutyType = context.dutyType;
|
|
106
|
+
|
|
107
|
+
let dutyIdentifier: DutyIdentifier;
|
|
108
|
+
if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
|
|
109
|
+
dutyIdentifier = {
|
|
110
|
+
rollupAddress: this.rollupAddress,
|
|
111
|
+
validatorAddress,
|
|
112
|
+
slot: context.slot,
|
|
113
|
+
blockIndexWithinCheckpoint: context.blockIndexWithinCheckpoint,
|
|
88
114
|
dutyType: context.dutyType,
|
|
115
|
+
};
|
|
116
|
+
} else {
|
|
117
|
+
dutyIdentifier = {
|
|
118
|
+
rollupAddress: this.rollupAddress,
|
|
119
|
+
validatorAddress,
|
|
89
120
|
slot: context.slot,
|
|
90
|
-
|
|
91
|
-
}
|
|
92
|
-
return await signFn(messageHash);
|
|
121
|
+
dutyType: context.dutyType,
|
|
122
|
+
};
|
|
93
123
|
}
|
|
94
124
|
|
|
95
|
-
const { slot, blockNumber, dutyType } = context;
|
|
96
|
-
|
|
97
125
|
// Acquire lock and get the token for ownership verification
|
|
126
|
+
// DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
|
|
127
|
+
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
98
128
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
99
|
-
|
|
100
|
-
slot,
|
|
129
|
+
...dutyIdentifier,
|
|
101
130
|
blockNumber,
|
|
102
|
-
dutyType,
|
|
103
131
|
messageHash: messageHash.toString(),
|
|
104
132
|
nodeId: this.config.nodeId,
|
|
105
133
|
});
|
|
@@ -110,33 +138,23 @@ export class ValidatorHASigner {
|
|
|
110
138
|
signature = await signFn(messageHash);
|
|
111
139
|
} catch (error: any) {
|
|
112
140
|
// 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
|
-
});
|
|
141
|
+
await this.slashingProtection.deleteDuty({ ...dutyIdentifier, lockToken });
|
|
142
|
+
this.metrics.recordSigningError(dutyType);
|
|
119
143
|
throw error;
|
|
120
144
|
}
|
|
121
145
|
|
|
122
146
|
// Record success (only succeeds if we own the lock)
|
|
123
147
|
await this.slashingProtection.recordSuccess({
|
|
124
|
-
|
|
125
|
-
slot,
|
|
126
|
-
dutyType,
|
|
148
|
+
...dutyIdentifier,
|
|
127
149
|
signature,
|
|
128
150
|
nodeId: this.config.nodeId,
|
|
129
151
|
lockToken,
|
|
130
152
|
});
|
|
131
153
|
|
|
132
|
-
|
|
133
|
-
|
|
154
|
+
const duration = this.dateProvider.now() - startTime;
|
|
155
|
+
this.metrics.recordSigningSuccess(dutyType, duration);
|
|
134
156
|
|
|
135
|
-
|
|
136
|
-
* Check if slashing protection is enabled
|
|
137
|
-
*/
|
|
138
|
-
get isEnabled(): boolean {
|
|
139
|
-
return this.slashingProtection !== undefined;
|
|
157
|
+
return signature;
|
|
140
158
|
}
|
|
141
159
|
|
|
142
160
|
/**
|
|
@@ -150,15 +168,16 @@ export class ValidatorHASigner {
|
|
|
150
168
|
* Start the HA signer background tasks (cleanup of stuck duties).
|
|
151
169
|
* Should be called after construction and before signing operations.
|
|
152
170
|
*/
|
|
153
|
-
start() {
|
|
154
|
-
this.slashingProtection
|
|
171
|
+
async start() {
|
|
172
|
+
await this.slashingProtection.start();
|
|
155
173
|
}
|
|
156
174
|
|
|
157
175
|
/**
|
|
158
|
-
* Stop the HA signer background tasks.
|
|
176
|
+
* Stop the HA signer background tasks and close database connection.
|
|
159
177
|
* Should be called during graceful shutdown.
|
|
160
178
|
*/
|
|
161
179
|
async stop() {
|
|
162
|
-
await this.slashingProtection
|
|
180
|
+
await this.slashingProtection.stop();
|
|
181
|
+
await this.slashingProtection.close();
|
|
163
182
|
}
|
|
164
183
|
}
|
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
|
-
}
|