@aztec/validator-ha-signer 0.0.1-commit.3469e52 → 0.0.1-commit.3895657bc
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 -2
- 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 +20 -4
- package/dest/db/postgres.d.ts.map +1 -1
- package/dest/db/postgres.js +44 -17
- package/dest/db/schema.d.ts +17 -10
- package/dest/db/schema.d.ts.map +1 -1
- package/dest/db/schema.js +39 -22
- package/dest/db/types.d.ts +43 -19
- package/dest/db/types.d.ts.map +1 -1
- package/dest/db/types.js +30 -15
- package/dest/factory.d.ts +22 -4
- package/dest/factory.d.ts.map +1 -1
- package/dest/factory.js +50 -5
- 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 +19 -6
- package/dest/slashing_protection_service.d.ts.map +1 -1
- package/dest/slashing_protection_service.js +55 -15
- package/dest/types.d.ts +32 -72
- package/dest/types.d.ts.map +1 -1
- package/dest/types.js +3 -20
- package/dest/validator_ha_signer.d.ts +15 -6
- package/dest/validator_ha_signer.d.ts.map +1 -1
- package/dest/validator_ha_signer.js +24 -11
- package/package.json +10 -5
- package/src/db/index.ts +1 -0
- package/src/db/lmdb.ts +264 -0
- package/src/db/postgres.ts +45 -12
- package/src/db/schema.ts +41 -22
- package/src/db/types.ts +67 -17
- package/src/factory.ts +61 -4
- package/src/metrics.ts +138 -0
- package/src/slashing_protection_service.ts +77 -19
- package/src/types.ts +50 -103
- package/src/validator_ha_signer.ts +41 -15
- package/dest/config.d.ts +0 -79
- package/dest/config.d.ts.map +0 -1
- package/dest/config.js +0 -73
- package/src/config.ts +0 -125
|
@@ -6,18 +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
|
-
|
|
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 } from '@aztec/foundation/timer';
|
|
16
13
|
import {
|
|
14
|
+
type BaseSignerConfig,
|
|
15
|
+
DutyType,
|
|
17
16
|
type HAProtectedSigningContext,
|
|
18
|
-
type SlashingProtectionDatabase,
|
|
19
17
|
getBlockNumberFromSigningContext,
|
|
20
|
-
} from '
|
|
18
|
+
} from '@aztec/stdlib/ha-signing';
|
|
19
|
+
|
|
20
|
+
import type { DutyIdentifier } from './db/types.js';
|
|
21
|
+
import type { HASignerMetrics } from './metrics.js';
|
|
22
|
+
import { SlashingProtectionService } from './slashing_protection_service.js';
|
|
23
|
+
import type { SlashingProtectionDatabase } from './types.js';
|
|
24
|
+
|
|
25
|
+
export interface ValidatorHASignerDeps {
|
|
26
|
+
metrics: HASignerMetrics;
|
|
27
|
+
dateProvider: DateProvider;
|
|
28
|
+
}
|
|
21
29
|
|
|
22
30
|
/**
|
|
23
31
|
* Validator High Availability Signer
|
|
@@ -41,24 +49,32 @@ import {
|
|
|
41
49
|
export class ValidatorHASigner {
|
|
42
50
|
private readonly log: Logger;
|
|
43
51
|
private readonly slashingProtection: SlashingProtectionService;
|
|
52
|
+
private readonly rollupAddress: EthAddress;
|
|
53
|
+
|
|
54
|
+
private readonly dateProvider: DateProvider;
|
|
55
|
+
private readonly metrics: HASignerMetrics;
|
|
44
56
|
|
|
45
57
|
constructor(
|
|
46
58
|
db: SlashingProtectionDatabase,
|
|
47
|
-
private readonly config:
|
|
59
|
+
private readonly config: BaseSignerConfig,
|
|
60
|
+
deps: ValidatorHASignerDeps,
|
|
48
61
|
) {
|
|
49
62
|
this.log = createLogger('validator-ha-signer');
|
|
50
63
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
throw new Error('Validator HA Signer is not enabled in config');
|
|
54
|
-
}
|
|
64
|
+
this.metrics = deps.metrics;
|
|
65
|
+
this.dateProvider = deps.dateProvider;
|
|
55
66
|
|
|
56
67
|
if (!config.nodeId || config.nodeId === '') {
|
|
57
68
|
throw new Error('NODE_ID is required for high-availability setups');
|
|
58
69
|
}
|
|
59
|
-
this.
|
|
70
|
+
this.rollupAddress = config.l1Contracts.rollupAddress;
|
|
71
|
+
this.slashingProtection = new SlashingProtectionService(db, config, {
|
|
72
|
+
metrics: deps.metrics,
|
|
73
|
+
dateProvider: deps.dateProvider,
|
|
74
|
+
});
|
|
60
75
|
this.log.info('Validator HA Signer initialized with slashing protection', {
|
|
61
76
|
nodeId: config.nodeId,
|
|
77
|
+
rollupAddress: this.rollupAddress.toString(),
|
|
62
78
|
});
|
|
63
79
|
}
|
|
64
80
|
|
|
@@ -85,9 +101,13 @@ export class ValidatorHASigner {
|
|
|
85
101
|
context: HAProtectedSigningContext,
|
|
86
102
|
signFn: (messageHash: Buffer32) => Promise<Signature>,
|
|
87
103
|
): Promise<Signature> {
|
|
104
|
+
const startTime = this.dateProvider.now();
|
|
105
|
+
const dutyType = context.dutyType;
|
|
106
|
+
|
|
88
107
|
let dutyIdentifier: DutyIdentifier;
|
|
89
108
|
if (context.dutyType === DutyType.BLOCK_PROPOSAL) {
|
|
90
109
|
dutyIdentifier = {
|
|
110
|
+
rollupAddress: this.rollupAddress,
|
|
91
111
|
validatorAddress,
|
|
92
112
|
slot: context.slot,
|
|
93
113
|
blockIndexWithinCheckpoint: context.blockIndexWithinCheckpoint,
|
|
@@ -95,6 +115,7 @@ export class ValidatorHASigner {
|
|
|
95
115
|
};
|
|
96
116
|
} else {
|
|
97
117
|
dutyIdentifier = {
|
|
118
|
+
rollupAddress: this.rollupAddress,
|
|
98
119
|
validatorAddress,
|
|
99
120
|
slot: context.slot,
|
|
100
121
|
dutyType: context.dutyType,
|
|
@@ -102,6 +123,7 @@ export class ValidatorHASigner {
|
|
|
102
123
|
}
|
|
103
124
|
|
|
104
125
|
// Acquire lock and get the token for ownership verification
|
|
126
|
+
// DutyAlreadySignedError and SlashingProtectionError may be thrown here and are recorded in the service
|
|
105
127
|
const blockNumber = getBlockNumberFromSigningContext(context);
|
|
106
128
|
const lockToken = await this.slashingProtection.checkAndRecord({
|
|
107
129
|
...dutyIdentifier,
|
|
@@ -117,6 +139,7 @@ export class ValidatorHASigner {
|
|
|
117
139
|
} catch (error: any) {
|
|
118
140
|
// Delete duty to allow retry (only succeeds if we own the lock)
|
|
119
141
|
await this.slashingProtection.deleteDuty({ ...dutyIdentifier, lockToken });
|
|
142
|
+
this.metrics.recordSigningError(dutyType);
|
|
120
143
|
throw error;
|
|
121
144
|
}
|
|
122
145
|
|
|
@@ -128,6 +151,9 @@ export class ValidatorHASigner {
|
|
|
128
151
|
lockToken,
|
|
129
152
|
});
|
|
130
153
|
|
|
154
|
+
const duration = this.dateProvider.now() - startTime;
|
|
155
|
+
this.metrics.recordSigningSuccess(dutyType, duration);
|
|
156
|
+
|
|
131
157
|
return signature;
|
|
132
158
|
}
|
|
133
159
|
|
|
@@ -142,8 +168,8 @@ export class ValidatorHASigner {
|
|
|
142
168
|
* Start the HA signer background tasks (cleanup of stuck duties).
|
|
143
169
|
* Should be called after construction and before signing operations.
|
|
144
170
|
*/
|
|
145
|
-
start() {
|
|
146
|
-
this.slashingProtection.start();
|
|
171
|
+
async start() {
|
|
172
|
+
await this.slashingProtection.start();
|
|
147
173
|
}
|
|
148
174
|
|
|
149
175
|
/**
|
package/dest/config.d.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { type ConfigMappingsType } from '@aztec/foundation/config';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
/**
|
|
4
|
-
* Configuration for the Validator HA Signer
|
|
5
|
-
*
|
|
6
|
-
* This config is used for distributed locking and slashing protection
|
|
7
|
-
* when running multiple validator nodes in a high-availability setup.
|
|
8
|
-
*/
|
|
9
|
-
export interface ValidatorHASignerConfig {
|
|
10
|
-
/** Whether HA signing / slashing protection is enabled */
|
|
11
|
-
haSigningEnabled: boolean;
|
|
12
|
-
/** Unique identifier for this node */
|
|
13
|
-
nodeId: string;
|
|
14
|
-
/** How long to wait between polls when a duty is being signed (ms) */
|
|
15
|
-
pollingIntervalMs: number;
|
|
16
|
-
/** Maximum time to wait for a duty being signed to complete (ms) */
|
|
17
|
-
signingTimeoutMs: number;
|
|
18
|
-
/** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
|
|
19
|
-
maxStuckDutiesAgeMs?: number;
|
|
20
|
-
/**
|
|
21
|
-
* PostgreSQL connection string
|
|
22
|
-
* Format: postgresql://user:password@host:port/database
|
|
23
|
-
*/
|
|
24
|
-
databaseUrl?: string;
|
|
25
|
-
/**
|
|
26
|
-
* PostgreSQL connection pool configuration
|
|
27
|
-
*/
|
|
28
|
-
/** Maximum number of clients in the pool (default: 10) */
|
|
29
|
-
poolMaxCount?: number;
|
|
30
|
-
/** Minimum number of clients in the pool (default: 0) */
|
|
31
|
-
poolMinCount?: number;
|
|
32
|
-
/** Idle timeout in milliseconds (default: 10000) */
|
|
33
|
-
poolIdleTimeoutMs?: number;
|
|
34
|
-
/** Connection timeout in milliseconds (default: 0, no timeout) */
|
|
35
|
-
poolConnectionTimeoutMs?: number;
|
|
36
|
-
}
|
|
37
|
-
export declare const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASignerConfig>;
|
|
38
|
-
export declare const defaultValidatorHASignerConfig: ValidatorHASignerConfig;
|
|
39
|
-
/**
|
|
40
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
41
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
42
|
-
* @returns The validator HA signer configuration.
|
|
43
|
-
*/
|
|
44
|
-
export declare function getConfigEnvVars(): ValidatorHASignerConfig;
|
|
45
|
-
export declare const ValidatorHASignerConfigSchema: z.ZodObject<{
|
|
46
|
-
haSigningEnabled: z.ZodBoolean;
|
|
47
|
-
nodeId: z.ZodString;
|
|
48
|
-
pollingIntervalMs: z.ZodNumber;
|
|
49
|
-
signingTimeoutMs: z.ZodNumber;
|
|
50
|
-
maxStuckDutiesAgeMs: z.ZodOptional<z.ZodNumber>;
|
|
51
|
-
databaseUrl: z.ZodOptional<z.ZodString>;
|
|
52
|
-
poolMaxCount: z.ZodOptional<z.ZodNumber>;
|
|
53
|
-
poolMinCount: z.ZodOptional<z.ZodNumber>;
|
|
54
|
-
poolIdleTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
55
|
-
poolConnectionTimeoutMs: z.ZodOptional<z.ZodNumber>;
|
|
56
|
-
}, "strip", z.ZodTypeAny, {
|
|
57
|
-
haSigningEnabled: boolean;
|
|
58
|
-
nodeId: string;
|
|
59
|
-
pollingIntervalMs: number;
|
|
60
|
-
signingTimeoutMs: number;
|
|
61
|
-
maxStuckDutiesAgeMs?: number | undefined;
|
|
62
|
-
databaseUrl?: string | undefined;
|
|
63
|
-
poolMaxCount?: number | undefined;
|
|
64
|
-
poolMinCount?: number | undefined;
|
|
65
|
-
poolIdleTimeoutMs?: number | undefined;
|
|
66
|
-
poolConnectionTimeoutMs?: number | undefined;
|
|
67
|
-
}, {
|
|
68
|
-
haSigningEnabled: boolean;
|
|
69
|
-
nodeId: string;
|
|
70
|
-
pollingIntervalMs: number;
|
|
71
|
-
signingTimeoutMs: number;
|
|
72
|
-
maxStuckDutiesAgeMs?: number | undefined;
|
|
73
|
-
databaseUrl?: string | undefined;
|
|
74
|
-
poolMaxCount?: number | undefined;
|
|
75
|
-
poolMinCount?: number | undefined;
|
|
76
|
-
poolIdleTim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AAI,uBAAuB,CAE1D;AAED,eAAO,MAAM,6BAA6B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAWE,CAAC"}
|
package/dest/config.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import { booleanConfigHelper, getConfigFromMappings, getDefaultConfig, numberConfigHelper, optionalNumberConfigHelper } from '@aztec/foundation/config';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
export const validatorHASignerConfigMappings = {
|
|
4
|
-
haSigningEnabled: {
|
|
5
|
-
env: 'VALIDATOR_HA_SIGNING_ENABLED',
|
|
6
|
-
description: 'Whether HA signing / slashing protection is enabled',
|
|
7
|
-
...booleanConfigHelper(false)
|
|
8
|
-
},
|
|
9
|
-
nodeId: {
|
|
10
|
-
env: 'VALIDATOR_HA_NODE_ID',
|
|
11
|
-
description: 'The unique identifier for this node',
|
|
12
|
-
defaultValue: ''
|
|
13
|
-
},
|
|
14
|
-
pollingIntervalMs: {
|
|
15
|
-
env: 'VALIDATOR_HA_POLLING_INTERVAL_MS',
|
|
16
|
-
description: 'The number of ms to wait between polls when a duty is being signed',
|
|
17
|
-
...numberConfigHelper(100)
|
|
18
|
-
},
|
|
19
|
-
signingTimeoutMs: {
|
|
20
|
-
env: 'VALIDATOR_HA_SIGNING_TIMEOUT_MS',
|
|
21
|
-
description: 'The maximum time to wait for a duty being signed to complete',
|
|
22
|
-
...numberConfigHelper(3_000)
|
|
23
|
-
},
|
|
24
|
-
maxStuckDutiesAgeMs: {
|
|
25
|
-
env: 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS',
|
|
26
|
-
description: 'The maximum age of a stuck duty in ms (defaults to 2x Aztec slot duration)',
|
|
27
|
-
...optionalNumberConfigHelper()
|
|
28
|
-
},
|
|
29
|
-
databaseUrl: {
|
|
30
|
-
env: 'VALIDATOR_HA_DATABASE_URL',
|
|
31
|
-
description: 'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)'
|
|
32
|
-
},
|
|
33
|
-
poolMaxCount: {
|
|
34
|
-
env: 'VALIDATOR_HA_POOL_MAX',
|
|
35
|
-
description: 'Maximum number of clients in the pool',
|
|
36
|
-
...numberConfigHelper(10)
|
|
37
|
-
},
|
|
38
|
-
poolMinCount: {
|
|
39
|
-
env: 'VALIDATOR_HA_POOL_MIN',
|
|
40
|
-
description: 'Minimum number of clients in the pool',
|
|
41
|
-
...numberConfigHelper(0)
|
|
42
|
-
},
|
|
43
|
-
poolIdleTimeoutMs: {
|
|
44
|
-
env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
|
|
45
|
-
description: 'Idle timeout in milliseconds',
|
|
46
|
-
...numberConfigHelper(10_000)
|
|
47
|
-
},
|
|
48
|
-
poolConnectionTimeoutMs: {
|
|
49
|
-
env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
|
|
50
|
-
description: 'Connection timeout in milliseconds (0 means no timeout)',
|
|
51
|
-
...numberConfigHelper(0)
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
export const defaultValidatorHASignerConfig = getDefaultConfig(validatorHASignerConfigMappings);
|
|
55
|
-
/**
|
|
56
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
57
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
58
|
-
* @returns The validator HA signer configuration.
|
|
59
|
-
*/ export function getConfigEnvVars() {
|
|
60
|
-
return getConfigFromMappings(validatorHASignerConfigMappings);
|
|
61
|
-
}
|
|
62
|
-
export const ValidatorHASignerConfigSchema = z.object({
|
|
63
|
-
haSigningEnabled: z.boolean(),
|
|
64
|
-
nodeId: z.string(),
|
|
65
|
-
pollingIntervalMs: z.number().min(0),
|
|
66
|
-
signingTimeoutMs: z.number().min(0),
|
|
67
|
-
maxStuckDutiesAgeMs: z.number().min(0).optional(),
|
|
68
|
-
databaseUrl: z.string().optional(),
|
|
69
|
-
poolMaxCount: z.number().min(0).optional(),
|
|
70
|
-
poolMinCount: z.number().min(0).optional(),
|
|
71
|
-
poolIdleTimeoutMs: z.number().min(0).optional(),
|
|
72
|
-
poolConnectionTimeoutMs: z.number().min(0).optional()
|
|
73
|
-
});
|
package/src/config.ts
DELETED
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ConfigMappingsType,
|
|
3
|
-
booleanConfigHelper,
|
|
4
|
-
getConfigFromMappings,
|
|
5
|
-
getDefaultConfig,
|
|
6
|
-
numberConfigHelper,
|
|
7
|
-
optionalNumberConfigHelper,
|
|
8
|
-
} from '@aztec/foundation/config';
|
|
9
|
-
import type { ZodFor } from '@aztec/foundation/schemas';
|
|
10
|
-
|
|
11
|
-
import { z } from 'zod';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Configuration for the Validator HA Signer
|
|
15
|
-
*
|
|
16
|
-
* This config is used for distributed locking and slashing protection
|
|
17
|
-
* when running multiple validator nodes in a high-availability setup.
|
|
18
|
-
*/
|
|
19
|
-
export interface ValidatorHASignerConfig {
|
|
20
|
-
/** Whether HA signing / slashing protection is enabled */
|
|
21
|
-
haSigningEnabled: boolean;
|
|
22
|
-
/** Unique identifier for this node */
|
|
23
|
-
nodeId: string;
|
|
24
|
-
/** How long to wait between polls when a duty is being signed (ms) */
|
|
25
|
-
pollingIntervalMs: number;
|
|
26
|
-
/** Maximum time to wait for a duty being signed to complete (ms) */
|
|
27
|
-
signingTimeoutMs: number;
|
|
28
|
-
/** Maximum age of a stuck duty in ms (defaults to 2x hardcoded Aztec slot duration if not set) */
|
|
29
|
-
maxStuckDutiesAgeMs?: number;
|
|
30
|
-
/**
|
|
31
|
-
* PostgreSQL connection string
|
|
32
|
-
* Format: postgresql://user:password@host:port/database
|
|
33
|
-
*/
|
|
34
|
-
databaseUrl?: string;
|
|
35
|
-
/**
|
|
36
|
-
* PostgreSQL connection pool configuration
|
|
37
|
-
*/
|
|
38
|
-
/** Maximum number of clients in the pool (default: 10) */
|
|
39
|
-
poolMaxCount?: number;
|
|
40
|
-
/** Minimum number of clients in the pool (default: 0) */
|
|
41
|
-
poolMinCount?: number;
|
|
42
|
-
/** Idle timeout in milliseconds (default: 10000) */
|
|
43
|
-
poolIdleTimeoutMs?: number;
|
|
44
|
-
/** Connection timeout in milliseconds (default: 0, no timeout) */
|
|
45
|
-
poolConnectionTimeoutMs?: number;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export const validatorHASignerConfigMappings: ConfigMappingsType<ValidatorHASignerConfig> = {
|
|
49
|
-
haSigningEnabled: {
|
|
50
|
-
env: 'VALIDATOR_HA_SIGNING_ENABLED',
|
|
51
|
-
description: 'Whether HA signing / slashing protection is enabled',
|
|
52
|
-
...booleanConfigHelper(false),
|
|
53
|
-
},
|
|
54
|
-
nodeId: {
|
|
55
|
-
env: 'VALIDATOR_HA_NODE_ID',
|
|
56
|
-
description: 'The unique identifier for this node',
|
|
57
|
-
defaultValue: '',
|
|
58
|
-
},
|
|
59
|
-
pollingIntervalMs: {
|
|
60
|
-
env: 'VALIDATOR_HA_POLLING_INTERVAL_MS',
|
|
61
|
-
description: 'The number of ms to wait between polls when a duty is being signed',
|
|
62
|
-
...numberConfigHelper(100),
|
|
63
|
-
},
|
|
64
|
-
signingTimeoutMs: {
|
|
65
|
-
env: 'VALIDATOR_HA_SIGNING_TIMEOUT_MS',
|
|
66
|
-
description: 'The maximum time to wait for a duty being signed to complete',
|
|
67
|
-
...numberConfigHelper(3_000),
|
|
68
|
-
},
|
|
69
|
-
maxStuckDutiesAgeMs: {
|
|
70
|
-
env: 'VALIDATOR_HA_MAX_STUCK_DUTIES_AGE_MS',
|
|
71
|
-
description: 'The maximum age of a stuck duty in ms (defaults to 2x Aztec slot duration)',
|
|
72
|
-
...optionalNumberConfigHelper(),
|
|
73
|
-
},
|
|
74
|
-
databaseUrl: {
|
|
75
|
-
env: 'VALIDATOR_HA_DATABASE_URL',
|
|
76
|
-
description:
|
|
77
|
-
'PostgreSQL connection string for validator HA signer (format: postgresql://user:password@host:port/database)',
|
|
78
|
-
},
|
|
79
|
-
poolMaxCount: {
|
|
80
|
-
env: 'VALIDATOR_HA_POOL_MAX',
|
|
81
|
-
description: 'Maximum number of clients in the pool',
|
|
82
|
-
...numberConfigHelper(10),
|
|
83
|
-
},
|
|
84
|
-
poolMinCount: {
|
|
85
|
-
env: 'VALIDATOR_HA_POOL_MIN',
|
|
86
|
-
description: 'Minimum number of clients in the pool',
|
|
87
|
-
...numberConfigHelper(0),
|
|
88
|
-
},
|
|
89
|
-
poolIdleTimeoutMs: {
|
|
90
|
-
env: 'VALIDATOR_HA_POOL_IDLE_TIMEOUT_MS',
|
|
91
|
-
description: 'Idle timeout in milliseconds',
|
|
92
|
-
...numberConfigHelper(10_000),
|
|
93
|
-
},
|
|
94
|
-
poolConnectionTimeoutMs: {
|
|
95
|
-
env: 'VALIDATOR_HA_POOL_CONNECTION_TIMEOUT_MS',
|
|
96
|
-
description: 'Connection timeout in milliseconds (0 means no timeout)',
|
|
97
|
-
...numberConfigHelper(0),
|
|
98
|
-
},
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const defaultValidatorHASignerConfig: ValidatorHASignerConfig = getDefaultConfig(
|
|
102
|
-
validatorHASignerConfigMappings,
|
|
103
|
-
);
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Returns the validator HA signer configuration from environment variables.
|
|
107
|
-
* Note: If an environment variable is not set, the default value is used.
|
|
108
|
-
* @returns The validator HA signer configuration.
|
|
109
|
-
*/
|
|
110
|
-
export function getConfigEnvVars(): ValidatorHASignerConfig {
|
|
111
|
-
return getConfigFromMappings<ValidatorHASignerConfig>(validatorHASignerConfigMappings);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export const ValidatorHASignerConfigSchema = z.object({
|
|
115
|
-
haSigningEnabled: z.boolean(),
|
|
116
|
-
nodeId: z.string(),
|
|
117
|
-
pollingIntervalMs: z.number().min(0),
|
|
118
|
-
signingTimeoutMs: z.number().min(0),
|
|
119
|
-
maxStuckDutiesAgeMs: z.number().min(0).optional(),
|
|
120
|
-
databaseUrl: z.string().optional(),
|
|
121
|
-
poolMaxCount: z.number().min(0).optional(),
|
|
122
|
-
poolMinCount: z.number().min(0).optional(),
|
|
123
|
-
poolIdleTimeoutMs: z.number().min(0).optional(),
|
|
124
|
-
poolConnectionTimeoutMs: z.number().min(0).optional(),
|
|
125
|
-
}) satisfies ZodFor<ValidatorHASignerConfig>;
|